Example #1
0
        private static void MergeOptionsToConfig(MergeCommandOptions options, ref MergeJsonConfig config)
        {
            // base directory for content from command line is current directory
            // e.g. C:\folder1>docfx build folder2\docfx.json --content "*.cs"
            // for `--content "*.cs*`, base directory should be `C:\folder1`
            string optionsBaseDirectory = Directory.GetCurrentDirectory();

            config.OutputFolder = options.OutputFolder;

            if (!string.IsNullOrEmpty(options.OutputFolder)) config.Destination = Path.GetFullPath(Path.Combine(options.OutputFolder, config.Destination ?? string.Empty));
            if (options.Content != null)
            {
                if (config.Content == null)
                {
                    config.Content = new FileMapping(new FileMappingItem());
                }
                config.Content.Add(
                    new FileMappingItem
                    {
                        Files = new FileItems(options.Content),
                        SourceFolder = optionsBaseDirectory
                    });
            }
            config.FileMetadata = BuildCommand.GetFileMetadataFromOption(config.FileMetadata, options.FileMetadataFilePath, null);
            config.GlobalMetadata = BuildCommand.GetGlobalMetadataFromOption(config.GlobalMetadata, options.GlobalMetadataFilePath, null, options.GlobalMetadata);
            if (options.TocMetadata != null)
            {
                config.TocMetadata = new ListWithStringFallback(options.TocMetadata);
            }
        }
Example #2
0
        private static MergeJsonConfig ParseOptions(MergeCommandOptions options)
        {
            var configFile = options.ConfigFile;
            MergeJsonConfig config;
            if (string.IsNullOrEmpty(configFile))
            {
                if (!File.Exists(DocAsCode.Constants.ConfigFileName))
                {
                    if (options.Content == null)
                    {
                        throw new ArgumentException("Either provide config file or specify content files to start building documentation.");
                    }
                    else
                    {
                        config = new MergeJsonConfig();
                        MergeOptionsToConfig(options, ref config);
                        return config;
                    }
                }
                else
                {
                    Logger.Log(LogLevel.Verbose, $"Config file {DocAsCode.Constants.ConfigFileName} is found.");
                    configFile = DocAsCode.Constants.ConfigFileName;
                }
            }

            config = CommandUtility.GetConfig<MergeConfig>(configFile).Item;
            if (config == null) throw new DocumentException($"Unable to find build subcommand config in file '{configFile}'.");
            config.BaseDirectory = Path.GetDirectoryName(configFile);

            MergeOptionsToConfig(options, ref config);

            return config;
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var model = new MergeJsonConfig();
            var value = reader.Value;
            IEnumerable <JToken> jItems;

            if (reader.TokenType == JsonToken.StartArray)
            {
                jItems = JArray.Load(reader);
            }
            else if (reader.TokenType == JsonToken.String)
            {
                jItems = JRaw.Load(reader);
            }
            else
            {
                jItems = JObject.Load(reader);
            }

            if (jItems is JValue one)
            {
                model.Add(serializer.Deserialize <MergeJsonItemConfig>(one.CreateReader()));
            }
            else if (jItems is JObject)
            {
                model.Add(serializer.Deserialize <MergeJsonItemConfig>(((JToken)jItems).CreateReader()));
            }
            else
            {
                foreach (var item in jItems)
                {
                    MergeJsonItemConfig itemModel = serializer.Deserialize <MergeJsonItemConfig>(item.CreateReader());
                    model.Add(itemModel);
                }
            }

            return(model);
        }
Example #4
0
 public MergeCommand(MergeCommandOptions options)
 {
     Config = ParseOptions(options);
 }
Example #5
0
 private static MetadataMergeParameters ConfigToParameter(MergeJsonConfig config, string baseDirectory, string outputDirectory) =>
     new MetadataMergeParameters
     {
         OutputBaseDir = outputDirectory,
         Metadata = config.GlobalMetadata?.ToImmutableDictionary() ?? ImmutableDictionary<string, object>.Empty,
         FileMetadata = ConvertToFileMetadataItem(baseDirectory, config.FileMetadata),
         TocMetadata = config.TocMetadata?.ToImmutableList() ?? ImmutableList<string>.Empty,
         Files = GetFileCollectionFromFileMapping(
             baseDirectory,
             DocumentType.Article,
             GlobUtility.ExpandFileMapping(baseDirectory, config.Content)),
     };