Skip to content

Commit 62c0fbe

Browse files
committed
fix(core,platform): revert "schematics, deps, migrations, assets & styles (#8465)"
This reverts commit 1dc00d1.
1 parent aa30248 commit 62c0fbe

File tree

21 files changed

+483
-504
lines changed

21 files changed

+483
-504
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { SchematicContext, Tree } from '@angular-devkit/schematics';
2+
import { addModuleImportToModule, findModuleFromOptions } from '@angular/cdk/schematics';
3+
import { hasModuleImport } from '../utils/ng-module-utils';
4+
5+
const browserAnimationsModuleName = 'BrowserAnimationsModule';
6+
const noopAnimationsModuleName = 'NoopAnimationsModule';
7+
8+
// Configures animations modules
9+
export function addAnimations(options: any): any {
10+
return async (tree: Tree, context: SchematicContext) => {
11+
const modulePath = await findModuleFromOptions(tree, options);
12+
13+
if (options.animations) {
14+
if (hasModuleImport(tree, modulePath, noopAnimationsModuleName)) {
15+
context.logger.warn(
16+
`Could not set up "${browserAnimationsModuleName} because "${noopAnimationsModuleName}" is already imported. Please manually set up browser animations.`
17+
);
18+
19+
return tree;
20+
}
21+
22+
if (hasModuleImport(tree, modulePath, browserAnimationsModuleName)) {
23+
context.logger.info(
24+
`✅️ Import of ${browserAnimationsModuleName} already present in root module. Skipping.`
25+
);
26+
27+
return tree;
28+
}
29+
30+
addModuleImportToModule(
31+
tree,
32+
modulePath,
33+
browserAnimationsModuleName,
34+
'@angular/platform-browser/animations'
35+
);
36+
37+
context.logger.info(`✅️ Added ${browserAnimationsModuleName} to root module.`);
38+
39+
return tree;
40+
}
41+
42+
if (!hasModuleImport(tree, modulePath, browserAnimationsModuleName)) {
43+
addModuleImportToModule(tree, modulePath, noopAnimationsModuleName, '@angular/platform-browser/animations');
44+
45+
context.logger.info(`✅️ Added ${noopAnimationsModuleName} to root module.`);
46+
}
47+
48+
return tree;
49+
};
50+
}

libs/core/schematics/collection.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
"description": "Adds @fundamental-ngx/core to the project.",
66
"factory": "./ng-add/index#ngAdd",
77
"schema": "./ng-add/schema.json"
8+
},
9+
"add-animations": {
10+
"description": "Adds animations module imports using @angular/cdk tools.",
11+
"factory": "./add-animations/index#addAnimations"
12+
},
13+
"migrate-theme-fonts": {
14+
"description": "Updates @fundamental-ngx/core to the latest version changes.",
15+
"factory": "./migrations/migrate-theme-fonts/index#ngUpdate",
16+
"schema": "./migrations/migrate-theme-fonts/schema.json"
817
}
918
}
1019
}

