@ui5/webcomponents-tools 0.0.0-f651a470c → 0.0.0-f79db712b

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 (46) hide show
  1. package/CHANGELOG.md +405 -0
  2. package/README.md +2 -1
  3. package/assets-meta.js +16 -7
  4. package/components-package/eslint.js +2 -0
  5. package/components-package/nps.js +37 -30
  6. package/components-package/postcss.components.js +1 -21
  7. package/components-package/postcss.themes.js +1 -26
  8. package/components-package/wdio.js +15 -3
  9. package/components-package/wdio.sync.js +9 -1
  10. package/icons-collection/nps.js +8 -6
  11. package/lib/cem/custom-elements-manifest.config.mjs +499 -0
  12. package/lib/cem/event.mjs +135 -0
  13. package/lib/cem/schema-internal.json +1354 -0
  14. package/lib/cem/schema.json +1098 -0
  15. package/lib/cem/types-internal.d.ts +801 -0
  16. package/lib/cem/types.d.ts +736 -0
  17. package/lib/cem/utils.mjs +354 -0
  18. package/lib/cem/validate.js +67 -0
  19. package/lib/create-illustrations/index.js +32 -28
  20. package/lib/create-new-component/index.js +28 -58
  21. package/lib/create-new-component/jsFileContentTemplate.js +0 -4
  22. package/lib/create-new-component/tsFileContentTemplate.js +2 -15
  23. package/lib/css-processors/css-processor-components.mjs +77 -0
  24. package/lib/css-processors/css-processor-themes.mjs +79 -0
  25. package/lib/css-processors/scope-variables.mjs +46 -0
  26. package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
  27. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  28. package/lib/esm-abs-to-rel/index.js +4 -1
  29. package/lib/generate-custom-elements-manifest/index.js +1 -1
  30. package/lib/generate-js-imports/illustrations.js +78 -64
  31. package/lib/generate-json-imports/i18n.js +10 -5
  32. package/lib/generate-json-imports/themes.js +10 -5
  33. package/lib/hbs2lit/src/compiler.js +9 -6
  34. package/lib/hbs2lit/src/litVisitor2.js +42 -17
  35. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  36. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
  37. package/lib/hbs2ui5/index.js +21 -4
  38. package/lib/jsdoc/preprocess.js +1 -1
  39. package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
  40. package/lib/scoping/get-all-tags.js +1 -1
  41. package/lib/scoping/scope-test-pages.js +2 -1
  42. package/lib/test-runner/test-runner.js +2 -2
  43. package/package.json +10 -9
  44. package/lib/postcss-css-to-json/index.js +0 -47
  45. package/lib/postcss-new-files/index.js +0 -36
  46. package/lib/postcss-p/postcss-p.mjs +0 -14
@@ -25,10 +25,7 @@ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
25
25
  * <code>import ${packageName}/dist/${componentName}.js";</code>
26
26
  *
27
27
  * @constructor
28
- * @author SAP SE
29
- * @alias sap.ui.webc.${library}.${componentName}
30
- * @extends sap.ui.webc.base.UI5Element
31
- * @tagname ${tagName}
28
+ * @extends UI5Element
32
29
  * @public
33
30
  */
