Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions src/material/schematics/ng-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,31 @@ export function updateToV20(): Rule {
]);
}

// Whether the given path should be included when renaming theme token names.
function shouldRenameTokens(path: string) {
if (path.includes('node_modules') || path.includes('.angular') || path.includes('.git')) {
return false;
}

return (
path.endsWith('.html') ||
path.endsWith('.css') ||
path.endsWith('.scss') ||
path.endsWith('.ts')
);
}

// Renames any CSS variables beginning with "--mdc-" to be "--mat-". These CSS variables
// refer to tokens that used to be derived from a mix of MDC and Angular. Now all the tokens
// are converged on being prefixed "--mat-".
function renameMdcTokens(): Rule {
return tree => {
tree.visit(path => {
const content = tree.readText(path);
const updatedContent = content.replace('--mdc-', '--mat-');
tree.overwrite(path, updatedContent);
if (shouldRenameTokens(path)) {
const content = tree.readText(path);
const updatedContent = content.replace('--mdc-', '--mat-');
tree.overwrite(path, updatedContent);
}
});
};
}
Expand Down Expand Up @@ -78,13 +94,15 @@ function renameComponentTokens(): Rule {
];
return tree => {
tree.visit(path => {
const content = tree.readText(path);
let updatedContent = content;
for (const tokenPrefix of tokenPrefixes) {
updatedContent = updatedContent.replace(tokenPrefix.old, tokenPrefix.replacement);
}
if (content !== updatedContent) {
tree.overwrite(path, updatedContent);
if (shouldRenameTokens(path)) {
const content = tree.readText(path);
let updatedContent = content;
for (const tokenPrefix of tokenPrefixes) {
updatedContent = updatedContent.replace(tokenPrefix.old, tokenPrefix.replacement);
}
if (content !== updatedContent) {
tree.overwrite(path, updatedContent);
}
}
});
};
Expand Down
Loading