Exemplo n.º 1
0
 public void Process(DefaultConfigModel model, QuestionContext context)
 {
     if (context.Quiet)
     {
         _setter(DefaultValue, model, context);
     }
     else
     {
         WriteQuestion(context);
         var value = GetAnswer();
         _setter(value, model, context);
     }
 }
Exemplo n.º 2
0
        public void Exec(SubCommandRunningContext context)
        {
            string outputFolder = null;

            try
            {
                var config          = new DefaultConfigModel();
                var questionContext = new QuestionContext
                {
                    Quiet = _options.Quiet
                };
                foreach (var question in _selectorQuestions)
                {
                    question.Process(config, questionContext);
                }

                foreach (var question in _overallQuestion)
                {
                    question.Process(config, questionContext);
                }

                if (questionContext.ContainsMetadata)
                {
                    foreach (var question in _metadataQuestions)
                    {
                        question.Process(config, questionContext);
                    }
                }

                foreach (var question in _buildQuestions)
                {
                    question.Process(config, questionContext);
                }
                config.Build.MarkdownEngineName = "markdig";

                if (_options.OnlyConfigFile)
                {
                    GenerateConfigFile(_options.OutputFolder, config, _options.Quiet, _options.Overwrite);
                }
                else
                {
                    outputFolder = Path.GetFullPath(string.IsNullOrEmpty(_options.OutputFolder) ? DefaultOutputFolder : _options.OutputFolder).ToDisplayPath();
                    GenerateSeedProject(outputFolder, config, _options.Quiet, _options.Overwrite);
                }
            }
            catch (Exception e)
            {
                throw new DocfxInitException($"Error with init docfx project under \"{outputFolder}\" : {e.Message}", e);
            }
        }
Exemplo n.º 3
0
        public void Exec(SubCommandRunningContext context)
        {
            string name = null;
            string path = null;

            try
            {
                var config          = new DefaultConfigModel();
                var questionContext = new QuestionContext
                {
                    Quite = _options.Quiet
                };
                foreach (var question in _selectorQuestions)
                {
                    question.Process(config, questionContext);
                }

                if (questionContext.ContainsMetadata)
                {
                    foreach (var question in _metadataQuestions)
                    {
                        question.Process(config, questionContext);
                    }
                }

                foreach (var question in _buildQuestions)
                {
                    question.Process(config, questionContext);
                }

                name = string.IsNullOrEmpty(_options.Name) ? ConfigName : _options.Name;
                path = string.IsNullOrEmpty(_options.OutputFolder) ? name : Path.Combine(_options.OutputFolder, name);

                JsonUtility.Serialize(path, config, Formatting.Indented);
                Logger.LogInfo($"Generated {name} to {path}");
            }
            catch (Exception e)
            {
                throw new DocfxInitException($"Error init { name ?? ConfigName}: {e.Message}", e);
            }
        }
Exemplo n.º 4
0
        private void GenerateSeedProject(string outputFolder, DefaultConfigModel config, bool quiet, bool overwrite)
        {
            if (Directory.Exists(outputFolder))
            {
                if (!ProcessOverwriteQuestion($"Output folder \"{outputFolder}\" already exists. Do you still want to generate files into this folder? You can use -o command option to specify the folder name", quiet, true))
                {
                    return;
                }
            }
            else
            {
                Directory.CreateDirectory(outputFolder);
            }

            // 1. Create default files
            var srcFolder     = Path.Combine(outputFolder, "src");
            var apiFolder     = Path.Combine(outputFolder, "api");
            var apidocFolder  = Path.Combine(outputFolder, "apidoc");
            var articleFolder = Path.Combine(outputFolder, "articles");
            var imageFolder   = Path.Combine(outputFolder, "images");
            var folders       = new string[] { srcFolder, apiFolder, apidocFolder, articleFolder, imageFolder };

            foreach (var folder in folders)
            {
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                    $"Created folder {folder.ToDisplayPath()}".WriteLineToConsole(ConsoleColor.Gray);
                }
            }

            // 2. Create default files
            // a. toc.yml
            // b. index.md
            // c. articles/toc.yml
            // d. articles/index.md
            // e. .gitignore
            // f. api/.gitignore
            // TODO: move api/index.md out to some other folder
            var tocYaml           = Tuple.Create("toc.yml", @"- name: Articles
  href: articles/
- name: Api Documentation
  href: api/
  homepage: api/index.md
");
            var indexMarkdownFile = Tuple.Create("index.md", @"# This is the **HOMEPAGE**.
Refer to [Markdown](http://daringfireball.net/projects/markdown/) for how to write markdown files.
## Quick Start Notes:
1. Add images to the *images* folder if the file is referencing an image.
");
            var apiTocFile        = Tuple.Create("api/toc.yml", @"- name: TO BE REPLACED
  href: index.md
");
            var apiIndexFile      = Tuple.Create("api/index.md", @"# PLACEHOLDER
TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*!
");

            var articleTocFile      = Tuple.Create("articles/toc.yml", @"- name: Introduction
  href: intro.md
");
            var articleMarkdownFile = Tuple.Create("articles/intro.md", @"# Add your introductions here!
");
            var gitignore           = Tuple.Create(".gitignore", $@"###############
#    folder   #
###############
/**/DROP/
/**/TEMP/
/**/packages/
/**/bin/
/**/obj/
{config.Build.Destination}
");
            var apiGitignore        = Tuple.Create("api/.gitignore", $@"###############
#  temp file  #
###############
*.yml
.manifest
");
            var files = new Tuple <string, string>[] { tocYaml, indexMarkdownFile, apiTocFile, apiIndexFile, articleTocFile, articleMarkdownFile, gitignore, apiGitignore };

            foreach (var file in files)
            {
                var filePath = Path.Combine(outputFolder, file.Item1);

                if (overwrite || !File.Exists(filePath))
                {
                    var content = file.Item2;
                    var dir     = Path.GetDirectoryName(filePath);
                    if (!string.IsNullOrEmpty(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    File.WriteAllText(filePath, content);
                    $"Created File {filePath.ToDisplayPath()}".WriteLineToConsole(ConsoleColor.Gray);
                }
            }

            // 2. Create docfx.json
            var path = Path.Combine(outputFolder ?? string.Empty, ConfigName);

            if (overwrite || !File.Exists(path))
            {
                SaveConfigFile(path, config);
                $"Created config file {path.ToDisplayPath()}".WriteLineToConsole(ConsoleColor.Gray);
            }

            $"Successfully generated default docfx project to {outputFolder.ToDisplayPath()}".WriteLineToConsole(ConsoleColor.Green);
            "Please run:".WriteLineToConsole(ConsoleColor.Gray);
            $"\tdocfx \"{path.ToDisplayPath()}\" --serve".WriteLineToConsole(ConsoleColor.White);
            "To generate a default docfx website.".WriteLineToConsole(ConsoleColor.Gray);
        }