Skip to content

Commit 0456af0

Browse files
authored
feat(migration): add stylePreprocessorOptions migration #12439 (#12459)
1 parent fb50e2f commit 0456af0

File tree

4 files changed

+113
-4
lines changed

4 files changed

+113
-4
lines changed

projects/igniteui-angular/migrations/migration-collection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@
130130
"version": "15.0.0",
131131
"description": "Updates Ignite UI for Angular from v14.1.x to v15.0.0",
132132
"factory": "./update-15_0_0"
133+
},
134+
"migration-27": {
135+
"version": "15.0.4",
136+
"description": "Updates Ignite UI for Angular from v15.0.x to v15.0.4",
137+
"factory": "./update-15_0_4"
133138
}
134139
}
135140
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as path from 'path';
2+
3+
import { EmptyTree } from '@angular-devkit/schematics';
4+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
5+
6+
const version = '15.0.4';
7+
8+
describe(`Update to ${version}`, () => {
9+
let appTree: UnitTestTree;
10+
const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json'));
11+
const configJson = {
12+
defaultProject: 'testProj',
13+
projects: {
14+
testProj: {
15+
root: '/',
16+
sourceRoot: '/testSrc',
17+
architect: {
18+
build: {
19+
options: {
20+
}
21+
}
22+
}
23+
}
24+
},
25+
version: 1
26+
};
27+
28+
beforeEach(() => {
29+
appTree = new UnitTestTree(new EmptyTree());
30+
appTree.create('/angular.json', JSON.stringify(configJson));
31+
});
32+
33+
const migrationName = 'migration-27';
34+
35+
it(`should add igniteui-theming to pacakage json and configure it`, async () => {
36+
const tree = await schematicRunner.runSchematicAsync(migrationName, {}, appTree)
37+
.toPromise();
38+
39+
expect(JSON.parse(JSON.stringify(tree.readContent('angular.json')))).toContain("stylePreprocessorOptions");
40+
});
41+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
Rule,
3+
SchematicContext,
4+
Tree
5+
} from '@angular-devkit/schematics';
6+
import { workspaces } from '@angular-devkit/core';
7+
import { UpdateChanges } from '../common/UpdateChanges';
8+
import { includeStylePreprocessorOptions } from '../../schematics/utils/dependency-handler';
9+
import { createHost } from '../../schematics/utils/util';
10+
11+
const version = '15.0.4';
12+
13+
export default (): Rule => async (host: Tree, context: SchematicContext) => {
14+
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
15+
16+
const update = new UpdateChanges(__dirname, host, context);
17+
update.applyChanges();
18+
19+
const workspaceHost = createHost(host);
20+
const { workspace } = await workspaces.readWorkspace(host.root.path, workspaceHost);
21+
await includeStylePreprocessorOptions(workspaceHost, workspace, context, host);
22+
await workspaces.writeWorkspace(workspace, workspaceHost);
23+
24+
// replace CSS custom properties prefix from --igx to --ig and grays to gray
25+
const CUSTOM_CSS_PROPERTIES = [
26+
'--igx-primary-',
27+
'--igx-secondary-',
28+
'--igx-grays-',
29+
'--igx-surface-',
30+
'--igx-info-',
31+
'--igx-success-',
32+
'--igx-warn-',
33+
'--igx-error-',
34+
'--igx-radius-factor',
35+
'--igx-elevation',
36+
'--igx-font-family',
37+
'--igx-h(\\d)-',
38+
'--igx-subtitle-(\\d)-',
39+
'--igx-body-(\\d)-',
40+
'--igx-button-',
41+
'--igx-caption-',
42+
'--igx-overline-'
43+
];
44+
for (const entryPath of update.sassFiles) {
45+
let content = host.read(entryPath).toString();
46+
CUSTOM_CSS_PROPERTIES.forEach(cssProperty => {
47+
const regex = new RegExp(cssProperty, 'g');
48+
if (regex.test(content)) {
49+
let newCssProperty = cssProperty.replace(/igx/g, 'ig');
50+
newCssProperty = newCssProperty.replace(/grays/g, 'gray');
51+
newCssProperty = newCssProperty.replace('(\\d)', '$1');
52+
content = content.replace(regex, newCssProperty);
53+
host.overwrite(entryPath, content);
54+
}
55+
});
56+
}
57+
};

projects/igniteui-angular/schematics/utils/dependency-handler.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const addDependencies = (options: Options) => async (tree: Tree, context:
9999

100100
await includeDependencies(workspaceHost, workspace, pkgJson, context, tree);
101101

102-
await includeStylePreprocessorOptions(workspaceHost, workspace, context, tree)
102+
await includeStylePreprocessorOptions(workspaceHost, workspace, context, tree);
103103

104104
addPackageToPkgJson(tree, schematicsPackage, pkgJson.igxDevDependencies[schematicsPackage], PackageTarget.DEV);
105105
};
@@ -157,7 +157,7 @@ const addHammerToConfig =
157157
}
158158
};
159159

160-
const includeStylePreprocessorOptions = async (workspaceHost: workspaces.WorkspaceHost, workspace: workspaces.WorkspaceDefinition, context: SchematicContext, tree: Tree): Promise<void> => {
160+
export const includeStylePreprocessorOptions = async (workspaceHost: workspaces.WorkspaceHost, workspace: workspaces.WorkspaceDefinition, context: SchematicContext, tree: Tree): Promise<void> => {
161161
await Promise.all(Array.from(workspace.projects.values()).map(async (project) => {
162162
await addStylePreprocessorOptions(project, tree, "build", context);
163163
await addStylePreprocessorOptions(project, tree, "test", context);
@@ -169,6 +169,13 @@ const includeStylePreprocessorOptions = async (workspaceHost: workspaces.Workspa
169169
const addStylePreprocessorOptions =
170170
async (project: workspaces.ProjectDefinition, tree: Tree, config: string, context: SchematicContext): Promise<void> => {
171171
const projectOptions = getTargetedProjectOptions(project, config, context);
172+
const warn = `Could not find a matching stylePreprocessorOptions includePaths array property under ${config} options. ` +
173+
`It could require you to manually update it to "stylePreprocessorOptions": { "includePaths": ["node_modules"] }`;
174+
175+
if (!projectOptions) {
176+
context.logger.warn(warn);
177+
return;
178+
}
172179

173180
// if there are no elements in the architect[config]options.stylePreprocessorOptions.includePaths that contain node_modules
174181
const stylePrepropPath = 'node_modules';
@@ -178,8 +185,7 @@ const addStylePreprocessorOptions =
178185
} else if (!projectOptions?.stylePreprocessorOptions) {
179186
projectOptions["stylePreprocessorOptions"] = { includePaths: [stylePrepropPath]};
180187
} else {
181-
context.logger.warn(`Could not find a matching stylePreprocessorOptions includePaths array property under ${config} options. ` +
182-
`It could require you to manually update it to "stylePreprocessorOptions": { "includePaths": ["node_modules"] }`);
188+
context.logger.warn(warn);
183189
}
184190
}
185191
};

0 commit comments

Comments
 (0)