예제 #1
0
        public bool TryLoadAndValidateToc(Config?config, out ToC?toc)
        {
            toc = null;

            if (config == null)
            {
                return(false);
            }

            var tocFile = new FsPath(_workdir).Combine(config.TOCFile);

            _log.Info("Parsing TOC file...");

            toc = MarkdownUtils.ParseToc(tocFile.ReadFile(_log));

            _log.Info("Found {0} chapters and {1} files", toc.ChapterCount, toc.FilesCount);
            TocValidator tocValidator = new TocValidator(toc, _workdir);

            tocValidator.Validate();

            if (!tocValidator.IsValid)
            {
                _log.Warning("Errors found in TOC file: ");
                foreach (var error in tocValidator.Errors)
                {
                    _log.Warning(error);
                }
                return(false);
            }

            _log.Info("Config file and TOC contain no errors");
            return(true);
        }
예제 #2
0
        public void EnsureThat_FsUtils_ReadFile_Works(string file, string expected)
        {
            var source = new FsPath(TestEnvironment.GetFile(file));

            string actual = source.ReadFile(TestEnvironment.GetMockedLog());

            Assert.AreEqual(expected, actual);
        }
예제 #3
0
        public string Generate(IArguments arguments)
        {
            var name = arguments.GetArgumentOrThrow <string>("file");

            FsPath file = new FsPath(name);

            _log.Detail("Inlineing {0}...", file);

            return(file.ReadFile(_log));
        }
예제 #4
0
        private static string GetDescription(ILog log, FsPath file)
        {
            using (var pipeline = new BookGenPipeline(BookGenPipeline.Plain))
            {
                string?content     = file.ReadFile(log).Replace('\n', ' ').Trim();
                string?description = pipeline.RenderMarkdown(content);

                var limit = description.Length < 190 ? description.Length : 190;
                return(description.Substring(0, limit) + "...");
            }
        }
예제 #5
0
 private static void ConvertChaptersToMarkdown(string workDir, ILog log, StringBuilder buffer, List <Chapter>?chapters)
 {
     foreach (var chapter in chapters)
     {
         buffer.AppendFormat("## {0}\r\n", chapter.Title);
         foreach (var file in chapter.Files)
         {
             FsPath path     = new FsPath(workDir, file);
             string content  = path.ReadFile(log);
             string subtitle = MarkdownUtils.GetTitle(content);
             buffer.AppendFormat("* [{0}]({1})", subtitle, file);
         }
         buffer.AppendLine();
     }
 }
예제 #6
0
        public string Generate(IArguments arguments)
        {
            var file = new FsPath(arguments.GetArgumentOrThrow <string>("file"));

            _log.Info("Trying to execute {0}", file);

            var nodeProgram = ProcessInterop.AppendExecutableExtension(processName);

            string?programPath = ProcessInterop.ResolveProgramFullPath(nodeProgram);

            if (programPath == null)
            {
                _log.Warning("{0} was not found on path.", processName);
                return($"{processName} was not found on path");
            }

            StringBuilder script = new StringBuilder(16 * 1024);

            script.AppendLine(SerializeHostInfo());
            script.AppendLine(file.ReadFile(_log));

            var temp = new FsPath(Path.GetTempFileName());

            temp.WriteFile(_log, script.ToString());

            var(exitcode, output) = ProcessInterop.RunProcess("node", temp.ToString(), ScriptTimeOut);

            if (temp.IsExisting)
            {
                File.Delete(temp.ToString());
            }

            if (exitcode != 0)
            {
                _log.Warning("Script run failed. Exit code: {0}", exitcode);
                _log.Detail("Script output: {0}", output);
                return($"Script run failed: {temp}");
            }
            else
            {
                return(output);
            }
        }
예제 #7
0
        public static string LoadTemplate(FsPath workingDirectory,
                                          BuildConfig buildConfig,
                                          ILog log,
                                          string FallBackTemplate)
        {
            if (string.IsNullOrEmpty(buildConfig.TemplateFile))
            {
                return(FallBackTemplate);
            }

            FsPath templatePath = workingDirectory.Combine(buildConfig.TemplateFile);

            if (!templatePath.IsExisting)
            {
                log.Warning("Template not found: {0}", buildConfig.TemplateFile);
                log.Info("Switching to built-in template.");
                return(FallBackTemplate);
            }

            return(templatePath.ReadFile(log));
        }