@ui5/webcomponents-tools 0.0.0-c41f1b293 → 0.0.0-c48b38fdc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/README.md +2 -1
  3. package/assets-meta.js +15 -7
  4. package/components-package/eslint.js +2 -0
  5. package/components-package/nps.js +41 -32
  6. package/components-package/postcss.components.js +1 -21
  7. package/components-package/postcss.themes.js +1 -36
  8. package/components-package/vite.config.js +0 -3
  9. package/components-package/wdio.js +6 -2
  10. package/icons-collection/nps.js +6 -4
  11. package/lib/amd-to-es6/index.js +102 -0
  12. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  13. package/lib/cem/custom-elements-manifest.config.mjs +501 -0
  14. package/lib/cem/event.mjs +131 -0
  15. package/lib/cem/schema-internal.json +1357 -0
  16. package/lib/cem/schema.json +1098 -0
  17. package/lib/cem/types-internal.d.ts +796 -0
  18. package/lib/cem/types.d.ts +736 -0
  19. package/lib/cem/utils.mjs +384 -0
  20. package/lib/cem/validate.js +70 -0
  21. package/lib/create-illustrations/index.js +51 -30
  22. package/lib/create-new-component/index.js +1 -1
  23. package/lib/create-new-component/jsFileContentTemplate.js +1 -1
  24. package/lib/create-new-component/tsFileContentTemplate.js +3 -12
  25. package/lib/css-processors/css-processor-component-styles.mjs +47 -0
  26. package/lib/css-processors/css-processor-components.mjs +77 -0
  27. package/lib/css-processors/css-processor-themes.mjs +79 -0
  28. package/lib/css-processors/scope-variables.mjs +49 -0
  29. package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
  30. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  31. package/lib/generate-custom-elements-manifest/index.js +51 -107
  32. package/lib/generate-js-imports/illustrations.js +78 -64
  33. package/lib/generate-json-imports/i18n.js +10 -5
  34. package/lib/generate-json-imports/themes.js +10 -5
  35. package/lib/jsdoc/preprocess.js +1 -1
  36. package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
  37. package/lib/scoping/get-all-tags.js +1 -1
  38. package/lib/scoping/scope-test-pages.js +2 -1
  39. package/package.json +12 -11
  40. package/lib/esm-abs-to-rel/index.js +0 -58
  41. package/lib/postcss-css-to-json/index.js +0 -47
  42. package/lib/postcss-new-files/index.js +0 -36
  43. package/lib/postcss-p/postcss-p.mjs +0 -14
  44. package/lib/replace-global-core/index.js +0 -25
@@ -1,72 +1,86 @@
1
1
  const fs = require("fs").promises;
