Skip to content

Commit e477777

Browse files
committed
fixup! fixup! feat(workspace-plugin): implement stories-map generator to generate all v9 stories metadata
1 parent 393ecf9 commit e477777

File tree

1 file changed

+38
-18
lines changed
  • tools/workspace-plugin/src/generators/stories-map

1 file changed

+38
-18
lines changed

tools/workspace-plugin/src/generators/stories-map/generator.ts

+38-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ type StoriesMetadata = Array<{
1717
| undefined;
1818
}>;
1919

20-
type AggregatedList = { [group_name: string]: Array<{ children: string[]; project: string }> };
20+
type GroupedList = { [group_name: string]: Array<{ children: string[]; project: string }> };
21+
type AggregatedGroupedList = { [group_name: string]: { [project_name: string]: string[] } };
2122

2223
export async function storiesMapGenerator(tree: Tree, _options: StoriesMapGeneratorSchema) {
2324
const stories = getStoriesMetadata(tree);
@@ -28,19 +29,20 @@ export async function storiesMapGenerator(tree: Tree, _options: StoriesMapGenera
2829
writeJson(tree, '/stories-list.json', list);
2930

3031
const githubIssueOptions = createOptions(list);
32+
const yamlList = githubIssueOptions.map(item => `- ${item}`).join(`\n`);
3133

32-
console.log(githubIssueOptions);
34+
console.log(yamlList);
3335

3436
await formatFiles(tree);
3537
}
3638

3739
export default storiesMapGenerator;
3840

39-
function createOptions(groups: AggregatedList) {
41+
function createOptions(groups: AggregatedGroupedList) {
4042
const list: string[] = [];
4143
const components = { stable: [] as string[], preview: [] as string[], compat: [] as string[] };
4244

43-
for (const [group, content] of Object.entries(groups)) {
45+
for (const [group, entry] of Object.entries(groups)) {
4446
if (group === 'Utilities') {
4547
list.push(group);
4648
continue;
@@ -57,42 +59,38 @@ function createOptions(groups: AggregatedList) {
5759
list.push(`${group}/Tokens`);
5860
continue;
5961
}
62+
63+
const entriesForList = Object.values(entry).flat();
6064
if (group === 'Migration Shims') {
61-
const item = unique(content.map(val => val.children[0])).map(val => `${group} ${val}`);
62-
list.push(...item);
65+
const item = entriesForList.filter(val => /^V\d/.exec(val));
66+
list.push(...item.map(val => `${group} ${val}`));
6367
continue;
6468
}
6569
if (group === 'Components') {
66-
const item = unique(content.map(val => val.children[0]))
67-
.sort()
68-
.map(val => `${val}`);
70+
const item = entriesForList.filter(val => val[0] === val[0].toUpperCase()).sort();
6971
components.stable.push(...item);
7072
continue;
7173
}
7274
if (group === 'Compat Components') {
73-
const item = unique(content.map(val => val.children[0]))
74-
.sort()
75-
.map(val => `${val} (Compat)`);
75+
const item = entriesForList.sort().map(val => `${val} (Compat)`);
7676
components.compat.push(...item);
7777
continue;
7878
}
7979
if (group === 'Preview Components') {
80-
const item = unique(content.map(val => val.children[0]))
81-
.sort()
82-
.map(val => `${val} (Preview)`);
80+
const item = entriesForList.sort().map(val => `${val} (Preview)`);
8381
components.preview.push(...item);
8482
continue;
8583
}
8684
}
8785

88-
list.unshift(...components.stable, ...components.preview, ...components.compat);
86+
list.sort().unshift(...components.stable, ...components.preview, ...components.compat);
8987
list.push('Other...');
9088

9189
return list;
9290
}
9391

9492
function generateIssuesOptionList(tree: Tree, metadata: StoriesMetadata) {
95-
const groups: AggregatedList = {};
93+
const groups: GroupedList = {};
9694

9795
for (const entry of metadata) {
9896
if (!entry.group) {
@@ -104,7 +102,29 @@ function generateIssuesOptionList(tree: Tree, metadata: StoriesMetadata) {
104102
groups[entry.group.name].push({ project: entry.project.name!, children: unique(entry.group.children) });
105103
}
106104

107-
return groups;
105+
const aggregatedGroups = aggregateData(groups);
106+
107+
return aggregatedGroups;
108+
109+
function aggregateData(input: typeof groups): AggregatedGroupedList {
110+
const output = Object.entries(input).reduce((acc, [group, entry]) => {
111+
if (!acc[group]) {
112+
acc[group] = {};
113+
}
114+
entry.forEach(val => {
115+
if (!acc[group][val.project]) {
116+
acc[group][val.project] = [];
117+
}
118+
119+
acc[group][val.project].push(...val.children);
120+
acc[group][val.project] = unique(acc[group][val.project]);
121+
});
122+
123+
return acc;
124+
}, {} as { [group_name: string]: { [project_name: string]: string[] } });
125+
126+
return output;
127+
}
108128
}
109129

110130
function getStoriesMetadata(tree: Tree) {

0 commit comments

Comments
 (0)