Example #1
0
        private static async Task GenerateLibraryManifest(GenerateLibraryManifestOptions genManOpts)
        {
            var manGen = new ManifestGenerator(new LocalFileSystemFileLoader(m_Logger));

            string publicKeyXml;

            var maninfest = await manGen.CreateManifest(Location.FromPath(genManOpts.LibraryPath),
                                                        genManOpts.Version,
                                                        genManOpts.CertificatePath, genManOpts.CertificatePassword, out publicKeyXml);

            new UserSettingsService().StoreSettings(maninfest,
                                                    Path.Combine(genManOpts.LibraryPath, "library.manifest"),
                                                    new BaseValueSerializer <ILocation>(x => x.ToId(), null));

            if (!string.IsNullOrEmpty(genManOpts.PublicKeyFile))
            {
                await System.IO.File.WriteAllTextAsync(genManOpts.PublicKeyFile, publicKeyXml);
            }
        }
Example #2
0
        private static async Task Main(string[] args)
        {
            var parser = new Parser(p =>
            {
                p.CaseInsensitiveEnumValues = true;
                p.AutoHelp               = true;
                p.EnableDashDash         = true;
                p.HelpWriter             = Console.Out;
                p.IgnoreUnknownArguments = false;
            });

            BuildOptions buildOpts = null;
            ServeOptions serveOpts = null;
            GenerateLibraryManifestOptions genManOpts = null;
            LibraryOptions libOpts = null;

            parser.ParseArguments <BuildOptions, ServeOptions, GenerateLibraryManifestOptions, LibraryOptions>(args)
            .WithParsed <BuildOptions>(o => buildOpts = o)
            .WithParsed <ServeOptions>(o => serveOpts = o)
            .WithParsed <GenerateLibraryManifestOptions>(o => genManOpts = o)
            .WithParsed <LibraryOptions>(o => libOpts = o)
            .WithNotParsed(e => Environment.Exit(1));

            try
            {
                if (serveOpts != null)
                {
                    var engine = new DocifyServeEngine(serveOpts.SourceDirectories?.ToArray(),
                                                       serveOpts.OutputDirectory, serveOpts.Library?.ToArray(),
                                                       serveOpts.Host, serveOpts.BaseUrl, serveOpts.Environment, serveOpts.Verbose,
                                                       serveOpts.HttpPort, serveOpts.HttpsPort);

                    m_Logger = engine.Resolve <ILogger>();

                    await engine.Serve(() =>
                    {
                        m_Logger.LogInformation("Press any key to close host");
                        Console.ReadLine();
                        return(Task.CompletedTask);
                    });
                }
                else if (buildOpts != null)
                {
                    var engine = new DocifyEngine(buildOpts.SourceDirectories?.ToArray(),
                                                  buildOpts.OutputDirectory, buildOpts.Library?.ToArray(),
                                                  buildOpts.Host, buildOpts.BaseUrl, buildOpts.Environment, buildOpts.Verbose);

                    m_Logger = engine.Resolve <ILogger>();

                    await engine.Build();

                    m_Logger.LogInformation($"Build completed. Site has been published to '{buildOpts.OutputDirectory}'");
                }
                else if (genManOpts != null)
                {
                    m_Logger = new ConsoleLogger(genManOpts.Verbose);
                    //TODO: create service
                    await GenerateLibraryManifest(genManOpts);
                }
                else if (libOpts != null)
                {
                    m_Logger = new ConsoleLogger(libOpts.Verbose);
                    //TODO: create service
                    await InstallLibrary(libOpts);
                }
            }
            catch (Exception ex)
            {
                string fullLog;
                var    err = ParseError(ex, out fullLog);
                System.Diagnostics.Trace.WriteLine(fullLog, "Xarial.Docify");

                m_Logger.LogError(err);
                m_Logger.LogError(fullLog, true);

                Environment.Exit(1);
            }
        }