Skip to content

Commit

Permalink
fixup! fixup! feat(workspace-plugin): implement stories-map generator…
Browse files Browse the repository at this point in the history
… to generate all v9 stories metadata
  • Loading branch information
Hotell committed Jan 9, 2025
1 parent 393ecf9 commit e477777
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions tools/workspace-plugin/src/generators/stories-map/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit e477777

Please sign in to comment.