forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-migration.ts
37 lines (32 loc) · 1.12 KB
/
template-migration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Migration, ResolvedResource} from '@angular/cdk/schematics';
import {SchematicContext} from '@angular-devkit/schematics';
import {visitElements, parseTemplate} from './tree-traversal';
import {ComponentMigrator} from '.';
export class TemplateMigration extends Migration<ComponentMigrator[], SchematicContext> {
enabled = true;
override visitTemplate(template: ResolvedResource) {
const ast = parseTemplate(template.content, template.filePath);
const migrators = this.upgradeData.filter(m => m.template).map(m => m.template!);
visitElements(
ast.nodes,
node => {
migrators.forEach(m => {
template.content = m.updateEndTag(template.content, node);
});
},
node => {
migrators.forEach(m => {
template.content = m.updateStartTag(template.content, node);
});
},
);
this.fileSystem.overwrite(template.filePath, template.content);
}
}