@ui5/webcomponents-tools 0.0.0-f24ff9019 → 0.0.0-f42e7c18c

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 (62) hide show
  1. package/CHANGELOG.md +955 -0
  2. package/README.md +3 -6
  3. package/assets-meta.js +5 -3
  4. package/components-package/cypress/support/commands.js +39 -0
  5. package/components-package/cypress/support/component-index.html +17 -0
  6. package/components-package/cypress/support/component.d.ts +23 -0
  7. package/components-package/cypress/support/component.js +34 -0
  8. package/components-package/cypress.config.js +19 -0
  9. package/components-package/eslint.js +90 -28
  10. package/components-package/nps.js +53 -45
  11. package/components-package/postcss.components.js +1 -24
  12. package/components-package/postcss.themes.js +1 -30
  13. package/components-package/wdio.js +415 -405
  14. package/icons-collection/nps.js +7 -5
  15. package/lib/amd-to-es6/index.js +102 -0
  16. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  17. package/lib/cem/custom-elements-manifest.config.mjs +527 -0
  18. package/lib/cem/event.mjs +168 -0
  19. package/lib/cem/schema-internal.json +1413 -0
  20. package/lib/cem/schema.json +1098 -0
  21. package/lib/cem/types-internal.d.ts +808 -0
  22. package/lib/cem/types.d.ts +736 -0
  23. package/lib/cem/utils.mjs +408 -0
  24. package/lib/cem/validate.js +70 -0
  25. package/lib/create-icons/index.js +8 -6
  26. package/lib/create-illustrations/index.js +40 -33
  27. package/lib/create-new-component/index.js +4 -13
  28. package/lib/create-new-component/tsFileContentTemplate.js +4 -13
  29. package/lib/css-processors/css-processor-components.mjs +77 -0
  30. package/lib/css-processors/css-processor-themes.mjs +79 -0
  31. package/lib/css-processors/scope-variables.mjs +49 -0
  32. package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
  33. package/lib/dev-server/custom-hot-update-plugin.js +4 -4
  34. package/lib/dev-server/{dev-server.js → dev-server.mjs} +4 -4
  35. package/lib/generate-js-imports/illustrations.js +17 -14
  36. package/lib/generate-json-imports/i18n.js +45 -61
  37. package/lib/generate-json-imports/themes.js +16 -33
  38. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +12 -7
  39. package/lib/hbs2ui5/index.js +3 -3
  40. package/lib/i18n/defaults.js +3 -2
  41. package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
  42. package/lib/remove-dev-mode/remove-dev-mode.mjs +37 -0
  43. package/lib/scoping/get-all-tags.js +10 -3
  44. package/lib/scoping/lint-src.js +8 -7
  45. package/lib/scoping/scope-test-pages.js +2 -1
  46. package/package.json +19 -11
  47. package/tsconfig.json +16 -0
  48. package/types/index.d.ts +1 -0
  49. package/components-package/wdio.sync.js +0 -368
  50. package/lib/create-new-component/jsFileContentTemplate.js +0 -73
  51. package/lib/esm-abs-to-rel/index.js +0 -58
  52. package/lib/generate-custom-elements-manifest/index.js +0 -327
  53. package/lib/jsdoc/config.json +0 -29
  54. package/lib/jsdoc/configTypescript.json +0 -29
  55. package/lib/jsdoc/plugin.js +0 -2468
  56. package/lib/jsdoc/preprocess.js +0 -146
  57. package/lib/jsdoc/template/publish.js +0 -4120
  58. package/lib/postcss-css-to-json/index.js +0 -47
  59. package/lib/postcss-new-files/index.js +0 -36
  60. package/lib/postcss-p/postcss-p.mjs +0 -14
  61. package/lib/postcss-scope-vars/index.js +0 -24
  62. package/lib/replace-global-core/index.js +0 -25
@@ -1,7 +1,5 @@
1
1
  const fs = require("fs");
2
- const path = require("path");
3
2
  const prompts = require("prompts");
4
- const jsFileContentTemplate = require("./jsFileContentTemplate.js");
5
3
  const tsFileContentTemplate = require("./tsFileContentTemplate.js");
6
4
 
