@@ -36,15 +36,31 @@ export function updateToV20(): Rule {
3636 ] ) ;
3737}
3838
39+ // Whether the given path should be included when renaming theme token names.
40+ function shouldRenameTokens ( path : string ) {
41+ if ( path . includes ( 'node_modules' ) || path . includes ( '.angular' ) || path . includes ( '.git' ) ) {
42+ return false ;
43+ }
44+
45+ return (
46+ path . endsWith ( '.html' ) ||
47+ path . endsWith ( '.css' ) ||
48+ path . endsWith ( '.scss' ) ||
49+ path . endsWith ( '.ts' )
50+ ) ;
51+ }
52+
3953// Renames any CSS variables beginning with "--mdc-" to be "--mat-". These CSS variables
4054// refer to tokens that used to be derived from a mix of MDC and Angular. Now all the tokens
4155// are converged on being prefixed "--mat-".
4256function renameMdcTokens ( ) : Rule {
4357 return tree => {
4458 tree . visit ( path => {
45- const content = tree . readText ( path ) ;
46- const updatedContent = content . replace ( '--mdc-' , '--mat-' ) ;
47- tree . overwrite ( path , updatedContent ) ;
59+ if ( shouldRenameTokens ( path ) ) {
60+ const content = tree . readText ( path ) ;
61+ const updatedContent = content . replace ( '--mdc-' , '--mat-' ) ;
62+ tree . overwrite ( path , updatedContent ) ;
63+ }
4864 } ) ;
4965 } ;
5066}
@@ -78,13 +94,15 @@ function renameComponentTokens(): Rule {
7894 ] ;
7995 return tree => {
8096 tree . visit ( path => {
81- const content = tree . readText ( path ) ;
82- let updatedContent = content ;
83- for ( const tokenPrefix of tokenPrefixes ) {
84- updatedContent = updatedContent . replace ( tokenPrefix . old , tokenPrefix . replacement ) ;
85- }
86- if ( content !== updatedContent ) {
87- tree . overwrite ( path , updatedContent ) ;
97+ if ( shouldRenameTokens ( path ) ) {
98+ const content = tree . readText ( path ) ;
99+ let updatedContent = content ;
100+ for ( const tokenPrefix of tokenPrefixes ) {
101+ updatedContent = updatedContent . replace ( tokenPrefix . old , tokenPrefix . replacement ) ;
102+ }
103+ if ( content !== updatedContent ) {
104+ tree . overwrite ( path , updatedContent ) ;
105+ }
88106 }
89107 } ) ;
90108 } ;
0 commit comments