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.
This commit is contained in:
Paul Gschwendtner
2018-11-27 02:07:36 +01:00
committed by Jeremy Elbourn
parent 4954bca555
commit 42681ee254
2 changed files with 5 additions and 4 deletions
+2 -1
View File
@@ -21,7 +21,8 @@ export interface LiveExample {
}
export const EXAMPLE_COMPONENTS: {[key: string]: LiveExample} = ${exampleComponents};
export const EXAMPLE_LIST = ${exampleList}
export const EXAMPLE_LIST = ${exampleList};
@NgModule({
declarations: EXAMPLE_LIST,
@@ -26,7 +26,7 @@ function inlineExampleModuleTemplate(parsedData: ExampleMetadata[]): string {
const quotePlaceholder = '◬';
const exampleList = parsedData.reduce((result, data) => {
return result.concat(data.component).concat(data.additionalComponents);
}, [] as string[]).join(',');
}, [] as string[]);
const exampleComponents = parsedData.reduce((result, data) => {
result[data.id] = {
@@ -44,8 +44,8 @@ function inlineExampleModuleTemplate(parsedData: ExampleMetadata[]): string {
return fs.readFileSync(require.resolve('./example-module.template'), 'utf8')
.replace('${exampleImports}', exampleImports)
.replace('${exampleComponents}', JSON.stringify(exampleComponents))
.replace('${exampleList}', `[${exampleList}]`)
.replace('${exampleComponents}', JSON.stringify(exampleComponents, null, 2))
.replace('${exampleList}', `[\n ${exampleList.join(',\n ')}\n]`)
.replace(new RegExp(`"${quotePlaceholder}|${quotePlaceholder}"`, 'g'), '');
}