7
5
  /**
@@ -58,21 +56,15 @@ const getLibraryName = packageName => {
58
56
  return packageName.substr("webcomponents-".length);
59
57
  };
60
58
 
61
- const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
59
+ const generateFiles = (componentName, tagName, library, packageName) => {
62
60
  componentName = capitalizeFirstLetter(componentName);
63
61
  const filePaths = {
64
- "main": isTypeScript
65
- ? `./src/${componentName}.ts`
66
- : `./src/${componentName}.js`,
62
+ "main": `./src/${componentName}.ts`,
67
63
  "css": `./src/themes/${componentName}.css`,
68
64
  "template": `./src/${componentName}.hbs`,
69
65
  };
70
66
 
71
- const FileContentTemplate = isTypeScript
72
- ? tsFileContentTemplate(componentName, tagName, library, packageName)
73
- : jsFileContentTemplate(componentName, tagName, library, packageName);
74
-
75
- fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
67
+ fs.writeFileSync(filePaths.main, tsFileContentTemplate(componentName, tagName, library, packageName), { flag: "wx+" });
76
68
  fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
77
69
  fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
78
70
 
@@ -112,10 +104,9 @@ const createWebComponent = async () => {
112
104
  }
113
105
  }
114
106
 
115
- const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
116
107
  const tagName = hyphaneteComponentName(componentName);
117
108
 
118
- generateFiles(componentName, tagName, library, packageName, isTypeScript);
109
+ generateFiles(componentName, tagName, library, packageName);
119
110
  };
120
111
 
121
112
  createWebComponent();
@@ -22,13 +22,10 @@ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
22
22
  * For the <code>${tagName}</code>
23
23
  * <h3>ES6 Module Import</h3>
24
24
  *
25
- * <code>import ${packageName}/dist/${componentName}.js";</code>
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,20 +47,15 @@ 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()
60
- value!: string;
54
+ value?: string;
61
55
 
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 })
@@ -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,49 @@
1
+ import * as path from "path";
2
+ import { createRequire } from 'node:module';
3
+
4
+ const require = createRequire(import.meta.url);
5
+
6
+ /**
7
+ * Tries to detect an override for a package
8
+ * @param {*} filePath For example: /my_project/src/themes/overrides/@ui5/webcomponents/my_custom_theme/parameters-bundle.css
9
+ * @returns
10
+ */
11
+ const getOverrideVersion = filePath => {
12
+ if (!filePath) {
13
+ return;
14
+ }
15
+
16
+ if (!filePath.includes(`overrides${path.sep}`)) {
17
+ return; // The "overrides/" directory is the marker
18
+ }
19
+ const override = filePath.split(`overrides${path.sep}`)[1]; // For example, this will be: @ui5/webcomponents/my_custom_theme/parameters-bundle.css
20
+ if (!override) {
21
+ return; // There must be other directories after overrides/, the path can't end with it
22
+ }
23
+ const parts = override.split(path.sep);
24
+ if (parts.length < 3) {
25
+ 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
26
+ }
27
+ 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
28
+
29
+ let overrideVersion;
30
+ try {
31
+ overrideVersion = require(`${packageName}${path.sep}package.json`).version;
32
+ } catch (e) {
33
+ console.log(`Error requiring package ${packageName}: ${e.message}`);
34
+ }
35
+
36
+ return overrideVersion;
37
+ }
38
+
39
+ const scopeVariables = (cssText, packageJSON, inputFile) => {
40
+ const escapeVersion = version => "v" + version?.replaceAll(/[^0-9A-Za-z\-_]/g, "-");
41
+ const versionStr = escapeVersion(getOverrideVersion(inputFile) || packageJSON.version);
42
+
43
+ const expr = /(--_?ui5)([^\,\:\)\s]+)/g;
44
+
45
+ return cssText.replaceAll(expr, `$1-${versionStr}$2`);
46
+ }
47
+
48
+ export default scopeVariables;
49
+
@@ -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
- OnceExit(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}
@@ -3,15 +3,15 @@ const fs = require("fs");
3
3
  /**
4
4
  * A change is observed on MacOS since 13.5, where the build generates a large amount
5
5
  * of JSON file that spotlight search has to index, as they are considered new files.
6
- *
6
+ *
7
7
  * Starting the vitejs dev server reads all of these files and this triggers the indexing.
8
8
  * The indexing has a side effect of changing some file metadata (can be checked with `mdls <path_to_file>`).
9
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
- *
10
+ *
11
11
  * Essentially only metadata is changed, not content. This should not cause a page refresh,
12
12
  * but chokidar reports this change and vite refreshes the page.
13
13
  * The indexing is running with a 10 second interval, so for roughtly 20 minutes vite is refreshing the page every 10 seconds
14
- *
14
+ *
15
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
16
  * In that case, returing an empty array tells vitejs that a custom update will be made by the plugin,
17
17
  * which is in effect ignoring the page refresh.
@@ -22,7 +22,7 @@ const customHotUpdate = async () => {
22
22
  name: 'custom-hot-update',
23
23
  handleHotUpdate(ctx) {
24
24
  // custom check for generated json files
25
- if (ctx.file.includes("dist/") && ctx.file.endsWith(".json")) {
25
+ if (ctx.file.endsWith(".json")) {
26
26
  const stat = fs.statSync(ctx.file);
27
27
 
28
28
  // metadata change only
@@ -1,7 +1,7 @@
1
- const fs = require("fs/promises");
2
- const { createServer } = require('vite');
3
- const yargs = require('yargs/yargs')
4
- const { hideBin } = require('yargs/helpers')
1
+ import fs from "fs/promises";
2
+ import { createServer } from 'vite';
3
+ import yargs from 'yargs';
4
+ import { hideBin } from 'yargs/helpers';
5
5
 
6
6
  const argv = yargs(hideBin(process.argv))
7
7
  .alias("c", "config")
@@ -1,12 +1,14 @@
1
1
  const fs = require("fs").promises;
2
2
  const path = require("path");
3
3
 
4
- const generateDynamicImportLines = (fileNames, location, exclusionPatterns = []) => {
4
+ const generateDynamicImportLines = async (fileNames, location, exclusionPatterns = []) => {
5
+ const packageName = JSON.parse(await fs.readFile("package.json")).name;
5
6
  return fileNames
6
7
  .filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
7
8
  .map((fileName) => {
8
- const illustrationPath = `${location}/${fileName.replace(".js", "")}`;
9
- return `\t\tcase "${fileName.replace('.js', '')}": return (await import("${illustrationPath}.js")).default;`;
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;`;
10
12
  })
11
13
  .join("\n");
12
14
  };
@@ -19,11 +21,12 @@ const generateAvailableIllustrationsArray = (fileNames, exclusionPatterns = [])
19
21
  );
20
22
  };
21
23
 
22
- const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, prefix = "") => {
23
- return `import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
24
+ const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, set, prefix = "") => {
25
+ return `// @ts-nocheck
26
+ import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
24
27
 
25
28
  export const loadIllustration = async (illustrationName) => {
26
- const collectionAndPrefix = "${collection}/${prefix}";
29
+ const collectionAndPrefix = "${set}/${collection}/${prefix}";
27
30
  const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
28
31
  switch (cleanIllustrationName) {
29
32
  ${dynamicImports}
@@ -38,7 +41,7 @@ const loadAndCheck = async (illustrationName) => {
38
41
  };
39
42
 
40
43
  ${availableIllustrations}.forEach((illustrationName) =>
41
- registerIllustrationLoader(\`${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
44
+ registerIllustrationLoader(\`${set}/${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
42
45
  );
43
46
  `;
44
47
  };
@@ -49,17 +52,17 @@ const getMatchingFiles = async (folder, pattern) => {
49
52
  };
50
53
 
51
54
  const generateIllustrations = async (config) => {
52
- const { inputFolder, outputFile, collection, location, prefix, filterOut } = config;
55
+ const { inputFolder, outputFile, collection, location, prefix, filterOut, set } = config;
53
56
 
54
57
  const normalizedInputFolder = path.normalize(inputFolder);
55
58
  const normalizedOutputFile = path.normalize(outputFile);
56
59
 
57
60
  const illustrations = await getMatchingFiles(normalizedInputFolder, /^.*\.js$/);
58
61
 
59
- const dynamicImports = generateDynamicImportLines(illustrations, location, filterOut);
62
+ const dynamicImports = await generateDynamicImportLines(illustrations, location, filterOut);
60
63
  const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
61
64
 
62
- const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, prefix);
65
+ const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, set, prefix);
63
66
 
64
67
  await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
65
68
  await fs.writeFile(normalizedOutputFile, contentDynamic);
@@ -71,10 +74,10 @@ const generateIllustrations = async (config) => {
71
74
  const config = {
72
75
  inputFolder: process.argv[2],
73
76
  outputFile: process.argv[3],
74
- collection: process.argv[4],
75
- location: process.argv[5],
76
- prefix: process.argv[6],
77
- filterOut: process.argv.slice(7),
77
+ set: process.argv[4],
78
+ collection: process.argv[5],
79
+ location: process.argv[6],
80
+ filterOut: process.argv.slice[7],
78
81
  };
79
82
 
80
83
  // Run the generation process
@@ -1,95 +1,79 @@
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
+
7
+
8
+ const getContent = function(caseLines, languagesKeysStringArray, packageName) {
9
+ return `// @ts-nocheck
10
+ import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
11
+
12
+ const importMessageBundle = async (localeId) => {
13
+ switch (localeId) {
14
+ ${caseLines}
15
+ default: throw "unknown locale"
16
+ }
17
+ }
18
+
19
+ const importAndCheck = async (localeId) => {
20
+ const data = await importMessageBundle(localeId);
21
+ if (typeof data === "string" && data.endsWith(".json")) {
22
+ throw new Error(\`[i18n] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build. Check the \"Assets\" documentation for more information.\`);
23
+ }
24
+ return data;
25
+ }
26
+
27
+ const localeIds = [${languagesKeysStringArray}];
28
+
29
+ localeIds.forEach(localeId => {
30
+ registerI18nLoader("${packageName}", localeId, importAndCheck);
31
+ });
32
+ `;
33
+ }
34
+
4
35
  const generate = async () => {
5
36
 
6
37
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
7
38
 
8
39
  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`);
40
+ const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.${ext}`);
41
+ const outputFileFetchMetaResolve = path.normalize(`${process.argv[3]}/i18n-fetch.${ext}`);
11
42
 
12
- // All languages present in the file system
43
+ // All languages present in the file system
13
44
  const files = await fs.readdir(inputFolder);
14
45
  const languages = files.map(file => {
15
46
  const matches = file.match(/messagebundle_(.+?).json$/);
16
47
  return matches ? matches[1] : undefined;
17
48
  }).filter(key => !!key);
18
49
 
19
- let contentStatic, contentDynamic;
50
+ let contentDynamic;
51
+ let contentFetchMetaResolve;
20
52
 
21
- // No i18n - just import dependencies, if any
53
+ // No i18n - just import dependencies, if any
22
54
  if (languages.length === 0) {
23
- contentStatic = "";
24
55
  contentDynamic = "";
25
- // There is i18n - generate the full file
56
+ contentFetchMetaResolve = "";
57
+ // There is i18n - generate the full file
26
58
  } else {
27
59
  // Keys for the array
28
- const languagesKeysString = languages.map(key => `"${key}": _${key},`).join("\n\t");
29
60
  const languagesKeysStringArray = languages.map(key => `"${key}",`).join("\n\t");
30
61
 
31
62
  // Actual imports for json assets
32
- const assetsImportsString = languages.map(key => `import _${key} from "../assets/i18n/messagebundle_${key}.json";`).join("\n");
33
-
34
- // static imports
35
- contentStatic = `import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
36
-
37
- ${assetsImportsString}
38
-
39
- const bundleMap = {
40
- ${languagesKeysString}
41
- };
42
-
43
- const fetchMessageBundle = async (localeId) => {
44
- if (typeof bundleMap[localeId] === "object") {
45
- // inlined from build
46
- throw new Error("[i18n] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs")
47
- }
48
- return (await fetch(bundleMap[localeId])).json()
49
- }
50
-
51
- const localeIds = [${languagesKeysStringArray}];
52
-
53
- localeIds.forEach(localeId => {
54
- registerI18nLoader("${packageName}", localeId, fetchMessageBundle);
55
- });
56
- `;
57
-
58
- // 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");
64
+ const fetchMetaResolveString = languages.map(key => ` case "${key}": return (await fetch(new URL("../assets/i18n/messagebundle_${key}.json", import.meta.url))).json();`).join("\n");
60
65
 
61
66
  // Resulting file content
62
- contentDynamic = `import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
63
-
64
- const importMessageBundle = async (localeId) => {
65
- switch (localeId) {
66
- ${dynamicImportsString}
67
- default: throw "unknown locale"
68
- }
69
- }
70
-
71
- const importAndCheck = async (localeId) => {
72
- const data = await importMessageBundle(localeId);
73
- if (typeof data === "string" && data.endsWith(".json")) {
74
- throw new Error(\`[i18n] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build or use 'import ".../Assets-static.js"'. Check the \"Assets\" documentation for more information.\`);
75
- }
76
- return data;
77
- }
78
-
79
- const localeIds = [${languagesKeysStringArray}];
80
-
81
- localeIds.forEach(localeId => {
82
- registerI18nLoader("${packageName}", localeId, importAndCheck);
83
- });
84
- `;
85
67
 
68
+ contentDynamic = getContent(dynamicImportsString, languagesKeysStringArray, packageName);
69
+ contentFetchMetaResolve = getContent(fetchMetaResolveString, languagesKeysStringArray, packageName);
86
70
 
87
71
  }
88
72
 
89
- await fs.mkdir(path.dirname(outputFile), { recursive: true });
73
+ await fs.mkdir(path.dirname(outputFileDynamic), { recursive: true });
90
74
  return Promise.all([
91
- fs.writeFile(outputFile, contentStatic),
92
75
  fs.writeFile(outputFileDynamic, contentDynamic),
76
+ fs.writeFile(outputFileFetchMetaResolve, contentFetchMetaResolve),
93
77
  ]);
94
78
  }
95
79