34
31
  @customElement({
@@ -43,7 +40,6 @@ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
43
40
  * Example custom event.
44
41
  * Please keep in mind that all public events should be documented in the API Reference as shown below.
45
42
  *
46
- * @event sap.ui.webc.${library}.${componentName}#interact
47
43
  * @public
48
44
  */
49
45
  @event("interact", { detail: { /* event payload ( optional ) */ } })
@@ -51,9 +47,7 @@ class ${componentName} extends UI5Element {
51
47
  /**
52
48
  * Defines the value of the component.
53
49
  *
54
- * @type {string}
55
- * @name sap.ui.webc.${library}.${componentName}.prototype.value
56
- * @defaultvalue ""
50
+ * @default ""
57
51
  * @public
58
52
  */
59
53
  @property()
@@ -62,17 +56,10 @@ class ${componentName} extends UI5Element {
62
56
  /**
63
57
  * Defines the text of the component.
64
58
  *
65
- * @type {Node[]}
66
- * @name sap.ui.webc.${library}.${componentName}.prototype.default
67
- * @slot
68
59
  * @public
69
60
  */
70
61
  @slot({ type: Node, "default": true })
71
62
  text!: Array<Node>;
72
-
73
- static async onDefine() {
74
-
75
- }
76
63
  }
77
64
 
78
65
  ${componentName}.define();
@@ -0,0 +1,77 @@
1
+ import { globby } from "globby";
2
+ import * as esbuild from 'esbuild'
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import { writeFile, mkdir } from "fs/promises";
6
+ import chokidar from "chokidar";
7
+ import scopeVariables from "./scope-variables.mjs";
8
+ import { writeFileIfChanged, getFileContent } from "./shared.mjs";
9
+
10
+ const tsMode = process.env.UI5_TS === "true";
11
+ const extension = tsMode ? ".css.ts" : ".css.js";
12
+
13
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
14
+ const inputFilesGlob = "src/themes/*.css";
15
+ const restArgs = process.argv.slice(2);
16
+
17
+ let customPlugin = {
18
+ name: 'ui5-tools',
19
+ setup(build) {
20
+ build.initialOptions.write = false;
21
+
22
+ build.onEnd(result => {
23
+ result.outputFiles.forEach(async f => {
24
+ // scoping
25
+ const newText = scopeVariables(f.text, packageJSON);
26
+ await mkdir(path.dirname(f.path), {recursive: true});
27
+ writeFile(f.path, newText);
28
+
29
+ // JS/TS
30
+ const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
31
+ const jsContent = getFileContent(tsMode, jsPath, packageJSON.name, "\`" + newText + "\`", true);
32
+ writeFileIfChanged(jsPath, jsContent);
33
+ });
34
+ })
35
+ },
36
+ }
37
+
38
+ const getConfig = async () => {
39
+ const config = {
40
+ entryPoints: await globby(inputFilesGlob),
41
+ bundle: true,
42
+ minify: true,
43
+ outdir: 'dist/css',
44
+ outbase: 'src',
45
+ plugins: [
46
+ customPlugin,
47
+ ]
48
+ };
49
+ return config;
50
+ }
51
+
52
+ if (restArgs.includes("-w")) {
53
+ let ready;
54
+ let config = await getConfig();
55
+ let ctx = await esbuild.context(config);
56
+ await ctx.watch()
57
+ console.log('watching...')
58
+
59
+ // when new component css files are added, they do not trigger a build as no one directly imports them
60
+ // restart the watch mode with the new entry points if a css file is added.
61
+ const watcher = chokidar.watch(inputFilesGlob);
62
+ watcher.on("ready", () => {
63
+ ready = true; // Initial scan is over -> waiting for new files
64
+ });
65
+ watcher.on("add", async path => {
66
+ if (ready) {
67
+ // new file
68
+ ctx.dispose();
69
+ config = await getConfig();
70
+ ctx = await esbuild.context(config);
71
+ ctx.watch();
72
+ }
73
+ });
74
+ } else {
75
+ const config = await getConfig();
76
+ const result = await esbuild.build(config);
77
+ }
@@ -0,0 +1,79 @@
1
+ import { globby } from "globby";
2
+ import * as esbuild from 'esbuild'
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import { writeFile, mkdir } from "fs/promises";
6
+ import postcss from "postcss";
7
+ import combineDuplicatedSelectors from "../postcss-combine-duplicated-selectors/index.js"
8
+ import { writeFileIfChanged, stripThemingBaseContent, getFileContent } from "./shared.mjs";
9
+ import scopeVariables from "./scope-variables.mjs";
10
+
11
+ const tsMode = process.env.UI5_TS === "true";
12
+ const extension = tsMode ? ".css.ts" : ".css.js";
13
+
14
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
15
+
16
+ let inputFiles = await globby("src/**/parameters-bundle.css");
17
+ const restArgs = process.argv.slice(2);
18
+
19
+ const removeDuplicateSelectors = async (text) => {
20
+ const result = await postcss(combineDuplicatedSelectors).process(text);
21
+ return result.css;
22
+ }
23
+
24
+ let scopingPlugin = {
25
+ name: 'scoping',
26
+ setup(build) {
27
+ build.initialOptions.write = false;
28
+
29
+ build.onEnd(result => {
30
+ result.outputFiles.forEach(async f => {
31
+ // remove duplicate selectors
32
+ let newText = await removeDuplicateSelectors(f.text);
33
+
34
+ // strip unnecessary theming-base-content
35
+ newText = stripThemingBaseContent(newText);
36
+
37
+ // scoping
38
+ newText = scopeVariables(newText, packageJSON, f.path);
39
+ await mkdir(path.dirname(f.path), {recursive: true});
40
+ writeFile(f.path, newText);
41
+
42
+ // JSON
43
+ const jsonPath = f.path.replace(/dist[\/\\]css/, "dist/generated/assets").replace(".css", ".css.json");
44
+ await mkdir(path.dirname(jsonPath), {recursive: true});
45
+ const data = {
46
+ packageName: packageJSON.name,
47
+ fileName: jsonPath.substr(jsonPath.lastIndexOf("themes")),
48
+ content: newText,
49
+ };
50
+ writeFileIfChanged(jsonPath, JSON.stringify({_: data}));
51
+
52
+ // JS/TS
53
+ const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
54
+ const jsContent = getFileContent(tsMode, jsPath, packageJSON.name, "\`" + newText + "\`");
55
+ writeFileIfChanged(jsPath, jsContent);
56
+ });
57
+ })
58
+ },
59
+ }
60
+
61
+ const config = {
62
+ entryPoints: inputFiles,
63
+ bundle: true,
64
+ minify: true,
65
+ outdir: 'dist/css',
66
+ outbase: 'src',
67
+ plugins: [
68
+ scopingPlugin,
69
+ ],
70
+ external: ["*.ttf", "*.woff", "*.woff2"],
71
+ };
72
+
73
+ if (restArgs.includes("-w")) {
74
+ let ctx = await esbuild.context(config);
75
+ await ctx.watch()
76
+ console.log('watching...')
77
+ } else {
78
+ const result = await esbuild.build(config);
79
+ }
@@ -0,0 +1,46 @@
1
+ import * as path from "path";
2
+
3
+ /**
4
+ * Tries to detect an override for a package
5
+ * @param {*} filePath For example: /my_project/src/themes/overrides/@ui5/webcomponents/my_custom_theme/parameters-bundle.css
6
+ * @returns
7
+ */
8
+ const getOverrideVersion = filePath => {
9
+ if (!filePath) {
10
+ return;
11
+ }
12
+
13
+ if (!filePath.includes(`overrides${path.sep}`)) {
14
+ return; // The "overrides/" directory is the marker
15
+ }
16
+ const override = filePath.split(`overrides${path.sep}`)[1]; // For example, this will be: @ui5/webcomponents/my_custom_theme/parameters-bundle.css
17
+ if (!override) {
18
+ return; // There must be other directories after overrides/, the path can't end with it
19
+ }
20
+ const parts = override.split(path.sep);
21
+ if (parts.length < 3) {
22
+ return; // There must be at least a directory for the theme that is being overridden (my_custom_theme) and the name of the CSS file after the name of the package that is overridden
23
+ }
24
+ const packageName = parts.slice(0, -2).join(path.sep); // After the last 2 parts are removed (my_custom_theme and parameters-bundle.css from the example), the rest is the package
25
+
26
+ let overrideVersion;
27
+ try {
28
+ overrideVersion = require(`${packageName}${path.sep}package.json`).version;
29
+ } catch (e) {
30
+ console.log(`Error requiring package ${packageName}: ${e.message}`);
31
+ }
32
+
33
+ return overrideVersion;
34
+ }
35
+
36
+ const scopeVariables = (cssText, packageJSON, inputFile) => {
37
+ const escapeVersion = version => "v" + version?.replaceAll(/[^0-9A-Za-z\-_]/g, "-");
38
+ const versionStr = escapeVersion(getOverrideVersion(inputFile) || packageJSON.version);
39
+
40
+ const expr = /(--_?ui5)([^\,\:\)\s]+)/g;
41
+
42
+ return cssText.replaceAll(expr, `$1-${versionStr}$2`);
43
+ }
44
+
45
+ export default scopeVariables;
46
+
@@ -1,7 +1,38 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const mkdirp = require('mkdirp');
4
- const assets = require("../../assets-meta.js");
1
+ import { writeFile, readFile, mkdir } from "fs/promises";
2
+ import * as path from "path";
3
+ import assets from "../../assets-meta.js";
4
+
5
+ const readOldContent = async (fileName) => {
6
+ // it seems slower to read the old content, but writing the same content with no real changes
7
+ // (as in initial build and then watch mode) will cause an unnecessary dev server refresh
8
+ let oldContent = "";
9
+ try {
10
+ oldContent = (await readFile(fileName)).toString();
11
+ } catch (e) {
12
+ // file not found
13
+ }
14
+ return oldContent;
15
+ }
16
+
17
+ const writeFileIfChanged = async (fileName, content) => {
18
+ const oldContent = await readOldContent(fileName);
19
+ if (content !== oldContent) {
20
+ if (!oldContent) {
21
+ await mkdir(path.dirname(fileName), {recursive: true});
22
+ }
23
+ return writeFile(fileName, content);
24
+ }
25
+ }
26
+
27
+ // strips the unnecessary theming data coming from @sap-theming/theming-base-content and leaves only the css parameters
28
+ const stripThemingBaseContent = css => {
29
+ css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
30
+ css = css.replace(/\.background-image.*{.*}/, "");
31
+ css = css.replace(/\.sapContrast[ ]*:root[\s\S]*?}/, "");
32
+ css = css.replace(/--sapFontUrl.*\);?/, "");
33
+ return css;
34
+ }
35
+
5
36
 
