Skip to content

Commit c4bc6dd

Browse files
devversionjelbourn
authored andcommitted
build: pretty print example module (#14264)
* In order to debug the example data for the tests on `material.angular.io`, I had to look into the `example-module.ts` output, but it was nearly impossible to read because we don't pretty print the auto-generated code.
1 parent 6b92616 commit c4bc6dd

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

tools/example-module/example-module.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export interface LiveExample {
2121
}
2222

2323
export const EXAMPLE_COMPONENTS: {[key: string]: LiveExample} = ${exampleComponents};
24-
export const EXAMPLE_LIST = ${exampleList}
24+
25+
export const EXAMPLE_LIST = ${exampleList};
2526

2627
@NgModule({
2728
declarations: EXAMPLE_LIST,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function inlineExampleModuleTemplate(parsedData: ExampleMetadata[]): string {
2626
const quotePlaceholder = '◬';
2727
const exampleList = parsedData.reduce((result, data) => {
2828
return result.concat(data.component).concat(data.additionalComponents);
29-
}, [] as string[]).join(',');
29+
}, [] as string[]);
3030

3131
const exampleComponents = parsedData.reduce((result, data) => {
3232
result[data.id] = {
@@ -44,8 +44,8 @@ function inlineExampleModuleTemplate(parsedData: ExampleMetadata[]): string {
4444

4545
return fs.readFileSync(require.resolve('./example-module.template'), 'utf8')
4646
.replace('${exampleImports}', exampleImports)
47-
.replace('${exampleComponents}', JSON.stringify(exampleComponents))
48-
.replace('${exampleList}', `[${exampleList}]`)
47+
.replace('${exampleComponents}', JSON.stringify(exampleComponents, null, 2))
48+
.replace('${exampleList}', `[\n ${exampleList.join(',\n ')}\n]`)
4949
.replace(new RegExp(`"${quotePlaceholder}|${quotePlaceholder}"`, 'g'), '');
5050
}
5151

0 commit comments

Comments
 (0)