From 77752b2ac1450169faadad710330faad35be9918 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sun, 10 Mar 2019 09:44:13 +0100 Subject: [PATCH] build: throw error if example is missing a title Throws a proper error message if one of the examples is missing a title, in order to avoid a more cryptic error down the line. --- tools/example-module/generate-example-module.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/example-module/generate-example-module.ts b/tools/example-module/generate-example-module.ts index 5fae23045308..6289786f8e51 100644 --- a/tools/example-module/generate-example-module.ts +++ b/tools/example-module/generate-example-module.ts @@ -61,6 +61,11 @@ function collectExampleMetadata(sourceFiles: string[], baseFile: string): Exampl const exampleMetadata: ExampleMetadata[] = []; for (const sourceFile of sourceFiles) { + // Avoid parsing non-example files. + if (!path.basename(sourceFile, path.extname(sourceFile)).endsWith('-example')) { + continue; + } + const sourceContent = fs.readFileSync(sourceFile, 'utf-8'); const {primaryComponent, secondaryComponents} = parseExampleFile(sourceFile, sourceContent); @@ -96,6 +101,9 @@ function collectExampleMetadata(sourceFiles: string[], baseFile: string): Exampl } exampleMetadata.push(example); + } else { + throw Error(`Could not find a primary example component in ${sourceFile}. ` + + `Ensure that there's a component with an @title annotation.`); } }