@ui5/webcomponents-tools 0.0.0-d9b978d1d → 0.0.0-da0d3eb88

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 (40) hide show
  1. package/CHANGELOG.md +514 -0
  2. package/assets-meta.js +2 -6
  3. package/components-package/eslint.js +1 -0
  4. package/components-package/nps.js +20 -17
  5. package/components-package/wdio.js +414 -405
  6. package/icons-collection/nps.js +2 -2
  7. package/lib/amd-to-es6/index.js +102 -0
  8. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  9. package/lib/cem/custom-elements-manifest.config.mjs +501 -0
  10. package/lib/cem/event.mjs +131 -0
  11. package/lib/cem/schema-internal.json +1357 -0
  12. package/lib/cem/schema.json +1098 -0
  13. package/lib/cem/types-internal.d.ts +796 -0
  14. package/lib/cem/types.d.ts +736 -0
  15. package/lib/cem/utils.mjs +384 -0
  16. package/lib/cem/validate.js +70 -0
  17. package/lib/create-icons/index.js +8 -6
  18. package/lib/create-illustrations/index.js +40 -33
  19. package/lib/create-new-component/index.js +4 -11
  20. package/lib/create-new-component/tsFileContentTemplate.js +3 -12
  21. package/lib/css-processors/css-processor-component-styles.mjs +48 -0
  22. package/lib/css-processors/scope-variables.mjs +3 -0
  23. package/lib/dev-server/ssr-dom-shim-loader.js +26 -0
  24. package/lib/generate-js-imports/illustrations.js +9 -9
  25. package/lib/generate-json-imports/i18n.js +3 -35
  26. package/lib/generate-json-imports/themes.js +2 -29
  27. package/lib/i18n/defaults.js +1 -1
  28. package/lib/remove-dev-mode/remove-dev-mode.mjs +37 -0
  29. package/lib/scoping/lint-src.js +8 -7
  30. package/package.json +6 -2
  31. package/components-package/wdio.sync.js +0 -368
  32. package/lib/create-new-component/jsFileContentTemplate.js +0 -73
  33. package/lib/esm-abs-to-rel/index.js +0 -61
  34. package/lib/generate-custom-elements-manifest/index.js +0 -327
  35. package/lib/jsdoc/config.json +0 -29
  36. package/lib/jsdoc/configTypescript.json +0 -29
  37. package/lib/jsdoc/plugin.js +0 -2468
  38. package/lib/jsdoc/preprocess.js +0 -146
  39. package/lib/jsdoc/template/publish.js +0 -4120
  40. package/lib/replace-global-core/index.js +0 -25
@@ -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,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,9 +56,6 @@ 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 })
@@ -0,0 +1,48 @@
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 scopeVariables from "./scope-variables.mjs";
7
+
8
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
9
+ const inputFiles = await globby("src/styles/*.module.css");
10
+ const restArgs = process.argv.slice(2);
11
+
12
+ let componentStylesPlugin = {
13
+ name: 'component-styles',
14
+ setup(build) {
15
+ build.initialOptions.write = false;
16
+
17
+ build.onEnd(result => {
18
+ result.outputFiles.forEach(async f => {
19
+ // scoping
20
+ const newText = scopeVariables(f.text, packageJSON);
21
+ await mkdir(path.dirname(f.path), {recursive: true});
22
+ writeFile(f.path, newText);
23
+ writeFile(f.path.replace(".module.css", ".css"), newText);
24
+ });
25
+ })
26
+ },
27
+ }
28
+
29
+ const config = {
30
+ entryPoints: inputFiles,
31
+ outdir: 'dist',
32
+ bundle: true,
33
+ outbase: 'src',
34
+ loader: {
35
+ ".module.css": "global-css"
36
+ },
37
+ plugins: [
38
+ componentStylesPlugin,
39
+ ]
40
+ };
41
+
42
+ if (restArgs.includes("-w")) {
43
+ let ctx = await esbuild.context(config);
44
+ await ctx.watch()
45
+ console.log('watching...')
46
+ } else {
47
+ await esbuild.build(config);
48
+ }
@@ -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
@@ -0,0 +1,26 @@
1
+ const fs = require("fs");
2
+
3
+ /**
4
+ * UI5Elements loads the ssr-dom.js file with a package specifier to use the export conditions
5
+ * in the package.json so that a shim for the dom can be loaded from SSR environments
6
+ * This however makes the TS Checker plugin used for development try to load the file from dist as input
7
+ * This plugin loads an empty file and TS ignores the file completely
8
+ */
9
+
10
+ const ssrDomShimLoader = async () => {
11
+ return {
12
+ name: 'ssr-dom-shim-loader',
13
+ resolveId(id) {
14
+ if (id === "@ui5/webcomponents-base/dist/ssr-dom.js") {
15
+ return "\0shim"
16
+ }
17
+ },
18
+ load(id) {
19
+ if (id === "\0shim") {
20
+ return "";
21
+ }
22
+ }
23
+ }
24
+ };
25
+
26
+ module.exports = ssrDomShimLoader;
@@ -21,12 +21,12 @@ const generateAvailableIllustrationsArray = (fileNames, exclusionPatterns = [])
21
21
  );
