Skip to content

Commit c2f3d48

Browse files
crisbetommalerba
authored andcommitted
build: throw error if example is missing a title (#15430)
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.
1 parent ac7b3cd commit c2f3d48

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ function collectExampleMetadata(sourceFiles: string[], baseFile: string): Exampl
6161
const exampleMetadata: ExampleMetadata[] = [];
6262

6363
for (const sourceFile of sourceFiles) {
64+
// Avoid parsing non-example files.
65+
if (!path.basename(sourceFile, path.extname(sourceFile)).endsWith('-example')) {
66+
continue;
67+
}
68+
6469
const sourceContent = fs.readFileSync(sourceFile, 'utf-8');
6570
const {primaryComponent, secondaryComponents} = parseExampleFile(sourceFile, sourceContent);
6671

@@ -96,6 +101,9 @@ function collectExampleMetadata(sourceFiles: string[], baseFile: string): Exampl
96101
}
97102

98103
exampleMetadata.push(example);
104+
} else {
105+
throw Error(`Could not find a primary example component in ${sourceFile}. ` +
106+
`Ensure that there's a component with an @title annotation.`);
99107
}
100108
}
101109

0 commit comments

Comments
 (0)