Example #1
0
        private static IList <string> ResolveAndExportYamlMetadata(
            Dictionary <string, MetadataItem> allMembers,
            Dictionary <string, ReferenceItem> allReferences,
            string folder,
            string indexFileName,
            string tocFileName,
            string apiFolder,
            bool preserveRawInlineComments,
            IEnumerable <string> externalReferencePackages)
        {
            var outputFiles = new List <string>();
            var model       = YamlMetadataResolver.ResolveMetadata(allMembers, allReferences, apiFolder, preserveRawInlineComments, externalReferencePackages);

            // 1. generate toc.yml
            outputFiles.Add(tocFileName);
            model.TocYamlViewModel.Type = MemberType.Toc;

            // TOC do not change
            var    tocViewModel = TocViewModel.FromModel(model.TocYamlViewModel);
            string tocFilePath  = Path.Combine(folder, tocFileName);

            YamlUtility.Serialize(tocFilePath, tocViewModel);

            ApiReferenceViewModel indexer = new ApiReferenceViewModel();

            // 2. generate each item's yaml
            var members = model.Members;

            foreach (var memberModel in members)
            {
                var outputPath = memberModel.Name + Constants.YamlExtension;

                outputFiles.Add(Path.Combine(apiFolder, outputPath));
                string itemFilePath = Path.Combine(folder, apiFolder, outputPath);
                Directory.CreateDirectory(Path.GetDirectoryName(itemFilePath));
                var memberViewModel = PageViewModel.FromModel(memberModel);
                YamlUtility.Serialize(itemFilePath, memberViewModel);
                Logger.Log(LogLevel.Verbose, $"Metadata file for {memberModel.Name} is saved to {itemFilePath}.");
                AddMemberToIndexer(memberModel, outputPath, indexer);
            }

            // 3. generate manifest file
            outputFiles.Add(indexFileName);
            string indexFilePath = Path.Combine(folder, indexFileName);

            JsonUtility.Serialize(indexFilePath, indexer);

            return(outputFiles);
        }