2
- const path = require('path');
3
-
4
- const generate = async () => {
5
- const fioriInputFolder = path.normalize(process.argv[2]);
6
- const tntInputFolder = path.normalize(process.argv[3]);
7
- const outputFile = path.normalize(`${process.argv[4]}/Illustrations.js`);
8
-
9
- const dir = await fs.readdir(fioriInputFolder);
10
- const fioriIllustrationsOnFileSystem = dir.map(illustrationName => {
11
- const fioriMatches = illustrationName.match(/.*\.js$/);
12
- return fioriMatches ? illustrationName : undefined;
13
- }).filter(key => !!key);
14
-
15
- const tntDir = await fs.readdir(tntInputFolder);
16
- const tntIllustrationsOnFileSystem = tntDir.map(illustrationName => {
17
- const tntMatches = illustrationName.match(/.*\.js$/);
18
- return tntMatches ? illustrationName : undefined;
19
- }).filter(key => !!key);
20
-
21
- // dynamic imports for Fiori illustrations
22
- const fioriAvailableIllustrationsArray = `[${fioriIllustrationsOnFileSystem.filter(
23
- // skipping the items starting with sapIllus-Dialog, sapIllus-Scene, sapIllus-Spot since they are included in the illustration's js file
24
- line => !line.startsWith("sapIllus-Dialog") && !line.startsWith("sapIllus-Scene") && !line.startsWith("sapIllus-Spot") && !line.startsWith("AllIllustrations")).map(illustrationName => `"${illustrationName.replace('.js', '')}"`).join(", ")}]`;
25
-
26
- const fioriDynamicImportLines = fioriIllustrationsOnFileSystem.map(illustrationName =>
27
- `\t\tcase "${illustrationName.replace('.js', '')}": return (await import("../../illustrations/${illustrationName}")).default;`).filter(
28
- // skipping the items starting with sapIllus-Dialog, sapIllus-Scene, sapIllus-Spot since they are included in the illustration's js file
29
- line => !line.startsWith("\t\tcase \"sapIllus-Dialog") && !line.startsWith("\t\tcase \"sapIllus-Scene") && !line.startsWith("\t\tcase \"sapIllus-Spot") && !line.startsWith("\t\tcase \"AllIllustrations")).join("\n");
30
-
31
- // dynamic imports for Tnt illustrations
32
- const tntAvailableIllustrationsArray = `[${tntIllustrationsOnFileSystem.filter(
33
- // skipping the items starting with tnt-Dialog, tnt-Scene, tnt-Spot since they are included in the illustration's js file
34
- line => !line.startsWith("tnt-Dialog") && !line.startsWith("tnt-Scene") && !line.startsWith("tnt-Spot")).map(illustrationName => `"Tnt${illustrationName.replace('.js', '')}"`).join(", ")}]`;
35
-
36
- const tntDynamicImportLines = tntIllustrationsOnFileSystem.map(illustrationName =>
37
- `\t\tcase "Tnt${illustrationName.replace('.js', '')}": return (await import("../../illustrations/tnt/${illustrationName}")).default;`).filter(
38
- // skipping the items starting with tnt-Dialog, tnt-Scene, tnt-Spot since they are included in the illustration's js file
39
- line => !line.startsWith("\t\tcase \"Tnttnt-Dialog") && !line.startsWith("\t\tcase \"Tnttnt-Scene") && !line.startsWith("\t\tcase \"Tnttnt-Spot")).join("\n");
40
-
41
-
42
- // dynamic imports file content
43
- const contentDynamic = `import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
44
-
45
- const loadIllustration = async (illustrationName) => {
46
- switch (illustrationName) {
47
- ${fioriDynamicImportLines}
48
- ${tntDynamicImportLines}
49
- default: throw new Error("[Illustrations] Illustration not found: " + illustrationName);
50
- }
2
+ const path = require("path");
3
+
4
+ const generateDynamicImportLines = async (fileNames, location, exclusionPatterns = []) => {
5
+ const packageName = JSON.parse(await fs.readFile("package.json")).name;
6
+ return fileNames
7
+ .filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
8
+ .map((fileName) => {
9
+ const illustrationName = fileName.replace(".js", "");
10
+ const illustrationPath = `${location}/${illustrationName}`;
11
+ return `\t\tcase "${fileName.replace('.js', '')}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-${illustrationName.toLowerCase()}" */ "${illustrationPath}.js")).default;`;
12
+ })
13
+ .join("\n");
14
+ };
15
+
16
+ const generateAvailableIllustrationsArray = (fileNames, exclusionPatterns = []) => {
17
+ return JSON.stringify(
18
+ fileNames
19
+ .filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
20
+ .map((fileName) => fileName.replace(".js", ""))
21
+ );
22
+ };
23
+
24
+ const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, set, prefix = "") => {
25
+ return `// @ts-nocheck
26
+ import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
27
+
28
+ export const loadIllustration = async (illustrationName) => {
29
+ const collectionAndPrefix = "${set}/${collection}/${prefix}";
30
+ const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
31
+ switch (cleanIllustrationName) {
32
+ ${dynamicImports}
33
+ default:
34
+ throw new Error("[Illustrations] Illustration not found: " + illustrationName);
35
+ }
36
+ };
37
+
38
+ const loadAndCheck = async (illustrationName) => {
39
+ const data = await loadIllustration(illustrationName);
40
+ return data;
41
+ };
42
+
43
+ ${availableIllustrations}.forEach((illustrationName) =>
44
+ registerIllustrationLoader(\`${set}/${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
45
+ );
46
+ `;
47
+ };
48
+
49
+ const getMatchingFiles = async (folder, pattern) => {
50
+ const dir = await fs.readdir(folder);
51
+ return dir.filter((fileName) => fileName.match(pattern));
51
52
  };
52
- const loadAndCheck = async (illustrationName) => {
53
- const data = await loadIllustration(illustrationName);
54
- return data;
55
- }
56
53
 
54
+ const generateIllustrations = async (config) => {
55
+ const { inputFolder, outputFile, collection, location, prefix, filterOut, set } = config;
56
+
57
+ const normalizedInputFolder = path.normalize(inputFolder);
58
+ const normalizedOutputFile = path.normalize(outputFile);
59
+
60
+ const illustrations = await getMatchingFiles(normalizedInputFolder, /^.*\.js$/);
57
61
 
58
- ${fioriAvailableIllustrationsArray}.forEach(illustrationName => registerIllustrationLoader(illustrationName, loadAndCheck));
59
- ${tntAvailableIllustrationsArray}.forEach(illustrationName => registerIllustrationLoader(illustrationName, loadAndCheck));`;
60
-
62
+ const dynamicImports = await generateDynamicImportLines(illustrations, location, filterOut);
63
+ const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
64
+
65
+ const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, set, prefix);
66
+
67
+ await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
68
+ await fs.writeFile(normalizedOutputFile, contentDynamic);
69
+
70
+ console.log(`Generated ${normalizedOutputFile}`);
71
+ };
61
72
 
62
- await fs.mkdir(path.dirname(outputFile), { recursive: true });
63
- return Promise.all([fs.writeFile(outputFile, contentDynamic)]);
73
+ // Parse configuration from command-line arguments
74
+ const config = {
75
+ inputFolder: process.argv[2],
76
+ outputFile: process.argv[3],
77
+ set: process.argv[4],
78
+ collection: process.argv[5],
79
+ location: process.argv[6],
80
+ filterOut: process.argv.slice[7],
64
81
  };
65
82
 
66
- generate().then(() => {
67
- console.log("Generated Illustrations.js");
68
- })
69
- .catch(err => {
70
- console.error(err);
71
- process.exit(1);
83
+ // Run the generation process
84
+ generateIllustrations(config).catch((error) => {
85
+ console.error("Error generating illustrations:", error);
72
86
  });
@@ -1,13 +1,16 @@
1
1
  const fs = require("fs").promises;
2
2
  const path = require('path');
3
3
 
4
+ const isTypeScript = process.env.UI5_TS;
5
+ const ext = isTypeScript ? 'ts' : 'js';
6
+
4
7
  const generate = async () => {
5
8
 
6
9
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
7
10
 
8
11
  const inputFolder = path.normalize(process.argv[2]);
9
- const outputFile = path.normalize(`${process.argv[3]}/i18n-static.js`);
10
- const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.js`);
12
+ const outputFile = path.normalize(`${process.argv[3]}/i18n-static.${ext}`);
13
+ const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.${ext}`);
11
14
 
12
15
  // All languages present in the file system
13
16
  const files = await fs.readdir(inputFolder);
@@ -32,7 +35,8 @@ const generate = async () => {
32
35
  const assetsImportsString = languages.map(key => `import _${key} from "../assets/i18n/messagebundle_${key}.json";`).join("\n");
33
36
 
34
37
  // static imports
35
- contentStatic = `import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
38
+ contentStatic = `// @ts-nocheck
39
+ import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
36
40
 
37
41
  ${assetsImportsString}
38
42
 
@@ -56,10 +60,11 @@ localeIds.forEach(localeId => {
56
60
  `;
57
61
 
58
62
  // Actual imports for json assets
59
- const dynamicImportsString = languages.map(key => ` case "${key}": return (await import("../assets/i18n/messagebundle_${key}.json")).default;`).join("\n");
63
+ const dynamicImportsString = languages.map(key => ` case "${key}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-messagebundle-${key}" */ "../assets/i18n/messagebundle_${key}.json")).default;`).join("\n");
60
64
 
61
65
  // Resulting file content
62
- contentDynamic = `import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
66
+ contentDynamic = `// @ts-nocheck
67
+ import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
63
68
 
64
69
  const importMessageBundle = async (localeId) => {
65
70
  switch (localeId) {
@@ -2,10 +2,13 @@ const fs = require("fs").promises;
2
2
  const path = require('path');
3
3
  const assets = require("../../assets-meta.js");
4
4
 
5
+ const isTypeScript = process.env.UI5_TS;
6
+ const ext = isTypeScript ? 'ts' : 'js';
7
+
5
8
  const generate = async () => {
6
9
  const inputFolder = path.normalize(process.argv[2]);
7
- const outputFile = path.normalize(`${process.argv[3]}/Themes-static.js`);
8
- const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes.js`);
10
+ const outputFile = path.normalize(`${process.argv[3]}/Themes-static.${ext}`);
11
+ const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes.${ext}`);
9
12
 
10
13
  // All supported optional themes
11
14
  const allThemes = assets.themes.all;
@@ -22,11 +25,12 @@ const generate = async () => {
22
25
  const importLines = themesOnFileSystem.map(theme => `import ${theme} from "../assets/themes/${theme}/parameters-bundle.css.json";`).join("\n");
23
26
  const themeUrlsByName = "{\n" + themesOnFileSystem.join(",\n") + "\n}";
24
27
  const availableThemesArray = `[${themesOnFileSystem.map(theme => `"${theme}"`).join(", ")}]`;
25
- const dynamicImportLines = themesOnFileSystem.map(theme => `\t\tcase "${theme}": return (await import("../assets/themes/${theme}/parameters-bundle.css.json")).default;`).join("\n");
28
+ const dynamicImportLines = themesOnFileSystem.map(theme => `\t\tcase "${theme}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-${theme.replace("_", "-")}-parameters-bundle" */"../assets/themes/${theme}/parameters-bundle.css.json")).default;`).join("\n");
26
29
 
27
30
 
28
31
  // static imports file content
29
- const contentStatic = `import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
32
+ const contentStatic = `// @ts-nocheck
33
+ import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
30
34
 
31
35
  ${importLines}
32
36
 
@@ -47,7 +51,8 @@ ${availableThemesArray}
47
51
 
48
52
 
49
53
  // dynamic imports file content
50
- const contentDynamic = `import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
54
+ const contentDynamic = `// @ts-nocheck
55
+ import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
51
56
 
52
57
  const loadThemeProperties = async (themeName) => {
53
58
  switch (themeName) {
@@ -116,7 +116,7 @@ const processComponentFile = async (fileName) => {
116
116
  const destFileName = fileName.replace(sourceDir, inputDir).replace(/\.ts$/, ".js");
117
117
  let jsFileContent = `${await fs.readFile(destFileName)}`;
118
118
 
119
- const classDefinitionRegExp = new RegExp(`let.*? = class`, "gm");
119
+ const classDefinitionRegExp = new RegExp(`(let.*? = class)|(^class.*?)`, "gm");
120
120
  let classDefinitionMatch = jsFileContent.match(classDefinitionRegExp);
121
121
  if (!classDefinitionMatch) {
122
122
  return; // not a file, generated by typescript, nothing to do here
@@ -154,22 +154,29 @@ module.exports = (options) => {
154
154
  options.removeDuplicatedProperties ||
155
155
  options.removeDuplicatedValues
156
156
  ) {
157
- removeDupProperties(
158
- destination,
159
- options.removeDuplicatedValues,
160
- );
157
+ // removeDupProperties(
158
+ // destination,
159
+ // options.removeDuplicatedValues,
160
+ // );
161
161
  }
162
162
  } else {
163
163
  if (
164
164
  options.removeDuplicatedProperties ||
165
165
  options.removeDuplicatedValues
166
166
  ) {
167
- removeDupProperties(rule, options.removeDuplicatedValues);
167
+ // removeDupProperties(rule, options.removeDuplicatedValues);
168
168
  }
169
169
  // add new selector to symbol table
170
170
  map.set(selector, rule);
171
171
  }
172
172
  },
173
+ OnceExit(root) {
174
+ root.nodes.forEach(node => {
175
+ if (node.type === "rule") {
176
+ removeDupProperties(node, options.removeDuplicatedValues);
177
+ }
178
+ })
179
+ }
173
180
  };
174
181
  },
175
182
  };
@@ -10,7 +10,7 @@ const getTag = file => {
10
10
 
11
11
  const getPackageTags = (packageDir) => {
12
12
  const srcDir = path.join(packageDir, "src/");
13
- return glob.sync(path.join(srcDir, "/**/*.js")).flatMap(file => {
13
+ return glob.sync(path.join(srcDir, "/**/*.ts")).flatMap(file => {
14
14
  const tag = getTag(file);
15
15
  return [tag];
16
16
  }).filter(item => !!item);
@@ -18,6 +18,7 @@ const replaceTagsHTML = content => {
18
18
 
19
19
  // Replace tags in any content
20
20
  const replaceTagsAny = content => {
21
+ console.log(tags.length);
21
22
  tags.forEach(tag => {
22
23
  content = content.replace(new RegExp(`(^|[^\-_A-Za-z0-9])(${tag})([^\-_A-Za-z0-9]|$)`, "g"), `$1$2-${suffix}$3`);
23
24
  });
@@ -27,7 +28,7 @@ const replaceTagsAny = content => {
27
28
  // Replace bundle names and HTML tag names in test pages
28
29
  glob.sync(path.join(root, "/**/*.html")).forEach(file => {
29
30
  let content = String(fs.readFileSync(file));
30
- content = content.replace(/bundle\.(.*?)\.js/g, `../bundle.scoped.$1.js`);
31
+ content = content.replace("%VITE_BUNDLE_PATH%", "%VITE_BUNDLE_PATH_SCOPED%");
31
32
  content = replaceTagsHTML(content);
32
33
  fs.writeFileSync(file, content);
33
34
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-tools",
3
- "version": "0.0.0-c41f1b293",
3
+ "version": "0.0.0-c48b38fdc",
4
4
  "description": "UI5 Web Components: webcomponents.tools",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -21,23 +21,26 @@
21
21
  "directory": "packages/tools"
22
22
  },
23
23
  "dependencies": {
24
- "@typescript-eslint/eslint-plugin": "^5.42.1",
25
- "@typescript-eslint/parser": "^5.42.1",
24
+ "@custom-elements-manifest/analyzer": "^0.8.4",
25
+ "@typescript-eslint/eslint-plugin": "^6.9.0",
26
+ "@typescript-eslint/parser": "^6.9.0",
26
27
  "@wdio/cli": "^7.19.7",
27
- "@wdio/devtools-service": "^7.19.7",
28
28
  "@wdio/dot-reporter": "^7.19.7",
29
29
  "@wdio/local-runner": "^7.19.7",
30
30
  "@wdio/mocha-framework": "^7.19.7",
31
31
  "@wdio/spec-reporter": "^7.19.7",
32
32
  "@wdio/static-server-service": "^7.19.5",
33
+ "ajv": "^8.12.0",
34
+ "cem-plugin-vs-code-custom-data-generator": "^1.4.2",
33
35
  "chai": "^4.3.4",
34
36
  "child_process": "^1.0.2",
35
37
  "chokidar": "^3.5.1",
36
38
  "chokidar-cli": "^3.0.0",
37
39
  "command-line-args": "^5.1.1",
40
+ "comment-parser": "^1.4.0",
38
41
  "concurrently": "^6.0.0",
39
42
  "cross-env": "^7.0.3",
40
- "cssnano": "^4.1.11",
43
+ "custom-element-jet-brains-integration": "^1.4.4",
41
44
  "escodegen": "^2.0.0",
42
45
  "eslint": "^7.22.0",
43
46
  "eslint-config-airbnb-base": "^14.2.1",
@@ -52,11 +55,9 @@
52
55
  "jsdoc": "^3.6.6",
53
56
  "json-beautify": "^1.1.1",
54
57
  "mkdirp": "^1.0.4",
55
- "modify-selectors": "^2.0.0",
56
58
  "nps": "^5.10.0",
57
59
  "postcss": "^8.4.5",
58
60
  "postcss-cli": "^9.1.0",
59
- "postcss-import": "^14.0.2",
60
61
  "postcss-selector-parser": "^6.0.10",
61
62
  "prompts": "^2.4.2",
62
63
  "properties-reader": "^2.2.0",
@@ -64,13 +65,12 @@
64
65
  "resolve": "^1.20.0",
65
66
  "rimraf": "^3.0.2",
66
67
  "slash": "3.0.0",
67
- "vite": "^3.0.4",
68
- "wdio-chromedriver-service": "^7.3.2",
69
- "zx": "^4.3.0"
68
+ "vite": "^4.4.9",
69
+ "wdio-chromedriver-service": "^7.3.2"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "chromedriver": "*",
73
- "typescript": "^4.9.4"
73
+ "typescript": "5.2.2"
74
74
  },
75
75
  "peerDependenciesMeta": {
76
76
  "typescript": {
@@ -78,6 +78,7 @@
78
78
  }
79
79
  },
80
80
  "devDependencies": {
81
+ "esbuild": "^0.19.9",
81
82
  "yargs": "^17.5.1"
82
83
  }
83
84
  }
@@ -1,58 +0,0 @@
1
- const esprima = require("esprima");
2
- const escodegen = require("escodegen");
3
-
4
- const fs = require("fs").promises;
5
- const path = require("path");
6
- const basePath = process.argv[2];
7
-
8
- const convertImports = async (srcPath) => {
9
- let changed = false;
10
- // console.log("scanning imports of", srcPath);
11
- let code = (await fs.readFile(srcPath)).toString();
12
- const tree = esprima.parseModule(code);
13
- const importer = srcPath.replace(basePath, "");
14
- const importerDir = path.dirname(importer);
15
- // console.log("-> ", importer);
16
- tree.body.forEach(node => {
17
- if (node.type === "ImportDeclaration") {
18
- let importee = node.source.value;
19
- if (importee.startsWith(".")) {
20
- // add .js extension if missing
21
- if (!importee.endsWith(".js")) {
22
- node.source.value += ".js"
23
- changed = true;
24
- }
25
- return;
26
- }
27
- let importeeDir = path.dirname(importee);
28
- let importeeFile = path.basename(importee);
29
- let relativePath = path.relative(importerDir, importeeDir);
30
- if (relativePath.length === 0) {
31
- relativePath = "."
32
- }
33
- if (!relativePath.startsWith(".")) {
34
- relativePath = "./" + relativePath;
35
- }
36
-
37
- relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
38
- let relativeImport = `${relativePath}/${importeeFile}.js`;
39
- // console.log(importee + " --> " + relativeImport);
40
- node.source.value = relativeImport;
41
- changed = true;
42
- }
43
- });
44
-
45
- if (changed) {
46
- return fs.writeFile(srcPath, escodegen.generate(tree));
47
- }
48
- }
49
-
50
- const generate = async () => {
51
- const { globby } = await import("globby");
52
- const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
53
- return Promise.all(fileNames.map(convertImports).filter(x => !!x));
54
- };
55
-
56
- generate().then(() => {
57
- console.log("Success: Converted absolute imports to relative for files in:", basePath);
58
- });
@@ -1,47 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const mkdirp = require('mkdirp');
4
-
5
- const proccessCSS = css => {
6
- css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
7
- css = css.replace(/\.background-image.*{.*}/, "");
8
- css = css.replace(/\.sapContrast[ ]*:root[\s\S]*?}/, "");
9
- css = css.replace(/--sapFontUrl.*\);?/, "");
10
- return css;
11
- }
12
-
13
- module.exports = function (opts) {
14
- opts = opts || {};
15
-
16
- return {
17
- postcssPlugin: 'postcss-css-to-json',
18
- Once (root) {
19
- let css = root.toString();
20
- css = proccessCSS(css);
21
-
22
- const targetFile = root.source.input.from.replace(`/${opts.toReplace}/`, "/dist/generated/assets/").replace(`\\${opts.toReplace}\\`, "\\dist\\generated\\assets\\");
23
- mkdirp.sync(path.dirname(targetFile));
24
-
25
- const filePath = `${targetFile}.json`;
26
- const data = {
27
- packageName: opts.packageName,
28
- fileName: targetFile.substr(targetFile.lastIndexOf("themes")),
29
- content: css
30
- };
31
- // it seems slower to read the old content, but writing the same content with no real changes
32
- // (as in initial build and then watch mode) will cause an unnecessary dev server refresh
33
- let oldContent = "";
34
- try {
35
- oldContent = fs.readFileSync(filePath).toString();
36
- } catch (e) {
37
- // file not found
38
- }
39
- const content = JSON.stringify({_: data});
40
- if (content !== oldContent) {
41
- fs.writeFileSync(filePath, content);
42
- }
43
- }
44
- };
45
- };
46
-
47
- module.exports.postcss = true;
@@ -1,36 +0,0 @@
1
- const chokidar = require("chokidar");
2
- const commandLineArgs = require("command-line-args");
3
- const { exec } = require("child_process");
4
-
5
- const options = commandLineArgs([
6
- { name: "srcFiles", type: String },
7
- ]);
8
-
9
- const runPostcss = path => {
10
- let command = `postcss ${path} --config config/postcss.components --base src --dir dist/css/`;
11
- console.log(`Executing: ${command}`);
12
- exec(command, (err, stdout, stderr) => {
13
- if (err) {
14
- console.log(`Could not run postcss for ${path}. Error: ${err}`);
15
- }
16
- });
17
-
18
- command = `${command} -w`;
19
- console.log(`Executing: ${command}`);
20
- exec(command, (err, stdout, stderr) => {
21
- if (err) {
22
- console.log(`Could not run postcss in watch mode for ${path}. Error: ${err}`);
23
- }
24
- });
25
- };
26
-
27
- let ready = false; // Do nothing until the ready event has been fired (we don't want to recompile all files initially)
28
- const watcher = chokidar.watch(options.srcFiles);
29
- watcher.on("ready", () => {
30
- ready = true; // Initial scan is over -> waiting for new files
31
- });
32
- watcher.on("add", path => {
33
- if (ready) {
34
- runPostcss(path);
35
- }
36
- });
@@ -1,14 +0,0 @@
1
- import 'zx/globals';
2
-
3
- // don't print executed commands and their output
4
- $.verbose = false;
5
-
6
- const inputFiles = await globby("src/**/parameters-bundle.css");
7
-
8
- const restArgs = process.argv.slice(2);
9
-
10
- // run all postcss processes in parallel as passing the glob directly to postcss makes them processed sequentially.
11
- // and the amount of imports give a big speed up when run in parallel
12
- await Promise.all(inputFiles.map(file => {
13
- return $`postcss ${file} --config config/postcss.themes --base src --dir dist/css/ ${restArgs}`;
14
- }));
@@ -1,25 +0,0 @@
1
- const fs = require("fs").promises;
2
-
3
- const basePath = process.argv[2];
4
-
5
- const replaceGlobalCoreUsage = async (srcPath) => {
6
-
7
- const original = (await fs.readFile(srcPath)).toString();
8
- let replaced = original.replace(/sap\.ui\.getCore\(\)/g, `Core`);
9
-
10
- if (original !== replaced) {
11
- replaced = `import Core from 'sap/ui/core/Core';
12
- ${replaced}`;
13
- return fs.writeFile(srcPath, replaced);
14
- }
15
- };
16
-
17
- const generate = async () => {
18
- const { globby } = await import("globby");
19
- const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
20
- return Promise.all(fileNames.map(replaceGlobalCoreUsage).filter(x => !!x));
21
- };
22
-
23
- generate().then(() => {
24
- console.log("Success: Replaced global core usage in:", basePath);
25
- });