Skip to content

Commit d0d97c3

Browse files
josephperrottjelbourn
authored andcommittedNov 5, 2018
fix: reference symbols for example components rather than providing a string of the component name (#13992)
1 parent b662bfa commit d0d97c3

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed
 

‎tools/example-module/generate-example-module.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,25 @@ function inlineExampleModuleTemplate(parsedData: ExampleMetadata[]): string {
2727
return result.concat(data.component).concat(data.additionalComponents);
2828
}, [] as string[]).join(',');
2929

30-
const exampleComponents = parsedData.reduce((result, data) => {
31-
result[data.id] = {
32-
title: data.title,
33-
component: data.component,
34-
additionalFiles: data.additionalFiles,
35-
selectorName: data.selectorName.join(', '),
36-
};
37-
38-
return result;
30+
const exampleComponents = parsedData.map((metaData) => {
31+
const fields = [
32+
`title: '${metaData.title.trim()}'`,
33+
`component: ${metaData.component}`,
34+
];
35+
36+
if (metaData.additionalFiles.length) {
37+
fields.push(`additionalFiles: ${JSON.stringify(metaData.additionalFiles)}`);
38+
}
39+
if (metaData.selectorName.length) {
40+
fields.push(`selectorName: '${metaData.selectorName.join(', ')}'`);
41+
}
42+
const data = '\n' + fields.map(field => ' ' + field).join(',\n');
43+
return `'${metaData.id}': {${data}\n }`;
3944
}, {} as any);
4045

4146
return fs.readFileSync(require.resolve('./example-module.template'), 'utf8')
4247
.replace('${exampleImports}', exampleImports)
43-
.replace('${exampleComponents}', JSON.stringify(exampleComponents))
48+
.replace('${exampleComponents}', `{\n ${exampleComponents.join(',\n ')}}`)
4449
.replace('${exampleList}', `[${exampleList}]`);
4550
}
4651

0 commit comments

Comments
 (0)
Please sign in to comment.