6
37
  const DEFAULT_THEME = assets.themes.default;
7
38
 
@@ -42,49 +73,4 @@ const getJSContent = (targetFile, packageName, css, includeDefaultTheme) => {
42
73
  return `${defaultTheme}export default {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
43
74
  }
44
75
 
45
-
46
- const proccessCSS = css => {
47
- css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
48
- css = css.replace(/\.background-image.*{.*}/, "");
49
- css = css.replace(/\.sapContrast[ ]*:root[\s\S]*?}/, "");
50
- css = css.replace(/--sapFontUrl.*\);?/, "");
51
- return JSON.stringify(css);
52
- }
53
-
54
- module.exports = function (opts) {
55
- opts = opts || {};
56
-
57
- const packageName = opts.packageName;
58
- const includeDefaultTheme = opts.includeDefaultTheme;
59
- const toReplace = opts.toReplace;
60
-
61
- return {
62
- postcssPlugin: 'postcss-css-to-esm',
63
- Once (root) {
64
- const tsMode = process.env.UI5_TS === "true";
65
-
66
- let css = root.toString();
67
- css = proccessCSS(css);
68
-
69
- const targetFile = root.source.input.from.replace(`/${toReplace}/`, "/src/generated/").replace(`\\${toReplace}\\`, "\\src\\generated\\");
70
- mkdirp.sync(path.dirname(targetFile));
71
-
72
- const filePath = `${targetFile}.${tsMode ? "ts" : "js"}`;
73
-
74
- // it seems slower to read the old content, but writing the same content with no real changes
75
- // (as in initial build and then watch mode) will cause an unnecessary dev server refresh
76
- let oldContent = "";
77
- try {
78
- oldContent = fs.readFileSync(filePath).toString();
79
- } catch (e) {
80
- // file not found
81
- }
82
-
83
- const content = getFileContent(tsMode, targetFile, packageName, css, includeDefaultTheme);
84
- if (content !== oldContent) {
85
- fs.writeFileSync(filePath, content);
86
- }
87
- }
88
- };
89
- };
90
- module.exports.postcss = true;
76
+ export { writeFileIfChanged, stripThemingBaseContent, getFileContent}
@@ -0,0 +1,39 @@
1
+ const fs = require("fs");
2
+
3
+ /**
4
+ * A change is observed on MacOS since 13.5, where the build generates a large amount
5
+ * of JSON file that spotlight search has to index, as they are considered new files.
6
+ *
7
+ * Starting the vitejs dev server reads all of these files and this triggers the indexing.
8
+ * The indexing has a side effect of changing some file metadata (can be checked with `mdls <path_to_file>`).
9
+ * This metadata change is changing the ctime of the file, but not the mtime. This can be checked with `stat -x <path_to_file>
10
+ *
11
+ * Essentially only metadata is changed, not content. This should not cause a page refresh,
12
+ * but chokidar reports this change and vite refreshes the page.
13
+ * The indexing is running with a 10 second interval, so for roughtly 20 minutes vite is refreshing the page every 10 seconds
14
+ *
15
+ * This plugin checks if the file causing the refresh is a generated json file (dist/*.json) and if ctime is changed after mtime
16
+ * In that case, returing an empty array tells vitejs that a custom update will be made by the plugin,
17
+ * which is in effect ignoring the page refresh.
18
+ */
19
+
20
+ const customHotUpdate = async () => {
21
+ return {
22
+ name: 'custom-hot-update',
23
+ handleHotUpdate(ctx) {
24
+ // custom check for generated json files
25
+ if (ctx.file.endsWith(".json")) {
26
+ const stat = fs.statSync(ctx.file);
27
+
28
+ // metadata change only
29
+ if (stat.ctime > stat.mtime) {
30
+ // uncomment for debugging
31
+ // console.log("ignoring hot update for:", ctx.file);
32
+ return [];
33
+ }
34
+ }
35
+ }
36
+ }
37
+ };
38
+
39
+ module.exports = customHotUpdate;
@@ -7,8 +7,11 @@ const basePath = process.argv[2];
7
7
 
8
8
  const convertImports = async (srcPath) => {
9
9
  let changed = false;
10
- // console.log("scanning imports of", srcPath);
11
10
  let code = (await fs.readFile(srcPath)).toString();
11
+ if (code.includes("import(")) {
12
+ // esprima can't parse this, but it's from the project files
13
+ return;
14
+ }
12
15
  const tree = esprima.parseModule(code);
13
16
  const importer = srcPath.replace(basePath, "");
14
17
  const importerDir = path.dirname(importer);
@@ -314,7 +314,7 @@ const generate = async () => {
314
314
  };
315
315
 
316
316
  file.symbols.forEach(entity => {
317
- if (entity.tagname) {
317
+ if (entity.tagname || entity.kind === "class") {
318
318
  customElementsManifest.modules.push(generateJavaScriptModule(entity));
319
319
  }
320
320
  });
@@ -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) {