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

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 (92) hide show
  1. package/CHANGELOG.md +752 -0
  2. package/README.md +6 -6
  3. package/assets-meta.js +23 -3
  4. package/bin/dev.js +12 -1
  5. package/components-package/eslint.js +34 -0
  6. package/components-package/nps.js +112 -44
  7. package/components-package/postcss.components.js +18 -15
  8. package/components-package/postcss.themes.js +23 -16
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +405 -297
  11. package/components-package/wdio.sync.js +368 -0
  12. package/icons-collection/nps.js +52 -11
  13. package/lib/copy-and-watch/index.js +145 -0
  14. package/lib/copy-list/index.js +28 -0
  15. package/lib/create-icons/index.js +124 -54
  16. package/lib/create-illustrations/index.js +175 -0
  17. package/lib/create-new-component/index.js +72 -93
  18. package/lib/create-new-component/jsFileContentTemplate.js +73 -0
  19. package/lib/create-new-component/tsFileContentTemplate.js +80 -0
  20. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  21. package/lib/dev-server/dev-server.js +66 -0
  22. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  23. package/lib/esm-abs-to-rel/index.js +58 -0
  24. package/lib/generate-custom-elements-manifest/index.js +327 -0
  25. package/lib/generate-js-imports/illustrations.js +83 -0
  26. package/lib/generate-json-imports/i18n.js +98 -47
  27. package/lib/generate-json-imports/themes.js +67 -17
  28. package/lib/hbs2lit/index.js +2 -4
  29. package/lib/hbs2lit/src/compiler.js +30 -9
  30. package/lib/hbs2lit/src/includesReplacer.js +23 -17
  31. package/lib/hbs2lit/src/litVisitor2.js +125 -26
  32. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  33. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +35 -7
  34. package/lib/hbs2ui5/index.js +69 -30
  35. package/lib/i18n/defaults.js +66 -54
  36. package/lib/i18n/toJSON.js +13 -10
  37. package/lib/jsdoc/config.json +1 -1
  38. package/lib/jsdoc/configTypescript.json +29 -0
  39. package/lib/jsdoc/plugin.js +65 -4
  40. package/lib/jsdoc/preprocess.js +146 -0
  41. package/lib/jsdoc/template/publish.js +32 -4
  42. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  43. package/lib/postcss-css-to-esm/index.js +64 -16
  44. package/lib/postcss-css-to-json/index.js +31 -11
  45. package/lib/postcss-new-files/index.js +36 -0
  46. package/lib/postcss-p/postcss-p.mjs +14 -0
  47. package/lib/postcss-scope-vars/index.js +24 -0
  48. package/lib/replace-global-core/index.js +25 -0
  49. package/lib/scoping/get-all-tags.js +37 -0
  50. package/lib/scoping/lint-src.js +31 -0
  51. package/lib/scoping/missing-dependencies.js +65 -0
  52. package/lib/scoping/report-tags-usage.js +28 -0
  53. package/lib/scoping/scope-test-pages.js +40 -0
  54. package/lib/test-runner/test-runner.js +71 -0
  55. package/package.json +54 -54
  56. package/bin/init-ui5-package.js +0 -3
  57. package/components-package/rollup.js +0 -134
  58. package/components-package/serve.json +0 -3
  59. package/lib/documentation/index.js +0 -143
  60. package/lib/documentation/templates/api-component-since.js +0 -3
  61. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  62. package/lib/documentation/templates/api-events-section.js +0 -35
  63. package/lib/documentation/templates/api-methods-section.js +0 -26
  64. package/lib/documentation/templates/api-properties-section.js +0 -40
  65. package/lib/documentation/templates/api-slots-section.js +0 -28
  66. package/lib/documentation/templates/template.js +0 -38
  67. package/lib/init-package/index.js +0 -119
  68. package/lib/init-package/resources/.eslintignore +0 -3
  69. package/lib/init-package/resources/bundle.es5.js +0 -25
  70. package/lib/init-package/resources/bundle.esm.js +0 -34
  71. package/lib/init-package/resources/config/.eslintrc.js +0 -1
  72. package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
  73. package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
  74. package/lib/init-package/resources/config/rollup.config.js +0 -1
  75. package/lib/init-package/resources/config/wdio.conf.js +0 -1
  76. package/lib/init-package/resources/package-scripts.js +0 -11
  77. package/lib/init-package/resources/src/Assets.js +0 -5
  78. package/lib/init-package/resources/src/Demo.hbs +0 -1
  79. package/lib/init-package/resources/src/Demo.js +0 -56
  80. package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
  81. package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
  82. package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
  83. package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
  84. package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
  85. package/lib/init-package/resources/src/themes/Demo.css +0 -11
  86. package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
  87. package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
  88. package/lib/init-package/resources/src/themes/sap_belize_hcw/parameters-bundle.css +0 -3
  89. package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  90. package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
  91. package/lib/init-package/resources/test/pages/index.html +0 -51
  92. package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
