Angular › Angular Schematics & Custom Builders
How would you create a custom schematic to generate a component following your own team's specific conventions?
AdvancedAnswer
You create a new schematic project using the Angular schematics CLI tools, define a rule function that describes what files to create and how to transform them, and package it as an npm library that your team can install and run using ng generate.
// A simplified custom schematic rule function
export function myComponent(options: any): Rule {
return (tree: Tree, context: SchematicContext) => {
const templateSource = apply(url('./files'), [template({ ...options })]);
return chain([mergeWith(templateSource)])(tree, context);
};
}Real-world example A large company builds a custom schematic that generates a new component pre wired with their specific logging setup and testing patterns, ensuring every new component across dozens of teams starts with the same consistent foundation.