diff --git a/tools/workspace-plugin/src/generators/stories-map/generator.ts b/tools/workspace-plugin/src/generators/stories-map/generator.ts index 15cf8bb203320c..b1cc4b7eb04b1c 100644 --- a/tools/workspace-plugin/src/generators/stories-map/generator.ts +++ b/tools/workspace-plugin/src/generators/stories-map/generator.ts @@ -17,7 +17,8 @@ type StoriesMetadata = Array<{ | undefined; }>; -type AggregatedList = { [group_name: string]: Array<{ children: string[]; project: string }> }; +type GroupedList = { [group_name: string]: Array<{ children: string[]; project: string }> }; +type AggregatedGroupedList = { [group_name: string]: { [project_name: string]: string[] } }; export async function storiesMapGenerator(tree: Tree, _options: StoriesMapGeneratorSchema) { const stories = getStoriesMetadata(tree); @@ -28,19 +29,20 @@ export async function storiesMapGenerator(tree: Tree, _options: StoriesMapGenera writeJson(tree, '/stories-list.json', list); const githubIssueOptions = createOptions(list); + const yamlList = githubIssueOptions.map(item => `- ${item}`).join(`\n`); - console.log(githubIssueOptions); + console.log(yamlList); await formatFiles(tree); } export default storiesMapGenerator; -function createOptions(groups: AggregatedList) { +function createOptions(groups: AggregatedGroupedList) { const list: string[] = []; const components = { stable: [] as string[], preview: [] as string[], compat: [] as string[] }; - for (const [group, content] of Object.entries(groups)) { + for (const [group, entry] of Object.entries(groups)) { if (group === 'Utilities') { list.push(group); continue; @@ -57,42 +59,38 @@ function createOptions(groups: AggregatedList) { list.push(`${group}/Tokens`); continue; } + + const entriesForList = Object.values(entry).flat(); if (group === 'Migration Shims') { - const item = unique(content.map(val => val.children[0])).map(val => `${group} ${val}`); - list.push(...item); + const item = entriesForList.filter(val => /^V\d/.exec(val)); + list.push(...item.map(val => `${group} ${val}`)); continue; } if (group === 'Components') { - const item = unique(content.map(val => val.children[0])) - .sort() - .map(val => `${val}`); + const item = entriesForList.filter(val => val[0] === val[0].toUpperCase()).sort(); components.stable.push(...item); continue; } if (group === 'Compat Components') { - const item = unique(content.map(val => val.children[0])) - .sort() - .map(val => `${val} (Compat)`); + const item = entriesForList.sort().map(val => `${val} (Compat)`); components.compat.push(...item); continue; } if (group === 'Preview Components') { - const item = unique(content.map(val => val.children[0])) - .sort() - .map(val => `${val} (Preview)`); + const item = entriesForList.sort().map(val => `${val} (Preview)`); components.preview.push(...item); continue; } } - list.unshift(...components.stable, ...components.preview, ...components.compat); + list.sort().unshift(...components.stable, ...components.preview, ...components.compat); list.push('Other...'); return list; } function generateIssuesOptionList(tree: Tree, metadata: StoriesMetadata) { - const groups: AggregatedList = {}; + const groups: GroupedList = {}; for (const entry of metadata) { if (!entry.group) { @@ -104,7 +102,29 @@ function generateIssuesOptionList(tree: Tree, metadata: StoriesMetadata) { groups[entry.group.name].push({ project: entry.project.name!, children: unique(entry.group.children) }); } - return groups; + const aggregatedGroups = aggregateData(groups); + + return aggregatedGroups; + + function aggregateData(input: typeof groups): AggregatedGroupedList { + const output = Object.entries(input).reduce((acc, [group, entry]) => { + if (!acc[group]) { + acc[group] = {}; + } + entry.forEach(val => { + if (!acc[group][val.project]) { + acc[group][val.project] = []; + } + + acc[group][val.project].push(...val.children); + acc[group][val.project] = unique(acc[group][val.project]); + }); + + return acc; + }, {} as { [group_name: string]: { [project_name: string]: string[] } }); + + return output; + } } function getStoriesMetadata(tree: Tree) {