@@ -0,0 +1,80 @@
1
+ const tsFileContentTemplate = (componentName, tagName, library, packageName) => {
2
+ return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
3
+ import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
4
+ import property from "@ui5/webcomponents-base/dist/decorators/property.js";
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";
8
+
9
+ import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
10
+
11
+ // Styles
12
+ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
13
+
14
+ /**
15
+ * @class
16
+ *
17
+ * <h3 class="comment-api-title">Overview</h3>
18
+ *
19
+ *
20
+ * <h3>Usage</h3>
21
+ *
22
+ * For the <code>${tagName}</code>
23
+ * <h3>ES6 Module Import</h3>
24
+ *
25
+ * <code>import ${packageName}/dist/${componentName}.js";</code>
26
+ *
27
+ * @constructor
28
+ * @author SAP SE
29
+ * @alias sap.ui.webc.${library}.${componentName}
30
+ * @extends sap.ui.webc.base.UI5Element
31
+ * @tagname ${tagName}
32
+ * @public
33
+ */
34
+ @customElement({
35
+ tag: "${tagName}",
36
+ renderer: litRender,
37
+ styles: ${componentName}Css,
38
+ template: ${componentName}Template,
39
+ dependencies: [],
40
+ })
41
+
42
+ /**
43
+ * Example custom event.
44
+ * Please keep in mind that all public events should be documented in the API Reference as shown below.
45
+ *
46
+ * @event sap.ui.webc.${library}.${componentName}#interact
47
+ * @public
48
+ */
49
+ @event("interact", { detail: { /* event payload ( optional ) */ } })
50
+ class ${componentName} extends UI5Element {
51
+ /**
52
+ * Defines the value of the component.
53
+ *
54
+ * @type {string}
55
+ * @name sap.ui.webc.${library}.${componentName}.prototype.value
56
+ * @defaultvalue ""
57
+ * @public
58
+ */
59
+ @property()
60
+ value!: string;
61
+
62
+ /**
63
+ * Defines the text of the component.
64
+ *
65
+ * @type {Node[]}
66
+ * @name sap.ui.webc.${library}.${componentName}.prototype.default
67
+ * @slot
68
+ * @public
69
+ */
70
+ @slot({ type: Node, "default": true })
71
+ text!: Array<Node>;
72
+ }
73
+
74
+ ${componentName}.define();
75
+
76
+ export default ${componentName};
77
+ `;
78
+ };
79
+
80
+ module.exports = tsFileContentTemplate;
@@ -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.includes("dist/") && 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;
@@ -0,0 +1,66 @@
1
+ const fs = require("fs/promises");
2
+ const { createServer } = require('vite');
3
+ const yargs = require('yargs/yargs')
4
+ const { hideBin } = require('yargs/helpers')
5
+
6
+ const argv = yargs(hideBin(process.argv))
7
+ .alias("c", "config")
8
+ .argv;
9
+
10
+ const startVite = async (port) => {
11
+ const server = await createServer({
12
+ configFile: argv.config,
13
+ server: {
14
+ port: port,
15
+ strictPort: true,
16
+ open: true,
17
+ host: true,
18
+ },
19
+ logLevel: 'info',
20
+ clearScreen: false,
21
+ })
22
+ await server.listen()
23
+ server.printUrls()
24
+ return server;
25
+ };
26
+
27
+ const rmPortFile = async () => {
28
+ // exit handler must be sync
29
+ try {
30
+ await fs.rm(".dev-server-port");
31
+ } catch (e) {}
32
+ process.exit();
33
+ }
34
+
35
+ ["exit", "SIGINT", "SIGUSR1", "SIGUSR2", "uncaughtException", "SIGTERM"].forEach((eventType) => {
36
+ process.on(eventType, rmPortFile);
37
+ });
38
+
39
+ (async () => {
40
+ let retries = 10;
41
+ let port = 8080;
42
+ while (retries--) {
43
+ console.log(`taking port ${port}`);
44
+ await fs.writeFile(".dev-server-port", `${port}`);
45
+ try {
46
+ // execSync(command, {stdio: 'pipe'});
47
+ const server = await startVite(port);
48
+ if (server) {
49
+ // server started, don't try other ports
50
+ break;
51
+ }
52
+ } catch (e) {
53
+ // uncomment for debug
54
+ // console.log(e.toString());
55
+ if (e.toString().includes("already in use")) {
56
+ console.log(`Port ${port} already in use`)
57
+ port++;
58
+ continue;
59
+ }
60
+ // other error or CTRL-C
61
+ process.exit();
62
+ }
63
+ // no error normal exit
64
+ // process.exit();
65
+ }
66
+ })();
@@ -0,0 +1,52 @@
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
+ });
11
+
12
+ const rollupInput = {};
13
+
14
+ files.forEach(file => {
15
+ rollupInput[file] = path.resolve(process.cwd(), file);
16
+ })
17
+
18
+ return {
19
+ name: 'virtual-index-html',
20
+ config() {
21
+ return {
22
+ build: {
23
+ rollupOptions: {
24
+ input: rollupInput
25
+ }
26
+ }
27
+ }
28
+ },
29
+ configureServer(server) {
30
+ server.middlewares.use((req, res, next) => {
31
+ if (req.url === "/") {
32
+ const folders = Object.keys(pagesPerFolder);
33
+
34
+ res.statusCode = 200;
35
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
36
+ res.end(`${folders.map(folder => {
37
+ const pages = pagesPerFolder[folder];
38
+ return `<h1>${folder}</h1>
39
+ ${pages.map(page => {
40
+ return `<li><a href='${folder}/${page}'>${page}</a></li>`
41
+ }).join("")}
42
+ `
43
+ }).join("")}`);
44
+ } else {
45
+ next();
46
+ }
47
+ })
48
+ },
49
+ }
50
+ };
51
+
52
+ module.exports = virtualIndexPlugin;
@@ -0,0 +1,58 @@
1
+ const esprima = require("esprima");
2
+ const escodegen = require("escodegen");
3
+
4
+ const fs = require("fs").promises;
5
+ const path = require("path");
6
+ const basePath = process.argv[2];
7
+
8
+ const convertImports = async (srcPath) => {
9
+ let changed = false;
10
+ // console.log("scanning imports of", srcPath);
11
+ let code = (await fs.readFile(srcPath)).toString();
12
+ const tree = esprima.parseModule(code);
13
+ const importer = srcPath.replace(basePath, "");
14
+ const importerDir = path.dirname(importer);
15
+ // console.log("-> ", importer);
16
+ tree.body.forEach(node => {
17
+ if (node.type === "ImportDeclaration") {
18
+ let importee = node.source.value;
19
+ if (importee.startsWith(".")) {
20
+ // add .js extension if missing
21
+ if (!importee.endsWith(".js")) {
22
+ node.source.value += ".js"
23
+ changed = true;
24
+ }
25
+ return;
26
+ }
27
+ let importeeDir = path.dirname(importee);
28
+ let importeeFile = path.basename(importee);
29
+ let relativePath = path.relative(importerDir, importeeDir);
30
+ if (relativePath.length === 0) {
31
+ relativePath = "."
32
+ }
33
+ if (!relativePath.startsWith(".")) {
34
+ relativePath = "./" + relativePath;
35
+ }
36
+
37
+ relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
38
+ let relativeImport = `${relativePath}/${importeeFile}.js`;
39
+ // console.log(importee + " --> " + relativeImport);
40
+ node.source.value = relativeImport;
41
+ changed = true;
42
+ }
43
+ });
44
+
45
+ if (changed) {
46
+ return fs.writeFile(srcPath, escodegen.generate(tree));
47
+ }
48
+ }
49
+
50
+ const generate = async () => {
51
+ const { globby } = await import("globby");
52
+ const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
53
+ return Promise.all(fileNames.map(convertImports).filter(x => !!x));
54
+ };
55
+
56
+ generate().then(() => {
57
+ console.log("Success: Converted absolute imports to relative for files in:", basePath);
58
+ });
@@ -0,0 +1,327 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+ // https://github.com/webcomponents/custom-elements-manifest/blob/main/schema.json
4
+
5
+ const inputDir = process.argv[2];
6
+ const outputDir = process.argv[3];
7
+
8
+ const camelToKebabMap = new Map();
9
+ const apiIndex = new Map();
10
+ const forbiddenAttributeTypes = ["object", "array"];
11
+
12
+ const camelToKebabCase = string => {
13
+ if (!camelToKebabMap.has(string)) {
14
+ const result = string.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
15
+ camelToKebabMap.set(string, result);
16
+ }
17
+ return camelToKebabMap.get(string);
18
+ };
19
+
20
+ const generateJavaScriptExport = entity => {
21
+ return {
22
+ declaration: generateRefenrece(entity.name),
23
+ deprecated: !!entity.deprecated,
24
+ kind: "js",
25
+ name: "default",
26
+ };
27
+ };
28
+
29
+ const generateCustomElementExport = entity => {
30
+ return {
31
+ declaration: {
32
+ name: entity.basename,
33
+ module: `${entity.module}.js`,
34
+ },
35
+ deprecated: !!entity.deprecated,
36
+ kind: "custom-element-definition",
37
+ name: entity.tagname,
38
+ };
39
+ };
40
+
41
+ const generateJavaScriptModule = entity => {
42
+ return {
43
+ kind: "javascript-module",
44
+ path: `${entity.basename}.js`,
45
+ declarations: [
46
+ generateCustomElementDeclaration(entity),
47
+ ],
48
+ exports: [
49
+ generateJavaScriptExport(entity),
50
+ generateCustomElementExport(entity),
51
+ ],
52
+ };
53
+ };
54
+
55
+ const generateSingleClassField = classField => {
56
+ let generatedClassField = {
57
+ deprecated: !!classField.deprecated,
58
+ kind: "field",
59
+ name: classField.name,
60
+ privacy: classField.visibility,
61
+ static: !!classField.static,
62
+ type: generateType(classField.type),
63
+ };
64
+
65
+ if (classField.defaultValue) {
66
+ generatedClassField.default = classField.defaultValue;
67
+ }
68
+
69
+ if (classField.description) {
70
+ generatedClassField.description = classField.description;
71
+ }
72
+
73
+ return generatedClassField;
74
+ };
75
+
76
+ const generateSingleParameter = parameter => {
77
+ let generatedParameter = {
78
+ deprecated: !!parameter.deprecated,
79
+ name: parameter.name,
80
+ type: generateType(parameter.type),
81
+ };
82
+
83
+ if (parameter.description) {
84
+ generatedParameter.description = parameter.description;
85
+ }
86
+
87
+ if (parameter.optional) {
88
+ generatedParameter.optional = parameter.optional;
89
+ }
90
+
91
+ return generatedParameter;
92
+ };
93
+
94
+ const generateParameters = (parameters) => {
95
+ return parameters.reduce((newParametersArray, parameter) => {
96
+ newParametersArray.push(generateSingleParameter(parameter));
97
+
98
+ return newParametersArray;
99
+ }, []);
100
+ };
101
+
102
+ const generateSingleClassMethod = classMethod => {
103
+ let generatedClassMethod = {
104
+ deprecated: !!classMethod.deprecated,
105
+ kind: "method",
106
+ name: classMethod.name,
107
+ privacy: classMethod.visibility,
108
+ static: classMethod.static,
109
+ };
110
+
111
+ if (classMethod.description) {
112
+ generatedClassMethod.description = classMethod.description;
113
+ }
114
+
115
+ if (classMethod.parameters && classMethod.parameters.length) {
116
+ generatedClassMethod.parameters = generateParameters(classMethod.parameters);
117
+ }
118
+
119
+ if (classMethod.returnValue) {
120
+ generatedClassMethod.return = {
121
+ type: generateType(classMethod.returnValue.type),
122
+ };
123
+
124
+ if (classMethod.returnValue.description) {
125
+ generatedClassMethod.return.description = classMethod.returnValue.type;
126
+ }
127
+ }
128
+
129
+ return generatedClassMethod;
130
+ };
131
+
132
+ const generateClassFields = classFields => {
133
+ return classFields.reduce((newClassFieldsArray, classField) => {
134
+ newClassFieldsArray.push(generateSingleClassField(classField));
135
+
136
+ return newClassFieldsArray;
137
+ }, []);
138
+ };
139
+
140
+ const generateClassMethods = classMethods => {
141
+ return classMethods.reduce((newClassMethodsArray, classMethod) => {
142
+ newClassMethodsArray.push(generateSingleClassMethod(classMethod));
143
+
144
+ return newClassMethodsArray;
145
+ }, []);
146
+ };
147
+
148
+ const generateMembers = (classFields, classMethods) => {
149
+ return [...generateClassFields(classFields), ...generateClassMethods(classMethods)];
150
+ };
151
+
152
+ const generateType = type => {
153
+ const dataType = apiIndex.get(type);
154
+
155
+ return {
156
+ text: dataType && dataType.name.includes(".types.") ?
157
+ filterPublicApi(dataType.properties)
158
+ .map(prop => `"${prop.name}"`)
159
+ .join(" | ") : type,
160
+ };
161
+ };
162
+
163
+ const generateSingleAttribute = attribute => {
164
+ let generatedAttribute = {
165
+ default: attribute.defaultValue,
166
+ deprecated: !!attribute.deprecated,
167
+ fieldName: attribute.name,
168
+ name: camelToKebabCase(attribute.name),
169
+ type: generateType(attribute.type),
170
+ };
171
+
172
+ if (attribute.description) {
173
+ generatedAttribute.description = attribute.description;
174
+ }
175
+
176
+ return generatedAttribute;
177
+ };
178
+
179
+ const generateAttributes = attributes => {
180
+ attributes = attributes.reduce((newAttributesArray, attribute) => {
181
+ newAttributesArray.push(generateSingleAttribute(attribute));
182
+
183
+ return newAttributesArray;
184
+ }, []);
185
+
186
+ return attributes;
187
+ };
188
+
189
+ const generateSingleEvent = event => {
190
+ let generatedEvent = {
191
+ deprecated: !!event.deprecated,
192
+ name: event.name,
193
+ type: event.native === "true" ? "NativeEvent" : "CustomEvent",
194
+ };
195
+
196
+ if (event.description) {
197
+ generatedEvent.description = event.description;
198
+ }
199
+
200
+ return generatedEvent;
201
+ };
202
+
203
+ const generateEvents = events => {
204
+ events = events.reduce((newEventsArray, event) => {
205
+ newEventsArray.push(generateSingleEvent(event));
206
+
207
+ return newEventsArray;
208
+ }, []);
209
+
210
+ return events;
211
+ };
212
+
213
+ const generateSingleSlot = slot => {
214
+ return {
215
+ deprecated: !!slot.deprecated,
216
+ description: slot.description,
217
+ name: slot.name,
218
+ };
219
+ };
220
+
221
+ const generateSlots = slots => {
222
+ slots = slots.reduce((newSlotsArray, event) => {
223
+ newSlotsArray.push(generateSingleSlot(event));
224
+
225
+ return newSlotsArray;
226
+ }, []);
227
+
228
+ return slots;
229
+ };
230
+
231
+ const generateCustomElementDeclaration = entity => {
232
+ let generatedCustomElementDeclaration = {
233
+ deprecated: !!entity.deprecated,
234
+ customElement: true,
235
+ kind: entity.basename,
236
+ name: entity.basename,
237
+ tagName: entity.tagname,
238
+ };
239
+
240
+ const slots = filterPublicApi(entity.slots);
241
+ const events = filterPublicApi(entity.events);
242
+ const classFields = filterPublicApi(entity.properties);
243
+ const classMethods = filterPublicApi(entity.methods);
244
+ const attributes = classFields.filter(property => {
245
+ return property.noattribute !== "true" && property.readonly !== "true" && !forbiddenAttributeTypes.includes(property.type.toLowerCase());
246
+ });
247
+
248
+ if (slots.length) {
249
+ generatedCustomElementDeclaration.slots = generateSlots(slots);
250
+ }
251
+
252
+ if (events.length) {
253
+ generatedCustomElementDeclaration.events = generateEvents(events);
254
+ }
255
+
256
+ if (attributes.length) {
257
+ generatedCustomElementDeclaration.attributes = generateAttributes(attributes);
258
+ }
259
+
260
+ if (entity.description) {
261
+ generatedCustomElementDeclaration.description = entity.description;
262
+ }
263
+
264
+ if (classFields.length || classMethods.length) {
265
+ generatedCustomElementDeclaration.members = generateMembers(classFields, classMethods);
266
+ }
267
+
268
+ if (entity.extends && entity.extends !== "HTMLElement") {
269
+ generatedCustomElementDeclaration.superclass = generateRefenrece(entity.extends);
270
+ }
271
+
272
+ return generatedCustomElementDeclaration;
273
+ };
274
+
275
+ const generateRefenrece = (entityName) => {
276
+ let packageName;
277
+ let basename;
278
+
279
+ if (!entityName) {
280
+ throw new Error("JSDoc error: entity not found in api.json.");
281
+ }
282
+
283
+ if (entityName.includes(".")) {
284
+ basename = entityName.split(".").pop();
285
+ } else {
286
+ basename = entityName
287
+ }
288
+
289
+ if (entityName.includes("sap.ui.webc.main")) {
290
+ packageName = "@ui5/webcomponents";
291
+ } else if (entityName.includes("sap.ui.webc.fiori")) {
292
+ packageName = "@ui5/webcomponents-fiori";
293
+ } else if (entityName.includes("sap.ui.webc.base")) {
294
+ packageName = "@ui5/webcomponents-base";
295
+ }
296
+
297
+ return {
298
+ module: `${basename}.js`,
299
+ name: `${basename}`,
300
+ package: packageName,
301
+ };
302
+ };
303
+
304
+ const filterPublicApi = array => {
305
+ return (array || []).filter(el => el.visibility === "public");
306
+ };
307
+
308
+ const generate = async () => {
309
+ const file = JSON.parse(await fs.readFile(path.join(inputDir, "api.json")));
310
+ let customElementsManifest = {
311
+ schemaVersion: "1.0.0",
312
+ readme: "",
313
+ modules: [],
314
+ };
315
+
316
+ file.symbols.forEach(entity => {
317
+ if (entity.tagname || entity.kind === "class") {
318
+ customElementsManifest.modules.push(generateJavaScriptModule(entity));
319
+ }
320
+ });
321
+
322
+ await fs.writeFile(path.join(outputDir, "custom-elements.json"), JSON.stringify(customElementsManifest));
323
+ };
324
+
325
+ generate().then(() => {
326
+ console.log("Custom elements manifest generated.");
327
+ });
@@ -0,0 +1,83 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const generateDynamicImportLines = (fileNames, location, exclusionPatterns = []) => {
5
+ return fileNames
6
+ .filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
7
+ .map((fileName) => {
8
+ const illustrationPath = `${location}/${fileName.replace(".js", "")}`;
9
+ return `\t\tcase "${fileName.replace('.js', '')}": return (await import("${illustrationPath}.js")).default;`;
10
+ })
11
+ .join("\n");
12
+ };
13
+
14
+ const generateAvailableIllustrationsArray = (fileNames, exclusionPatterns = []) => {
15
+ return JSON.stringify(
16
+ fileNames
17
+ .filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
18
+ .map((fileName) => fileName.replace(".js", ""))
19
+ );
20
+ };
21
+
22
+ const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, prefix = "") => {
23
+ return `import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
24
+
25
+ export const loadIllustration = async (illustrationName) => {
26
+ const collectionAndPrefix = "${collection}/${prefix}";
27
+ const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
28
+ switch (cleanIllustrationName) {
29
+ ${dynamicImports}
30
+ default:
31
+ throw new Error("[Illustrations] Illustration not found: " + illustrationName);
32
+ }
33
+ };
34
+
35
+ const loadAndCheck = async (illustrationName) => {
36
+ const data = await loadIllustration(illustrationName);
37
+ return data;
38
+ };
39
+
40
+ ${availableIllustrations}.forEach((illustrationName) =>
41
+ registerIllustrationLoader(\`${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
42
+ );
43
+ `;
44
+ };
45
+
46
+ const getMatchingFiles = async (folder, pattern) => {
47
+ const dir = await fs.readdir(folder);
48
+ return dir.filter((fileName) => fileName.match(pattern));
49
+ };
50
+
51
+ const generateIllustrations = async (config) => {
52
+ const { inputFolder, outputFile, collection, location, prefix, filterOut } = config;
53
+
54
+ const normalizedInputFolder = path.normalize(inputFolder);
55
+ const normalizedOutputFile = path.normalize(outputFile);
56
+
57
+ const illustrations = await getMatchingFiles(normalizedInputFolder, /^.*\.js$/);
58
+
59
+ const dynamicImports = generateDynamicImportLines(illustrations, location, filterOut);
60
+ const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
61
+
62
+ const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, prefix);
63
+
64
+ await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
65
+ await fs.writeFile(normalizedOutputFile, contentDynamic);
66
+
67
+ console.log(`Generated ${normalizedOutputFile}`);
68
+ };
69
+
70
+ // Parse configuration from command-line arguments
71
+ const config = {
72
+ inputFolder: process.argv[2],
73
+ 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),
78
+ };
79
+
80
+ // Run the generation process
81
+ generateIllustrations(config).catch((error) => {
82
+ console.error("Error generating illustrations:", error);
83
+ });