@ui5/webcomponents-tools 0.0.0-38861c872 → 0.0.0-38f83ffef

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 (48) hide show
  1. package/CHANGELOG.md +1121 -0
  2. package/README.md +2 -5
  3. package/assets-meta.js +3 -11
  4. package/components-package/eslint.js +59 -31
  5. package/components-package/nps.js +48 -26
  6. package/components-package/vite.config.js +7 -11
  7. package/components-package/wdio.js +415 -405
  8. package/icons-collection/nps.js +2 -2
  9. package/lib/amd-to-es6/index.js +102 -0
  10. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  11. package/lib/cem/custom-elements-manifest.config.mjs +129 -55
  12. package/lib/cem/event.mjs +75 -21
  13. package/lib/cem/schema-internal.json +71 -0
  14. package/lib/cem/types-internal.d.ts +564 -785
  15. package/lib/cem/types.d.ts +520 -655
  16. package/lib/cem/utils.mjs +115 -47
  17. package/lib/cem/validate.js +41 -37
  18. package/lib/create-icons/index.js +13 -10
  19. package/lib/create-illustrations/index.js +44 -9
  20. package/lib/create-new-component/{tsFileContentTemplate.js → Component.js} +13 -10
  21. package/lib/create-new-component/ComponentTemplate.js +12 -0
  22. package/lib/create-new-component/index.js +14 -22
  23. package/lib/css-processors/css-processor-components.mjs +3 -2
  24. package/lib/css-processors/css-processor-themes.mjs +2 -7
  25. package/lib/css-processors/scope-variables.mjs +3 -0
  26. package/lib/css-processors/shared.mjs +2 -22
  27. package/lib/dev-server/{dev-server.js → dev-server.mjs} +4 -4
  28. package/lib/dev-server/virtual-index-html-plugin.js +24 -20
  29. package/lib/generate-json-imports/i18n.js +46 -62
  30. package/lib/generate-json-imports/themes.js +13 -32
  31. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +12 -7
  32. package/lib/hbs2ui5/index.js +3 -3
  33. package/lib/i18n/defaults.js +3 -2
  34. package/lib/remove-dev-mode/remove-dev-mode.mjs +37 -0
  35. package/lib/scoping/get-all-tags.js +9 -2
  36. package/lib/scoping/lint-src.js +8 -7
  37. package/package.json +11 -8
  38. package/tsconfig.json +18 -0
  39. package/components-package/wdio.sync.js +0 -368
  40. package/lib/create-new-component/jsFileContentTemplate.js +0 -73
  41. package/lib/esm-abs-to-rel/index.js +0 -61
  42. package/lib/generate-custom-elements-manifest/index.js +0 -327
  43. package/lib/jsdoc/config.json +0 -29
  44. package/lib/jsdoc/configTypescript.json +0 -29
  45. package/lib/jsdoc/plugin.js +0 -2468
  46. package/lib/jsdoc/preprocess.js +0 -146
  47. package/lib/jsdoc/template/publish.js +0 -4120
  48. package/lib/replace-global-core/index.js +0 -25
