Skip to content

Commit

Permalink
fix(material/schematics): run theming API migration during ng update
Browse files Browse the repository at this point in the history
Switches the `themingApi` migration from `ng generate` to `ng update`. Includes refactoring it into a `DevkitMigration` and changing the test setup to match.

(cherry picked from commit bd063bf)
  • Loading branch information
crisbeto authored and mmalerba committed May 7, 2021
1 parent 87d5432 commit d8f3c0b
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 163 deletions.
6 changes: 0 additions & 6 deletions src/material/schematics/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@
"factory": "./ng-generate/address-form/index",
"schema": "./ng-generate/address-form/schema.json",
"aliases": ["address-form", "material-address-form", "material-addressForm"]
},
"themingApi": {
"description": "Switch the project to the new @use-based Material theming API",
"factory": "./ng-generate/theming-api/index",
"schema": "./ng-generate/theming-api/schema.json",
"aliases": ["theming-api", "sass-api"]
}
}
}
28 changes: 0 additions & 28 deletions src/material/schematics/ng-generate/theming-api/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/material/schematics/ng-generate/theming-api/schema.json

This file was deleted.

9 changes: 0 additions & 9 deletions src/material/schematics/ng-generate/theming-api/schema.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/material/schematics/ng-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import {
SecondaryEntryPointsMigration
} from './migrations/package-imports-v8/secondary-entry-points-migration';
import {ThemingApiMigration} from './migrations/theming-api-v12/theming-api-migration';

import {materialUpgradeData} from './upgrade-data';

Expand All @@ -36,6 +37,7 @@ const materialMigrations: NullableDevkitMigration[] = [
RippleSpeedFactorMigration,
SecondaryEntryPointsMigration,
HammerGesturesMigration,
ThemingApiMigration,
];

/** Entry point for the migration schematics with target of Angular Material v6 */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 {extname} from '@angular-devkit/core';
import {DevkitMigration, ResolvedResource, TargetVersion} from '@angular/cdk/schematics';
import {migrateFileContent} from './migration';

/** Migration that switches all Sass files using Material theming APIs to `@use`. */
export class ThemingApiMigration extends DevkitMigration<null> {
enabled = this.targetVersion === TargetVersion.V12;

visitStylesheet(stylesheet: ResolvedResource): void {
if (extname(stylesheet.filePath) === '.scss') {
const content = stylesheet.content;
const migratedContent = content ? migrateFileContent(content,
'~@angular/material/', '~@angular/cdk/', '~@angular/material', '~@angular/cdk') : content;

if (migratedContent && migratedContent !== content) {
this.fileSystem.edit(stylesheet.filePath)
.remove(0, stylesheet.content.length)
.insertLeft(0, migratedContent);
}
}
}
}
Loading

0 comments on commit d8f3c0b

Please sign in to comment.