/
template-migration.ts
30 lines (25 loc) · 1.08 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
/**
* @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 {parseTemplate} from './tree-traversal';
import {ComponentMigrator} from '.';
import {Update, writeUpdates} from '../../../migration-utilities';
export class TemplateMigration extends Migration<ComponentMigrator[], SchematicContext> {
enabled = true;
override visitTemplate(template: ResolvedResource) {
this.fileSystem.overwrite(template.filePath, this.migrate(template.content, template.filePath));
}
migrate(template: string, templateUrl?: string): string {
const ast = parseTemplate(template, templateUrl);
const migrators = this.upgradeData.filter(m => m.template).map(m => m.template!);
const updates: Update[] = [];
migrators.forEach(m => updates.push(...m.getUpdates(ast)));
return writeUpdates(template, updates);
}
}