I have a simple schematic running that proves how schematics work as described in https://angular.io/guide/schematics-for-libraries
My next step is to do something relevent to my project using the schematic - What I want is to add a directive to all of my HTML angular templates in my application
For example if there is a HTML file that has content like this
<input name="input" [(ngModel)]="input" />
after running the schematic (adds the directive)
<input appInput name="input" [(ngModel)]="input" />
From the documentation or otherwise, I am unable to see how to loop through all the files and make this change to each file. Are there any examples/pointers for this use case?
I know ng update does it for migration from NG7 => NG8 to add this to the @ViewChild /** TO DO - static flag is mandatory */ but not able to narrow down the code for this.
Basically, what can I do here to get a handle to all the HTML files
export function appInputs(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
console.log('schematic called');
const workspaceConfig = tree.read('/angular.json');
// convert workspace to string
if (workspaceConfig) {
const workspaceContent = workspaceConfig.toString();
// parse workspace string into JSON object
const workspace: experimental.workspace.WorkspaceSchema = JSON.parse(workspaceContent);
console.log(workspace);
}
return tree;
};
}