22
22
  };
23
23
 
24
- const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, prefix = "") => {
24
+ const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, set, prefix = "") => {
25
25
  return `// @ts-nocheck
26
26
  import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
27
27
 
28
28
  export const loadIllustration = async (illustrationName) => {
29
- const collectionAndPrefix = "${collection}/${prefix}";
29
+ const collectionAndPrefix = "${set}/${collection}/${prefix}";
30
30
  const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
31
31
  switch (cleanIllustrationName) {
32
32
  ${dynamicImports}
@@ -41,7 +41,7 @@ const loadAndCheck = async (illustrationName) => {
41
41
  };
42
42
 
43
43
  ${availableIllustrations}.forEach((illustrationName) =>
44
- registerIllustrationLoader(\`${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
44
+ registerIllustrationLoader(\`${set}/${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
45
45
  );
46
46
  `;
47
47
  };
@@ -52,7 +52,7 @@ const getMatchingFiles = async (folder, pattern) => {
52
52
  };
53
53
 
54
54
  const generateIllustrations = async (config) => {
55
- const { inputFolder, outputFile, collection, location, prefix, filterOut } = config;
55
+ const { inputFolder, outputFile, collection, location, prefix, filterOut, set } = config;
56
56
 
57
57
  const normalizedInputFolder = path.normalize(inputFolder);
58
58
  const normalizedOutputFile = path.normalize(outputFile);
@@ -62,7 +62,7 @@ const generateIllustrations = async (config) => {
62
62
  const dynamicImports = await generateDynamicImportLines(illustrations, location, filterOut);
63
63
  const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
64
64
 
65
- const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, prefix);
65
+ const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, set, prefix);
66
66
 
67
67
  await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
68
68
  await fs.writeFile(normalizedOutputFile, contentDynamic);
@@ -74,10 +74,10 @@ const generateIllustrations = async (config) => {
74
74
  const config = {
75
75
  inputFolder: process.argv[2],
76
76
  outputFile: process.argv[3],
77
- collection: process.argv[4],
78
- location: process.argv[5],
79
- prefix: process.argv[6],
80
- 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],
81
81
  };
82
82
 
83
83
  // Run the generation process
