From 42681ee25495917bd6b708b10222b66914fb8222 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 27 Nov 2018 02:07:36 +0100 Subject: [PATCH] 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. --- tools/example-module/example-module.template | 3 ++- tools/example-module/generate-example-module.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/example-module/example-module.template b/tools/example-module/example-module.template index e932f664ddc..c3b2b1a5e06 100644 --- a/tools/example-module/example-module.template +++ b/tools/example-module/example-module.template @@ -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, diff --git a/tools/example-module/generate-example-module.ts b/tools/example-module/generate-example-module.ts index 09a8d22246a..5fae2304530 100644 --- a/tools/example-module/generate-example-module.ts +++ b/tools/example-module/generate-example-module.ts @@ -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'), ''); }