@@ -1,12 +1,12 @@
1
- const tsFileContentTemplate = (componentName, tagName, library, packageName) => {
1
+ const Component = (componentName, tagName, library, packageName) => {
2
2
  return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
3
3
  import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
4
4
  import property from "@ui5/webcomponents-base/dist/decorators/property.js";
5
5
  import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
6
- import event from "@ui5/webcomponents-base/dist/decorators/event.js";
7
- import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
6
+ import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
7
+ import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
8
8
 
9
- import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
9
+ import ${componentName}Template from "./${componentName}Template.js";
10
10
 
11
11
  // Styles
12
12
  import ${componentName}Css from "./generated/themes/${componentName}.css.js";
@@ -22,7 +22,7 @@ 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
28
  * @extends UI5Element
@@ -30,10 +30,9 @@ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
30
30
  */
31
31
  @customElement({
32
32
  tag: "${tagName}",
33
- renderer: litRender,
33
+ renderer: jsxRenderer,
34
34
  styles: ${componentName}Css,
35
35
  template: ${componentName}Template,
36
- dependencies: [],
37
36
  })
38
37
 
39
38
  /**
@@ -42,8 +41,12 @@ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
42
41
  *
43
42
  * @public
44
43
  */
45
- @event("interact", { detail: { /* event payload ( optional ) */ } })
44
+ @event("interact")
46
45
  class ${componentName} extends UI5Element {
46
+ eventDetails!: {
47
+ "interact": void,
48
+ };
49
+
47
50
  /**
48
51
  * Defines the value of the component.
49
52
  *
@@ -51,7 +54,7 @@ class ${componentName} extends UI5Element {
51
54
  * @public
52
55
  */
53
56
  @property()
54
- value!: string;
57
+ value?: string;
55
58
 
56
59
  /**
57
60
  * Defines the text of the component.
@@ -68,4 +71,4 @@ export default ${componentName};
68
71
  `;
69
72
  };
70
73
 
71
- module.exports = tsFileContentTemplate;
74
+ module.exports = Component;
@@ -0,0 +1,12 @@
1
+ const ComponentTemplate = (componentName) => {
2
+ return `import type ${componentName} from "./${componentName}.js";
3
+
4
+ export default function ${componentName}Template(this: ${componentName}) {
5
+ return (
6
+ <div>Hello World!</div>
7
+ );
8
+ }
9
+ `;
10
+ };
11
+
12
+ module.exports = ComponentTemplate;
@@ -1,18 +1,17 @@
1
1
  const fs = require("fs");
2
- const path = require("path");
3
2
  const prompts = require("prompts");
4
- const jsFileContentTemplate = require("./jsFileContentTemplate.js");
5
- const tsFileContentTemplate = require("./tsFileContentTemplate.js");
3
+ const Component = require("./Component.js");
4
+ const ComponentTemplate= require("./ComponentTemplate.js");
6
5
 
7
6
  /**
8
- * Hyphanates the given PascalCase string, f.e.:
9
- * Foo -> "my-foo" (adds preffix)
10
- * FooBar -> "foo-bar"
7
+ * Hyphanates the given PascalCase string and adds prefix, f.e.:
8
+ * Foo -> "my-foo"
9
+ * FooBar -> "my-foo-bar"
11
10
  */
12
11
  const hyphaneteComponentName = (componentName) => {
13
12
  const result = componentName.replace(/([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
14
13
 
15
- return result.includes("-") ? result : `my-${result}`;
14
+ return `my-${result}`;
16
15
  };
17
16
 
18
17
  /**
@@ -58,23 +57,17 @@ const getLibraryName = packageName => {
58
57
  return packageName.substr("webcomponents-".length);
59
58
  };
60
59
 
61
- const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
60
+ const generateFiles = (componentName, tagName, library, packageName) => {
62
61
  componentName = capitalizeFirstLetter(componentName);
63
62
  const filePaths = {
64
- "main": isTypeScript
65
- ? `./src/${componentName}.ts`
66
- : `./src/${componentName}.js`,
63
+ "main": `./src/${componentName}.ts`,
67
64
  "css": `./src/themes/${componentName}.css`,
68
- "template": `./src/${componentName}.hbs`,
65
+ "template": `./src/${componentName}Template.tsx`,
69
66
  };
70
67
 
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+" });
68
+ fs.writeFileSync(filePaths.main, Component(componentName, tagName, library, packageName), { flag: "wx+" });
76
69
  fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
77
- fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
70
+ fs.writeFileSync(filePaths.template, ComponentTemplate(componentName), { flag: "wx+" });
78
71
 
79
72
  console.log(`Successfully generated ${filePaths.main}`);
80
73
  console.log(`Successfully generated ${filePaths.css}`);
@@ -82,8 +75,8 @@ const generateFiles = (componentName, tagName, library, packageName, isTypeScrip
82
75
 
83
76
  // Change the color of the output
84
77
  console.warn('\x1b[33m%s\x1b[0m', `
85
- Make sure to import the component in your bundle by using:
86
- import "./dist/${componentName}.js";`);
78
+ Now, import the component in src/bundle.esm.ts via: "import ${componentName} from ./${componentName}.js";
79
+ And, add it to your HTML: <${tagName}></${tagName}>.`);
87
80
  }
88
81
 
89
82
  // Main function
@@ -112,10 +105,9 @@ const createWebComponent = async () => {
112
105
  }
113
106
  }
114
107
 
115
- const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
116
108
  const tagName = hyphaneteComponentName(componentName);
117
109
 
118
- generateFiles(componentName, tagName, library, packageName, isTypeScript);
110
+ generateFiles(componentName, tagName, library, packageName);
119
111
  };
120
112
 
121
113
  createWebComponent();
@@ -22,13 +22,14 @@ let customPlugin = {
22
22
  build.onEnd(result => {
23
23
  result.outputFiles.forEach(async f => {
24
24
  // scoping
25
- const newText = scopeVariables(f.text, packageJSON);
25
+ let newText = scopeVariables(f.text, packageJSON);
26
+ newText = newText.replaceAll(/\\/g, "\\\\"); // Escape backslashes as they might appear in css rules
26
27
  await mkdir(path.dirname(f.path), {recursive: true});
27
28
  writeFile(f.path, newText);
28
29
 
29
30
  // JS/TS
30
31
  const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
31
- const jsContent = getFileContent(tsMode, jsPath, packageJSON.name, "\`" + newText + "\`", true);
32
+ const jsContent = getFileContent(packageJSON.name, "\`" + newText + "\`", true);
32
33
  writeFileIfChanged(jsPath, jsContent);
33
34
  });
34
35
  })
@@ -42,16 +42,11 @@ let scopingPlugin = {
42
42
  // JSON
43
43
  const jsonPath = f.path.replace(/dist[\/\\]css/, "dist/generated/assets").replace(".css", ".css.json");
44
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}));
45
+ writeFileIfChanged(jsonPath, JSON.stringify(newText));
51
46
 
52
47
  // JS/TS
53
48
  const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
54
- const jsContent = getFileContent(tsMode, jsPath, packageJSON.name, "\`" + newText + "\`");
49
+ const jsContent = getFileContent(packageJSON.name, "\`" + newText + "\`");
55
50
  writeFileIfChanged(jsPath, jsContent);
56
51
  });
57
52
  })
@@ -1,4 +1,7 @@
1
1
  import * as path from "path";
2
+ import { createRequire } from 'node:module';
3
+
4
+ const require = createRequire(import.meta.url);
2
5
 
3
6
  /**
4
7
  * Tries to detect an override for a package
@@ -47,30 +47,10 @@ registerThemePropertiesLoader("${packageName}", "${DEFAULT_THEME}", async () =>
47
47
  `;
48
48
  };
49
49
 
50
- const getFileContent = (tsMode, targetFile, packageName, css, includeDefaultTheme) => {
51
- if (tsMode) {
52
- return getTSContent(targetFile, packageName, css, includeDefaultTheme);
53
- }
54
-
55
- return getJSContent(targetFile, packageName, css, includeDefaultTheme);
56
- }
57
-
58
- const getTSContent = (targetFile, packageName, css, includeDefaultTheme) => {
59
- const typeImport = "import type { StyleData } from \"@ui5/webcomponents-base/dist/types.js\";"
50
+ const getFileContent = (packageName, css, includeDefaultTheme) => {
60
51
  const defaultTheme = includeDefaultTheme ? getDefaultThemeCode(packageName) : "";
61
-
62
- // tabs are intentionally mixed to have proper identation in the produced file
63
- return `${typeImport}
64
- ${defaultTheme}
65
- const styleData: StyleData = {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}};
66
- export default styleData;
67
- `;
52
+ return `${defaultTheme}export default ${css.trim()}`
68
53
  }
69
54
 
70
- const getJSContent = (targetFile, packageName, css, includeDefaultTheme) => {
71
- const defaultTheme = includeDefaultTheme ? getDefaultThemeCode(packageName) : "";
72
-
73
- return `${defaultTheme}export default {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
74
- }
75
55
 
76
56
  export { writeFileIfChanged, stripThemingBaseContent, getFileContent}
@@ -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,23 +1,17 @@
1
- const virtualIndexPlugin = async () => {
2
- const path = await import("path");
3
- const { globby } = await import("globby");
4
- const files = await globby(["test/pages/**/*.html", "packages/*/test/pages/**/*.html"]);
5
-
6
- const pagesPerFolder = {};
7
- files.forEach(file => {
8
- let folder = pagesPerFolder[path.dirname(file)] = pagesPerFolder[path.dirname(file)] || [];
9
- folder.push(path.basename(file));
10
- });
1
+ const virtualIndexPlugin = () => {
2
+ return {
3
+ name: 'virtual-index-html',
4
+ async config() {
5
+ const path = (await import("path")).default;
6
+ const globby = (await import("globby")).globby;
7
+ const files = await globby(["test/pages/**/*.html", "packages/*/test/pages/**/*.html"]);
11
8
 
12
- const rollupInput = {};
9
+ const rollupInput = {};
13
10
 
14
- files.forEach(file => {
15
- rollupInput[file] = path.resolve(process.cwd(), file);
16
- })
11
+ files.forEach(file => {
12
+ rollupInput[file] = path.resolve(process.cwd(), file);
13
+ });
17
14
 
18
- return {
19
- name: 'virtual-index-html',
20
- config() {
21
15
  return {
22
16
  build: {
23
17
  rollupOptions: {
@@ -26,7 +20,17 @@ const virtualIndexPlugin = async () => {
26
20
  }
27
21
  }
28
22
  },
29
- configureServer(server) {
23
+ async configureServer(server) {
24
+ const path = (await import("path")).default;
25
+ const globby = (await import("globby")).globby;
26
+ const files = await globby(["test/pages/**/*.html", "packages/*/test/pages/**/*.html"]);
27
+
28
+ const pagesPerFolder = {};
29
+ files.forEach(file => {
30
+ let folder = pagesPerFolder[path.dirname(file)] = pagesPerFolder[path.dirname(file)] || [];
31
+ folder.push(path.basename(file));
32
+ });
33
+
30
34
  server.middlewares.use((req, res, next) => {
31
35
  if (req.url === "/") {
32
36
  const folders = Object.keys(pagesPerFolder);
@@ -37,8 +41,8 @@ const virtualIndexPlugin = async () => {
37
41
  const pages = pagesPerFolder[folder];
38
42
  return `<h1>${folder}</h1>
39
43
  ${pages.map(page => {
40
- return `<li><a href='${folder}/${page}'>${page}</a></li>`
41
- }).join("")}
44
+ return `<li><a href='${folder}/${page}'>${page}</a></li>`
45
+ }).join("")}
42
46
  `
43
47
  }).join("")}`);
44
48
  } else {
@@ -4,97 +4,81 @@ const path = require('path');
4
4
  const isTypeScript = process.env.UI5_TS;
5
5
  const ext = isTypeScript ? 'ts' : 'js';
6
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
+
7
35
  const generate = async () => {
8
36
 
9
37
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
10
38
 
11
39
  const inputFolder = path.normalize(process.argv[2]);
12
- const outputFile = path.normalize(`${process.argv[3]}/i18n-static.${ext}`);
13
40
  const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.${ext}`);
41
+ const outputFileFetchMetaResolve = path.normalize(`${process.argv[3]}/i18n-fetch.${ext}`);
42
+ const outputFileDynamicImportJSONImport = path.normalize(`${process.argv[3]}/i18n-node.${ext}`);
14
43
 
15
- // All languages present in the file system
44
+ // All languages present in the file system
16
45
  const files = await fs.readdir(inputFolder);
17
46
  const languages = files.map(file => {
18
47
  const matches = file.match(/messagebundle_(.+?).json$/);
19
48
  return matches ? matches[1] : undefined;
20
49
  }).filter(key => !!key);
21
50
 
22
- let contentStatic, contentDynamic;
51
+ let contentDynamic;
52
+ let contentFetchMetaResolve;
53
+ let contentDynamicImportJSONAttr;
23
54
 
24
- // No i18n - just import dependencies, if any
55
+ // No i18n - just import dependencies, if any
25
56
  if (languages.length === 0) {
26
- contentStatic = "";
27
57
  contentDynamic = "";
28
- // There is i18n - generate the full file
58
+ contentFetchMetaResolve = "";
59
+ contentDynamicImportJSONAttr = "";
60
+ // There is i18n - generate the full file
29
61
  } else {
30
62
  // Keys for the array
31
- const languagesKeysString = languages.map(key => `"${key}": _${key},`).join("\n\t");
32
63
  const languagesKeysStringArray = languages.map(key => `"${key}",`).join("\n\t");
33
64
 
34
- // Actual imports for json assets
35
- const assetsImportsString = languages.map(key => `import _${key} from "../assets/i18n/messagebundle_${key}.json";`).join("\n");
36
-
37
- // static imports
38
- contentStatic = `// @ts-nocheck
39
- import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
40
-
41
- ${assetsImportsString}
42
-
43
- const bundleMap = {
44
- ${languagesKeysString}
45
- };
46
-
47
- const fetchMessageBundle = async (localeId) => {
48
- if (typeof bundleMap[localeId] === "object") {
49
- // inlined from build
50
- throw new Error("[i18n] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs")
51
- }
52
- return (await fetch(bundleMap[localeId])).json()
53
- }
54
-
55
- const localeIds = [${languagesKeysStringArray}];
56
-
57
- localeIds.forEach(localeId => {
58
- registerI18nLoader("${packageName}", localeId, fetchMessageBundle);
59
- });
60
- `;
61
-
62
65
  // Actual imports for json assets
63
66
  const dynamicImportsString = languages.map(key => ` case "${key}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-messagebundle-${key}" */ "../assets/i18n/messagebundle_${key}.json")).default;`).join("\n");
67
+ const fetchMetaResolveString = languages.map(key => ` case "${key}": return (await fetch(new URL("../assets/i18n/messagebundle_${key}.json", import.meta.url))).json();`).join("\n");
68
+ const dynamicImportJSONAttrString = languages.map(key => ` case "${key}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-messagebundle-${key}" */ "../assets/i18n/messagebundle_${key}.json", {with: { type: 'json'}})).default;`).join("\n");
64
69
 
65
70
  // Resulting file content
66
- contentDynamic = `// @ts-nocheck
67
- import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
68
-
69
- const importMessageBundle = async (localeId) => {
70
- switch (localeId) {
71
- ${dynamicImportsString}
72
- default: throw "unknown locale"
73
- }
74
- }
75
-
76
- const importAndCheck = async (localeId) => {
77
- const data = await importMessageBundle(localeId);
78
- if (typeof data === "string" && data.endsWith(".json")) {
79
- 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.\`);
80
- }
81
- return data;
82
- }
83
-
84
- const localeIds = [${languagesKeysStringArray}];
85
-
86
- localeIds.forEach(localeId => {
87
- registerI18nLoader("${packageName}", localeId, importAndCheck);
88
- });
89
- `;
90
-
91
71
 
72
+ contentDynamic = getContent(dynamicImportsString, languagesKeysStringArray, packageName);
73
+ contentFetchMetaResolve = getContent(fetchMetaResolveString, languagesKeysStringArray, packageName);
74
+ contentDynamicImportJSONAttr = getContent(dynamicImportJSONAttrString, languagesKeysStringArray, packageName);
92
75
  }
93
76
 
94
- await fs.mkdir(path.dirname(outputFile), { recursive: true });
77
+ await fs.mkdir(path.dirname(outputFileDynamic), { recursive: true });
95
78
  return Promise.all([
96
- fs.writeFile(outputFile, contentStatic),
97
79
  fs.writeFile(outputFileDynamic, contentDynamic),
80
+ fs.writeFile(outputFileFetchMetaResolve, contentFetchMetaResolve),
81
+ fs.writeFile(outputFileDynamicImportJSONImport, contentDynamicImportJSONAttr),
98
82
  ]);
99
83
  }
100
84
 
@@ -7,8 +7,9 @@ const ext = isTypeScript ? 'ts' : 'js';
7
7
 
8
8
  const generate = async () => {
9
9
  const inputFolder = path.normalize(process.argv[2]);
10
- const outputFile = path.normalize(`${process.argv[3]}/Themes-static.${ext}`);
11
10
  const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes.${ext}`);
11
+ const outputFileDynamicImportJSONAttr = path.normalize(`${process.argv[3]}/Themes-node.${ext}`);
12
+ const outputFileFetchMetaResolve = path.normalize(`${process.argv[3]}/Themes-fetch.${ext}`);
12
13
 
13
14
  // All supported optional themes
14
15
  const allThemes = assets.themes.all;
@@ -22,41 +23,19 @@ const generate = async () => {
22
23
 
23
24
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
24
25
 
25
- const importLines = themesOnFileSystem.map(theme => `import ${theme} from "../assets/themes/${theme}/parameters-bundle.css.json";`).join("\n");
26
- const themeUrlsByName = "{\n" + themesOnFileSystem.join(",\n") + "\n}";
27
26
  const availableThemesArray = `[${themesOnFileSystem.map(theme => `"${theme}"`).join(", ")}]`;
28
27
  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");
29
-
30
-
31
- // static imports file content
32
- const contentStatic = `// @ts-nocheck
33
- import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
34
-
35
- ${importLines}
36
-
37
- const themeUrlsByName = ${themeUrlsByName};
38
- const isInlined = obj => typeof (obj) === "object";
39
-
40
- const loadThemeProperties = async (themeName) => {
41
- if (typeof themeUrlsByName[themeName] === "object") {
42
- // inlined from build
43
- throw new Error("[themes] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs");
44
- }
45
- return (await fetch(themeUrlsByName[themeName])).json();
46
- };
47
-
48
- ${availableThemesArray}
49
- .forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadThemeProperties));
50
- `;
51
-
28
+ const dynamicImportJSONAttrLines = themesOnFileSystem.map(theme => `\t\tcase "${theme}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-${theme.replace("_", "-")}-parameters-bundle" */"../assets/themes/${theme}/parameters-bundle.css.json", {with: { type: 'json'}})).default;`).join("\n");
29
+ const fetchMetaResolveLines = themesOnFileSystem.map(theme => `\t\tcase "${theme}": return (await fetch(new URL("../assets/themes/${theme}/parameters-bundle.css.json", import.meta.url))).json();`).join("\n");
52
30
 
53
31
  // dynamic imports file content
54
- const contentDynamic = `// @ts-nocheck
32
+ const contentDynamic = function (lines) {
33
+ return `// @ts-nocheck
55
34
  import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
56
35
 
57
36
  const loadThemeProperties = async (themeName) => {
58
37
  switch (themeName) {
59
- ${dynamicImportLines}
38
+ ${lines}
60
39
  default: throw "unknown theme"
61
40
  }
62
41
  };
@@ -64,7 +43,7 @@ ${dynamicImportLines}
64
43
  const loadAndCheck = async (themeName) => {
65
44
  const data = await loadThemeProperties(themeName);
66
45
  if (typeof data === "string" && data.endsWith(".json")) {
67
- throw new Error(\`[themes] 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.\`);
46
+ throw new Error(\`[themes] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build. Check the \"Assets\" documentation for more information.\`);
68
47
  }
69
48
  return data;
70
49
  };
@@ -72,11 +51,13 @@ const loadAndCheck = async (themeName) => {
72
51
  ${availableThemesArray}
73
52
  .forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadAndCheck));
74
53
  `;
54
+ }
75
55
 
76
- await fs.mkdir(path.dirname(outputFile), { recursive: true });
56
+ await fs.mkdir(path.dirname(outputFileDynamic), { recursive: true });
77
57
  return Promise.all([
78
- fs.writeFile(outputFile, contentStatic),
79
- fs.writeFile(outputFileDynamic, contentDynamic)
58
+ fs.writeFile(outputFileDynamic, contentDynamic(dynamicImportLines)),
59
+ fs.writeFile(outputFileDynamicImportJSONAttr, contentDynamic(dynamicImportJSONAttrLines)),
60
+ fs.writeFile(outputFileFetchMetaResolve, contentDynamic(fetchMetaResolveLines)),
80
61
  ]);
81
62
  };
82
63
 
@@ -3,11 +3,11 @@ const tsImports = (controlName, hasTypes) => {
3
3
  return "";
4
4
  }
5
5
 
6
- const importPrefix = process.env.UI5_BASE ? "../../../" : "@ui5/webcomponents-base/dist/"
6
+ const importPrefix = process.env.UI5_BASE ? "../../../../../src/" : "@ui5/webcomponents-base/dist/"
7
7
 
8
8
  return `import type UI5Element from "${importPrefix}UI5Element.js";
9
- ${importForControl(controlName, hasTypes)}
10
- import type { ClassMapValue } from "${importPrefix}types.js";
9
+ ${importForControl(controlName, hasTypes)}
10
+ import type { ClassMapValue } from "${importPrefix}types.js";
11
11
  `;
12
12
  }
13
13
  const importForControl = (controlName, hasTypes) => {
@@ -18,21 +18,26 @@ const importForControl = (controlName, hasTypes) => {
18
18
 
19
19
  if (process.env.UI5_BASE) {
20
20
  // base package has a component in `test/elements` instead of `src`
21
- return `import type ${controlName} from "../../../../test/elements/${controlName}.js";`
21
+ return `import type ${controlName} from "../../../${controlName}.js";`
22
22
  }
23
23
  return `import type ${controlName} from "../../${controlName}.js";`
24
24
  }
25
25
 
26
26
  const buildRenderer = (controlName, litTemplate, hasTypes) => {
27
- const importPrefix = process.env.UI5_BASE ? "../../../" : "@ui5/webcomponents-base/dist/"
27
+ const importPrefix = process.env.UI5_BASE ? "../../../../../src/" : "@ui5/webcomponents-base/dist/";
28
+
29
+ const mainTemplateFunction = process.env.UI5_TS ?
30
+ `function template(this: ${controlName}) { return block0.call(this, this, (this.constructor as typeof UI5Element).tagsToScope, getCustomElementsScopingSuffix()); }` :
31
+ `function template() { return block0.call(this, this, this.constructor.tagsToScope, getCustomElementsScopingSuffix()); }`;
28
32
 
29
33
  // typescript cannot process package imports for the same package and the paths are changed to relative for base package templates
30
34
  return `/* eslint no-unused-vars: 0 */
31
35
  import { html, svg, repeat, classMap, styleMap, ifDefined, unsafeHTML, scopeTag } from "${importPrefix}renderer/LitRenderer.js";
36
+ import { getCustomElementsScopingSuffix } from "${importPrefix}CustomElementsScopeUtils.js";
32
37
  ${tsImports(controlName, hasTypes)}
33
38
  ${litTemplate}
34
-
35
- export default block0;`;
39
+ ${mainTemplateFunction}
40
+ export default template;`;
36
41
  };
37
42
 
38
43
  module.exports = {
@@ -24,7 +24,7 @@ const onError = (place) => {
24
24
  console.log(`A problem occoured when reading ${place}. Please recheck passed parameters.`);
25
25
  };
26
26
 
27
- const isHandlebars = (fileName) => fileName.indexOf('.hbs') !== -1;
27
+ const isHandlebars = (fileName) => fileName.endsWith('.hbs');
28
28
 
29
29
  const hasTypes = (file, componentName) => {
30
30
  const tsFile = path.join(path.dirname(file), componentName + ".ts")
@@ -36,7 +36,7 @@ const processFile = async (file, outputDir) => {
36
36
  const componentNameMatcher = /(\w+)(\.hbs)/gim;
37
37
  const componentName = componentNameMatcher.exec(file)[1];
38
38
  const componentHasTypes = hasTypes(file, componentName);
39
- if (!componentHasTypes) {
39
+ if (!componentHasTypes) {
40
40
  if (!missingTypesReported) {
41
41
  console.warn("[Warn] The following templates do not have a corresponging .ts or .d.ts file and won't be type checked:")
42
42
  missingTypesReported = true;
@@ -98,7 +98,7 @@ const writeRenderers = async (outputDir, controlName, fileContent) => {
98
98
 
99
99
  let existingFileContent = "";
100
100
  try {
101
- existingFileContent = await fs.readFile(compiledFilePath);
101
+ existingFileContent = (await fs.readFile(compiledFilePath)).toString();
102
102
  } catch (e) {}
103
103
 
104
104
  if (existingFileContent !== fileContentUnix) {
@@ -31,7 +31,8 @@ const generate = async () => {
31
31
  // (2) as the messagebundle.properties file is always written in English,
32
32
  // it makes sense to consider the messagebundle.properties content only when the default language is "en".
33
33
  if (defaultLanguage === "en") {
34
- defaultLanguageProperties = Object.assign({}, defaultLanguageProperties, properties);
34
+ // use messagebundle_en.properties to overwrite all developer properties, only the not translated ones will remain
35
+ defaultLanguageProperties = Object.assign({}, properties, defaultLanguageProperties);
35
36
  }
36
37
 
37
38
  /*
@@ -68,7 +69,7 @@ const generate = async () => {
68
69
  const texts = textKeys.map(prop => getTextInfo(prop, properties[prop], defaultLanguageProperties && defaultLanguageProperties[prop])).join('');
69
70
 
70
71
  // tabs are intentionally mixed to have proper identation in the produced file
71
- return `${tsMode ? `import { I18nText } from "@ui5/webcomponents-base/dist/i18nBundle.js";` : ""}
72
+ return `${tsMode ? `import type { I18nText } from "@ui5/webcomponents-base/dist/i18nBundle.js";` : ""}
72
73
  ${texts}
73
74
  export {${textKeys.join()}};`;
74
75
  };