@@ -9,7 +9,6 @@ const generate = async () => {
9
9
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
10
10
 
11
11
  const inputFolder = path.normalize(process.argv[2]);
12
- const outputFile = path.normalize(`${process.argv[3]}/i18n-static.${ext}`);
13
12
  const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.${ext}`);
14
13
 
15
14
  // All languages present in the file system
@@ -19,46 +18,16 @@ const generate = async () => {
19
18
  return matches ? matches[1] : undefined;
20
19
  }).filter(key => !!key);
21
20
 
22
- let contentStatic, contentDynamic;
21
+ let contentDynamic;
23
22
 
24
23
  // No i18n - just import dependencies, if any
25
24
  if (languages.length === 0) {
26
- contentStatic = "";
27
25
  contentDynamic = "";
28
26
  // There is i18n - generate the full file
29
27
  } else {
30
28
  // Keys for the array
31
- const languagesKeysString = languages.map(key => `"${key}": _${key},`).join("\n\t");
32
29
  const languagesKeysStringArray = languages.map(key => `"${key}",`).join("\n\t");
33
30
 
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
31
  // Actual imports for json assets
63
32
  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
33
 
@@ -76,7 +45,7 @@ import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registrie
76
45
  const importAndCheck = async (localeId) => {
77
46
  const data = await importMessageBundle(localeId);
78
47
  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.\`);
48
+ 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.\`);
80
49
  }
81
50
  return data;
82
51
  }
@@ -91,9 +60,8 @@ import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registrie
91
60
 
92
61
  }
93
62
 
94
- await fs.mkdir(path.dirname(outputFile), { recursive: true });
63
+ await fs.mkdir(path.dirname(outputFileDynamic), { recursive: true });
95
64
  return Promise.all([
96
- fs.writeFile(outputFile, contentStatic),
97
65
  fs.writeFile(outputFileDynamic, contentDynamic),
98
66
  ]);
99
67
  }
@@ -7,7 +7,6 @@ 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}`);
12
11
 
13
12
  // All supported optional themes
@@ -22,34 +21,9 @@ const generate = async () => {
22
21
 
23
22
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
24
23
 
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
24
  const availableThemesArray = `[${themesOnFileSystem.map(theme => `"${theme}"`).join(", ")}]`;
28
25
  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
26
 
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
-
52
-
53
27
  // dynamic imports file content
54
28
  const contentDynamic = `// @ts-nocheck
55
29
  import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
@@ -64,7 +38,7 @@ ${dynamicImportLines}
64
38
  const loadAndCheck = async (themeName) => {
65
39
  const data = await loadThemeProperties(themeName);
66
40
  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.\`);
41
+ 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
42
  }
69
43
  return data;
70
44
  };
@@ -73,9 +47,8 @@ ${availableThemesArray}
73
47
  .forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadAndCheck));
74
48
  `;
75
49
 
76
- await fs.mkdir(path.dirname(outputFile), { recursive: true });
50
+ await fs.mkdir(path.dirname(outputFileDynamic), { recursive: true });
77
51
  return Promise.all([
78
- fs.writeFile(outputFile, contentStatic),
79
52
  fs.writeFile(outputFileDynamic, contentDynamic)
80
53
  ]);
81
54
  };
@@ -31,7 +31,7 @@ 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
+ defaultLanguageProperties = Object.assign({}, defaultLanguageProperties, properties);
35
35
  }
36
36
 
37
37
  /*
@@ -0,0 +1,37 @@
1
+ import { globby } from "globby";
2
+ import * as esbuild from 'esbuild'
3
+ import * as fs from "fs";
4
+
5
+ let customPlugin = {
6
+ name: 'ui5-tools',
7
+ setup(build) {
8
+ build.onLoad({ filter: /UI5Element.ts$/ }, async (args) => {
9
+ let text = await fs.promises.readFile(args.path, 'utf8');
10
+ text = text.replaceAll(/const DEV_MODE = true/g, "");
11
+ text = text.replaceAll(/if \(DEV_MODE\)/g, "if (false)");
12
+ return {
13
+ contents: text,
14
+ loader: 'ts',
15
+ }
16
+ })
17
+ },
18
+ }
19
+
20
+ const getConfig = async () => {
21
+ const config = {
22
+ entryPoints: await globby("src/**/*.ts"),
23
+ bundle: false,
24
+ minify: true,
25
+ sourcemap: true,
26
+ outdir: 'dist/prod',
27
+ outbase: 'src',
28
+ plugins: [
29
+ customPlugin,
30
+ ]
31
+ };
32
+ return config;
33
+ }
34
+
35
+
36
+ const config = await getConfig();
37
+ const result = await esbuild.build(config);
@@ -7,25 +7,26 @@ const tags = getAllTags(process.cwd());
7
7
 