libs/core/schematics/migrations.json

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { Rule, SchematicContext, Tree, chain, SchematicsException } from '@angular-devkit/schematics';
2+
import { WorkspaceSchema } from '@schematics/angular/utility/workspace-models';
3+
import { findStylesheetFiles } from '../../utils/file-utils';
4+
5+
import { sapFioriFonts, sapHorizonFonts } from './styles';
6+
import { Schema } from './schema';
7+
8+
export function ngUpdate(options: any): Rule {
9+
return chain([addStylePathToConfig(options), createThemingStyleFiles(options)]);
10+
}
11+
12+
interface AngularStyleObject {
13+
input: string;
14+
inject: boolean;
15+
bundleName: string;
16+
}
17+
18+
const FONT_FACE_REGEX = /(@font-face)[\w\s]?{[\s\S\W\w]+?(?=\s}\s)?\s?}/gi;
19+
20+
const themeFontFiles = ['sap_fiori_3_fonts', 'sap_horizon_fonts'];
21+
22+
function createThemingStyleFiles(options: Schema): Rule {
23+
return (tree: Tree, context: SchematicContext) => {
24+
const angularConfigPath = '/angular.json';
25+
const workspaceConfig = tree.read(angularConfigPath);
26+
27+
if (!workspaceConfig) {
28+
throw new SchematicsException(
29+
`❌ Unable to find angular.json. Please manually configure your styles array.`
30+
);
31+
}
32+
33+
const workspaceJson: WorkspaceSchema = JSON.parse(workspaceConfig.toString());
34+
35+
const sourceRoot = workspaceJson.projects[options.project].sourceRoot;
36+
37+
if (!tree.exists(`${sourceRoot}/theming/sap_fiori_3_fonts.css`)) {
38+
tree.create(`${sourceRoot}/theming/sap_fiori_3_fonts.css`, sapFioriFonts);
39+
context.logger.info(`✅️ Created sap_fiori_3_fonts.css file.`);
40+
}
41+
if (!tree.exists(`${sourceRoot}/theming/sap_horizon_fonts.css`)) {
42+
tree.create(`${sourceRoot}/theming/sap_horizon_fonts.css`, sapHorizonFonts);
43+
context.logger.info(`✅️ Created sap_horizon_fonts.css file.`);
44+
}
45+
46+
if (options.autofixFontStyles) {
47+
const styleSheets = findStylesheetFiles(tree).filter(
48+
(s) => !s.endsWith('sap_horizon_fonts.css') && !s.endsWith('sap_fiori_3_fonts.css')
49+
);
50+
context.logger.info(styleSheets.join());
51+
52+
if (styleSheets.length > 0) {
53+
styleSheets.forEach((styleSheet) => {
54+
let contents = tree.read(styleSheet).toString();
55+
56+
if (FONT_FACE_REGEX.test(contents)) {
57+
const matches = contents.match(FONT_FACE_REGEX).filter((m) => m.includes('/SAP-icons.woff'));
58+
59+
if (matches.length === 0) {
60+
return;
61+
}
62+
63+
matches.forEach((match) => {
64+
contents = contents.replace(match, '');
65+
});
66+
67+
tree.overwrite(styleSheet, contents);
68+
context.logger.info(`✅️ Successfully migrated ${styleSheet}.`);
69+
}
70+
});
71+
}
72+
}
73+
74+
context.logger.info(
75+
`⚠️ Notice: If you have imported SAP-Icon icon font styles from @sap-theming, please remove it since now it controlled by fundamental-ngx`
76+
);
77+
78+
return tree;
79+
};
80+
}
81+
82+
// Adds the icon style path to the angular.json.
83+
function addStylePathToConfig(options: any): Rule {
84+
return (tree: Tree, context: SchematicContext) => {
85+
const angularConfigPath = '/angular.json';
86+
const workspaceConfig = tree.read(angularConfigPath);
87+
88+
if (!workspaceConfig) {
89+
throw new SchematicsException(
90+
`❌ Unable to find angular.json. Please manually configure your styles array.`
91+
);
92+
}
93+
94+
const workspaceJson: WorkspaceSchema = JSON.parse(workspaceConfig.toString());
95+
96+
const sourceRoot = workspaceJson.projects[options.project].sourceRoot;
97+
98+
try {
99+
let stylesArray = (workspaceJson!.projects[options.project]!.architect!.build!.options as any)[
100+
'styles'
101+
] as (string | AngularStyleObject)[];
102+
103+
themeFontFiles.forEach((fontStyle) => {
104+
if (!stylesArray.find((style) => typeof style === 'object' && style.bundleName === `${fontStyle}`)) {
105+
stylesArray.push({
106+
input: `${sourceRoot}/theming/${fontStyle}.css`,
107+
inject: false,
108+
bundleName: fontStyle
109+
});
110+
context.logger.info(`✅️ Added ${fontStyle} font style to angular.json`);
111+
}
112+
});
113+
114+
(workspaceJson!.projects[options.project]!.architect!.build!.options as any)['styles'] = stylesArray;
115+
} catch (e) {
116+
throw new SchematicsException(
117+
`❌ Unable to find angular.json project styles. Please manually configure your styles array.`
118+
);
119+
}
120+
121+
tree.overwrite(angularConfigPath, JSON.stringify(workspaceJson, null, 2));
122+
123+
return tree;
124+
};
125+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"$id": "fundamental-ngx-ng-add",
4+
"title": "Fundamental Library for Angular ng-add schematic",
5+
"type": "object",
6+
"properties": {
7+
"project": {
8+
"type": "string",
9+
"description": "The name of the project.",
10+
"$default": {
11+
"$source": "projectName"
12+
}
13+
},
14+
"autofixFontStyles": {
15+
"type": "boolean",
16+
"default": true,
17+
"description": "Whether to try to automatically fix icon font imports",
18+
"x-prompt": "Try to automatically fix icon font imports?"
19+
}
20+
}
21+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Schema {
2+
project: string;
3+
autofixFontStyles: boolean;
4+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const sapFioriFonts = `
2+
@font-face {
3+
font-family: 'SAP-icons';
4+
src: url('~@sap-theming/theming-base-content/content/Base/baseLib/baseTheme/fonts/SAP-icons.woff') format('woff');
5+
font-weight: normal;
6+
font-style: normal;
7+
}
8+
`;
9+
10+
export const sapHorizonFonts = `
11+
@font-face {
12+
font-family: 'SAP-icons';
13+
src: url('~@sap-theming/theming-base-content/content/Base/baseLib/sap_horizon/fonts/SAP-icons.woff') format('woff');
14+
font-weight: normal;
15+
font-style: normal;
16+
}
17+
`;

libs/core/schematics/migrations/migration-0.36/index.ts

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)