Skip to content

Commit 1153d21

Browse files
authored
fix(schematics): font and materials icons import, provideAnimations provider (#1740)
1 parent 1147db9 commit 1153d21

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

packages/ng-schematics/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"@igniteui/cli-core": "~15.4.0",
2525
"@schematics/angular": "^22.0.0",
2626
"minimatch": "^10.0.1",
27-
"rxjs": "~7.8.1"
27+
"rxjs": "~7.8.1",
28+
"typescript": "~5.6.2"
2829
},
2930
"devDependencies": {
3031
"@types/jasmine": "^5.1.4",
3132
"@types/minimatch": "^5.1.2",
3233
"@types/node": "^22.5.5",
33-
"jasmine": "^5.12.0",
34-
"typescript": "~5.6.2"
34+
"jasmine": "^5.12.0"
3535
},
3636
"ng-update": {
3737
"migrations": "./src/migrations/migration-collection.json"

packages/ng-schematics/src/cli-config/index_spec.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,75 @@ describe("cli-config schematic", () => {
129129
expect(headContentsRegex.exec(content)!.pop()).toContain("family=Material+Icons");
130130
});
131131

132+
it("should add Titillium and Material Icons when build options do not have index", async () => {
133+
const targetFile = "/src/index.html";
134+
const ngJsonWithoutBuildIndex = {
135+
projects: {
136+
testProj: {
137+
root: "",
138+
sourceRoot,
139+
architect: {
140+
build: {
141+
options: {
142+
main: `${sourceRoot}/main.ts`,
143+
polyfills: `${sourceRoot}/polyfills.ts`,
144+
scripts: []
145+
}
146+
},
147+
serve: {},
148+
test: {}
149+
}
150+
}
151+
},
152+
version: 1
153+
};
154+
155+
tree.overwrite("/angular.json", JSON.stringify(ngJsonWithoutBuildIndex));
156+
await runner.runSchematic("cli-config", {}, tree);
157+
158+
const content = tree.readContent(targetFile);
159+
const headContentsRegex = /(?:<head>)([\s\S]*)(?:<\/head>)/;
160+
expect(headContentsRegex.test(content)).toBeTruthy();
161+
expect(headContentsRegex.exec(content)!.pop()).toContain("family=Titillium+Web");
162+
expect(headContentsRegex.exec(content)!.pop()).toContain("family=Material+Icons");
163+
});
164+
165+
it("should add Titillium and Material Icons when build index is an object input", async () => {
166+
const targetFile = "/src/index.html";
167+
const ngJsonWithIndexObject = {
168+
projects: {
169+
testProj: {
170+
root: "",
171+
sourceRoot,
172+
architect: {
173+
build: {
174+
options: {
175+
main: `${sourceRoot}/main.ts`,
176+
polyfills: `${sourceRoot}/polyfills.ts`,
177+
scripts: [],
178+
index: {
179+
input: `${sourceRoot}/index.html`
180+
}
181+
}
182+
},
183+
serve: {},
184+
test: {}
185+
}
186+
}
187+
},
188+
version: 1
189+
};
190+
191+
tree.overwrite("/angular.json", JSON.stringify(ngJsonWithIndexObject));
192+
await runner.runSchematic("cli-config", {}, tree);
193+
194+
const content = tree.readContent(targetFile);
195+
const headContentsRegex = /(?:<head>)([\s\S]*)(?:<\/head>)/;
196+
expect(headContentsRegex.test(content)).toBeTruthy();
197+
expect(headContentsRegex.exec(content)!.pop()).toContain("family=Titillium+Web");
198+
expect(headContentsRegex.exec(content)!.pop()).toContain("family=Material+Icons");
199+
});
200+
132201
it("should add the default scss theme correctly", async () => {
133202
const targetFile = "/src/styles.scss";
134203
tree.create(targetFile, "");

packages/ng-schematics/src/utils/theme-import.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ export async function addFontsToIndexHtml(tree: Tree) {
2727
const materialIcons = '<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">';
2828
const projects = await getProjects(tree);
2929
projects.forEach(project => {
30-
const targetFile = project.targets.get("build")?.options?.index as string;
30+
const indexOptions = project.targets.get("build")?.options?.index as any;
31+
32+
// newer version of angular.json has index either as string or as object with input property
33+
let targetFile = typeof indexOptions === "string" ? indexOptions : indexOptions?.input;
34+
if (!targetFile && project.sourceRoot) {
35+
targetFile = path.posix.join(project.sourceRoot, "index.html");
36+
}
3137

3238
if (targetFile && tree.exists(targetFile)) {
3339
let content = tree.read(targetFile)!.toString();

0 commit comments

Comments
 (0)