8
8
  const errors = [];
9
9
 
10
+ const removeComments = str => str.replaceAll(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, "");
11
+
10
12
  glob.sync(path.join(process.cwd(), "src/**/*.css")).forEach(file => {
11
- let content = String(fs.readFileSync(file));
13
+ let content = removeComments(String(fs.readFileSync(file)));
12
14
  tags.forEach(tag => {
13
15
  if (content.match(new RegExp(`(^|[^\.\-_A-Za-z0-9"\[])(${tag})([^\-_A-Za-z0-9]|$)`, "g"))) {
14
- errors.push(`Warning! ${tag} found in ${file}`);
16
+ errors.push(`${tag} found in ${file}`);
15
17
  }
16
18
  });
17
19
  });
18
20
 
19
- glob.sync(path.join(process.cwd(), "src/**/*.js")).forEach(file => {
20
- let content = String(fs.readFileSync(file));
21
+ glob.sync(path.join(process.cwd(), "src/**/*.ts")).forEach(file => {
22
+ let content = removeComments(String(fs.readFileSync(file)));
21
23
  tags.forEach(tag => {
22
24
  if (content.match(new RegExp(`querySelector[A-Za-z]*..${tag}`, "g"))) {
23
- errors.push(`Warning! querySelector for ${tag} found in ${file}`);
25
+ errors.push(`querySelector for ${tag} found in ${file}`);
24
26
  }
25
27
  });
26
28
  });
27
29
 
28
30
  if (errors.length) {
29
- errors.forEach(error => console.log(error));
30
- throw new Error("Errors found.");
31
+ throw new Error(`Scoping-related errors found (f.e. used ui5-input instead of [ui5-input]): \n ${errors.join("\n")}`);
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-tools",
3
- "version": "0.0.0-d9b978d1d",
3
+ "version": "0.0.0-da0d3eb88",
4
4
  "description": "UI5 Web Components: webcomponents.tools",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -21,6 +21,7 @@
21
21
  "directory": "packages/tools"
22
22
  },
23
23
  "dependencies": {
24
+ "@custom-elements-manifest/analyzer": "^0.8.4",
24
25
  "@typescript-eslint/eslint-plugin": "^6.9.0",
25
26
  "@typescript-eslint/parser": "^6.9.0",
26
27
  "@wdio/cli": "^7.19.7",
@@ -29,13 +30,17 @@
29
30
  "@wdio/mocha-framework": "^7.19.7",
30
31
  "@wdio/spec-reporter": "^7.19.7",
31
32
  "@wdio/static-server-service": "^7.19.5",
33
+ "ajv": "^8.12.0",
34
+ "cem-plugin-vs-code-custom-data-generator": "^1.4.2",
32
35
  "chai": "^4.3.4",
33
36
  "child_process": "^1.0.2",
34
37
  "chokidar": "^3.5.1",
35
38
  "chokidar-cli": "^3.0.0",
36
39
  "command-line-args": "^5.1.1",
40
+ "comment-parser": "^1.4.0",
37
41
  "concurrently": "^6.0.0",
38
42
  "cross-env": "^7.0.3",
43
+ "custom-element-jet-brains-integration": "^1.4.4",
39
44
  "escodegen": "^2.0.0",
40
45
  "eslint": "^7.22.0",
41
46
  "eslint-config-airbnb-base": "^14.2.1",
@@ -47,7 +52,6 @@
47
52
  "globby": "^13.1.1",
48
53
  "handlebars": "^4.7.7",
49
54
  "is-port-reachable": "^3.1.0",
50
- "jsdoc": "^3.6.6",
51
55
  "json-beautify": "^1.1.1",
52
56
  "mkdirp": "^1.0.4",
53
57
  "nps": "^5.10.0",