@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
@@ -0,0 +1,408 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ let documentationErrors = new Map();
5
+
6
+ const getDeprecatedStatus = (jsdocComment) => {
7
+ const deprecatedTag = findTag(jsdocComment, "deprecated");
8
+ return deprecatedTag?.name
9
+ ? deprecatedTag.description
10
+ ? `${deprecatedTag.name} ${deprecatedTag.description}`
11
+ : deprecatedTag.name
12
+ : deprecatedTag
13
+ ? true
14
+ : undefined;
15
+ };
16
+
17
+ const getExperimentalStatus = (jsdocComment) => {
18
+ const experimentalTag = findTag(jsdocComment, "experimental");
19
+ return experimentalTag?.name
20
+ ? experimentalTag.description
21
+ ? `${experimentalTag.name} ${experimentalTag.description}`
22
+ : experimentalTag.name
23
+ : experimentalTag
24
+ ? true
25
+ : undefined;
26
+ };
27
+
28
+ const toKebabCase = str => {
29
+ return str.replaceAll(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase())
30
+ }
31
+
32
+ const normalizeDescription = (description) => {
33
+ return typeof description === 'string' ? description.replaceAll(/^-\s+|^(\n)+|(\n)+$/g, ""): description;
34
+ }
35
+
36
+ const getTypeRefs = (ts, node, member) => {
37
+ const extractTypeRefs = (type) => {
38
+ if (type?.kind === ts.SyntaxKind.TypeReference) {
39
+ return type.typeArguments?.length
40
+ ? type.typeArguments.map((typeRef) => typeRef.typeName?.text)
41
+ : [type.typeName?.text];
42
+ } else if (type?.kind === ts.SyntaxKind.ArrayType) {
43
+ return [type.elementType?.typeName?.text];
44
+ } else if (type?.kind === ts.SyntaxKind.UnionType) {
45
+ return type.types
46
+ .map((type) => extractTypeRefs(type))
47
+ .flat(1);
48
+ } else if (type?.kind === ts.SyntaxKind.TemplateLiteralType) {
49
+ if (member?.type) {
50
+ member.type.text = member.type.text.replaceAll?.(/`|\${|}/g, "");
51
+ }
52
+
53
+ return type.templateSpans?.length
54
+ ? type.templateSpans.map((typeRef) => typeRef.type?.typeName?.text)
55
+ : [type.typeName?.text];
56
+ }
57
+ };
58
+
59
+ let typeRefs = extractTypeRefs(node.type) || node?.typeArguments?.map(n => extractTypeRefs(n)).flat(2);
60
+
61
+ if (typeRefs) {
62
+ typeRefs = typeRefs.filter((e) => !!e);
63
+ }
64
+
65
+ return typeRefs?.length ? typeRefs : undefined;
66
+ };
67
+
68
+ const getSinceStatus = (jsdocComment) => {
69
+ const sinceTag = findTag(jsdocComment, "since");
70
+ return sinceTag
71
+ ? sinceTag.description
72
+ ? `${sinceTag.name} ${sinceTag.description}`
73
+ : sinceTag.name
74
+ : undefined;
75
+ };
76
+
77
+ const getPrivacyStatus = (jsdocComment) => {
78
+ const privacyTag = findTag(jsdocComment, ["public", "private", "protected"]);
79
+ return privacyTag?.tag || "private";
80
+ };
81
+
82
+ const findPackageName = (ts, sourceFile, typeName) => {
83
+ const localStatements = [
84
+ ts.SyntaxKind.EnumDeclaration,
85
+ ts.SyntaxKind.InterfaceDeclaration,
86
+ ts.SyntaxKind.ClassDeclaration,
87
+ ts.SyntaxKind.TypeAliasDeclaration,
88
+ ];
89
+
90
+ const isLocalDeclared = sourceFile.statements.some(
91
+ (statement) =>
92
+ localStatements.includes(statement.kind) && statement?.name?.text === typeName
93
+ );
94
+
95
+ if (isLocalDeclared) {
96
+ return packageJSON?.name;
97
+ } else {
98
+ const importStatements = sourceFile.statements?.filter(
99
+ (statement) => statement.kind === ts.SyntaxKind.ImportDeclaration
100
+ );
101
+ const currentModuleSpecifier = importStatements.find((statement) => {
102
+ if (statement.importClause?.name?.text === typeName) {
103
+ return true;
104
+ }
105
+
106
+ return statement.importClause?.namedBindings?.elements?.some(
107
+ (element) => element.name?.text === typeName
108
+ );
109
+ })?.moduleSpecifier;
110
+
111
+ if (currentModuleSpecifier?.text?.startsWith(".")) {
112
+ return packageJSON?.name;
113
+ } else {
114
+ return Object.keys(packageJSON?.dependencies || {}).find(
115
+ (dependency) =>
116
+ currentModuleSpecifier?.text?.startsWith(`${dependency}/`)
117
+ );
118
+ }
119
+ }
120
+ };
121
+
122
+ const findImportPath = (ts, sourceFile, typeName, modulePath) => {
123
+ const localStatements = [
124
+ ts.SyntaxKind.EnumDeclaration,
125
+ ts.SyntaxKind.InterfaceDeclaration,
126
+ ts.SyntaxKind.ClassDeclaration,
127
+ ts.SyntaxKind.TypeAliasDeclaration,
128
+ ];
129
+
130
+ const isLocalDeclared = sourceFile.statements.some(
131
+ (statement) =>
132
+ localStatements.includes(statement.kind) && statement?.name?.text === typeName
133
+ );
134
+
135
+ if (isLocalDeclared) {
136
+ return (
137
+ modulePath?.replace("src", "dist")?.replace(".ts", ".js") || undefined
138
+ );
139
+ } else {
140
+ const importStatements = sourceFile.statements?.filter(
141
+ (statement) => statement.kind === ts.SyntaxKind.ImportDeclaration
142
+ );
143
+ const currentModuleSpecifier = importStatements.find((statement) => {
144
+ if (statement.importClause?.name?.text === typeName) {
145
+ return true;
146
+ }
147
+
148
+ return statement.importClause?.namedBindings?.elements?.some(
149
+ (element) => element.name?.text === typeName
150
+ );
151
+ })?.moduleSpecifier;
152
+
153
+ if (currentModuleSpecifier?.text?.startsWith(".")) {
154
+ return (
155
+ path.join(path.dirname(modulePath), currentModuleSpecifier.text)
156
+ ?.replace("src", "dist")?.replace(".ts", ".js") || undefined
157
+ );
158
+ } else {
159
+ // my-package/test
160
+ // my-package
161
+ // @scope/my-package
162
+ // my.package
163
+ // _mypackage
164
+ // mypackage-
165
+ // scope/my-package/test
166
+ // @scope/my-package/test
167
+ const match = currentModuleSpecifier?.text.match(/^((@([a-z0-9._-]+)\/)?([a-z0-9._-]+))/);
168
+ let packageName;
169
+
170
+ if (match) {
171
+ packageName = match[1];
172
+ }
173
+
174
+ return packageName || undefined;
175
+ }
176
+ }
177
+ };
178
+
179
+
180
+ const isClass = text => {
181
+ return text.includes("@abstract") || text.includes("@class") || text.includes("@constructor");
182
+ };
183
+
184
+ const normalizeTagType = (type) => {
185
+ return type?.trim();
186
+ }
187
+
188
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
189
+
190
+ const getReference = (ts, type, classNode, modulePath) => {
191
+ let sourceFile = classNode.parent;
192
+
193
+ while (sourceFile && sourceFile.kind !== ts.SyntaxKind.SourceFile) {
194
+ sourceFile = sourceFile.parent;
195
+ }
196
+
197
+ const typeName =
198
+ typeof type === "string"
199
+ ? normalizeTagType(type)
200
+ : type.class?.expression?.text ||
201
+ type.typeExpression?.type?.getText() ||
202
+ type.typeExpression?.type?.elementType?.typeName?.text;
203
+ const packageName = findPackageName(ts, sourceFile, typeName);
204
+ const importPath = findImportPath(
205
+ ts,
206
+ sourceFile,
207
+ typeName,
208
+ modulePath
209
+ )?.replace(`${packageName}/`, "");
210
+
211
+ return packageName && {
212
+ name: typeName,
213
+ package: packageName,
214
+ module: importPath,
215
+ };
216
+ };
217
+
218
+ const getType = (type) => {
219
+ const typeName = typeof type === "string" ? normalizeTagType(type) : type?.type;
220
+
221
+ const multiple =
222
+ typeName?.endsWith("[]") || typeName?.startsWith("Array<");
223
+ const name = multiple
224
+ ? typeName?.replace("[]", "")?.replace("Array<", "")?.replace(">", "")
225
+ : typeName;
226
+
227
+ return typeName ? { typeName: multiple ? `Array<${name}>` : typeName, name, multiple } : undefined;
228
+ };
229
+
230
+ const commonTags = ["public", "protected", "private", "since", "deprecated"];
231
+
232
+ const allowedTags = {
233
+ field: [...commonTags, "formEvents", "formProperty", "default"],
234
+ slot: [...commonTags, "default"],
235
+ event: [...commonTags, "param", "native", "allowPreventDefault"],
236
+ eventParam: [...commonTags],
237
+ method: [...commonTags, "param", "returns", "override"],
238
+ class: [...commonTags, "constructor", "class", "abstract", "experimental", "implements", "extends", "slot", "csspart"],
239
+ enum: [...commonTags],
240
+ enumMember: [...commonTags, "experimental",],
241
+ interface: [...commonTags, "experimental",],
242
+ };
243
+ allowedTags.getter = [...allowedTags.field, "override"]
244
+
245
+ const tagMatchCallback = (tag, tagName) => {
246
+ const currentTagName = tag.tag;
247
+
248
+ return typeof tagName === "string"
249
+ ? currentTagName === tagName
250
+ : tagName.includes(currentTagName);
251
+ };
252
+
253
+ const findDecorator = (node, decoratorName) => {
254
+ return node?.decorators?.find(
255
+ (decorator) =>
256
+ decorator?.expression?.expression?.text === decoratorName
257
+ );
258
+ };
259
+
260
+ const findAllDecorators = (node, decoratorName) => {
261
+ return (
262
+ node?.decorators?.filter(
263
+ (decorator) =>
264
+ decorator?.expression?.expression?.text === decoratorName
265
+ ) || []
266
+ );
267
+ };
268
+
269
+ const hasTag = (jsDoc, tagName) => {
270
+ if (!jsDoc) {
271
+ return;
272
+ }
273
+
274
+ return jsDoc?.tags?.some((tag) => tagMatchCallback(tag, tagName));
275
+ };
276
+
277
+ const findTag = (jsDoc, tagName) => {
278
+ if (!jsDoc) {
279
+ return;
280
+ }
281
+
282
+ return jsDoc?.tags?.find((tag) => tagMatchCallback(tag, tagName));
283
+ };
284
+
285
+ const findAllTags = (jsDoc, tagName) => {
286
+ if (!jsDoc) {
287
+ return [];
288
+ }
289
+
290
+ const foundTags = jsDoc?.tags?.filter((tag) => tagMatchCallback(tag, tagName));
291
+
292
+ return foundTags || [];
293
+ };
294
+
295
+ const validateJSDocTag = (tag) => {
296
+ const booleanTags = ["private", "protected", "public", "abstract", "native", "allowPreventDefault", "formProperty", "constructor", "override"];
297
+ let tagName = tag.tag;
298
+
299
+ if (booleanTags.includes(tag.tag)) {
300
+ tagName = "boolean";
301
+ }
302
+
303
+ switch (tagName) {
304
+ case "boolean":
305
+ return !tag.name && !tag.type && !tag.description;
306
+ case "deprecated":
307
+ return !tag.type;
308
+ case "experimental":
309
+ return !tag.type;
310
+ case "extends":
311
+ return !tag.type && tag.name && !tag.description;
312
+ case "implements":
313
+ return tag.type && !tag.name && !tag.description;
314
+ case "slot":
315
+ return tag.type && tag.name && tag.description;
316
+ case "csspart":
317
+ return !tag.type && tag.name && tag.description;
318
+ case "since":
319
+ return !tag.type && tag.name;
320
+ case "returns":
321
+ return !tag.type && tag.name;
322
+ case "default":
323
+ return !tag.type && !tag.description;
324
+ case "class":
325
+ return !tag.type;
326
+ case "param":
327
+ return !tag.type && tag.name;
328
+ case "eventparam":
329
+ return tag.type && tag.name;
330
+ case "formEvents":
331
+ return !tag.type && tag.name;
332
+ default:
333
+ return false;
334
+ }
335
+ };
336
+
337
+ const validateJSDocComment = (fieldType, jsdocComment, node, moduleDoc) => {
338
+ return !!jsdocComment?.tags?.every((tag) => {
339
+ let isValid = false
340
+
341
+ if (fieldType === "event" && tag?.tag === "param") {
342
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag({...tag, tag: "eventparam"});
343
+ } else {
344
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag(tag);
345
+ }
346
+
347
+ if (!isValid) {
348
+ logDocumentationError(moduleDoc.path, `Incorrect use of @${tag.tag}. Ensure it is part of ${fieldType} JSDoc tags.`)
349
+ }
350
+
351
+ return !!isValid;
352
+ });
353
+ };
354
+
355
+ const logDocumentationError = (modulePath, message) => {
356
+ let moduleErrors = documentationErrors.get(modulePath);
357
+
358
+ if (!moduleErrors) {
359
+ documentationErrors.set(modulePath, []);
360
+ moduleErrors = documentationErrors.get(modulePath);
361
+ }
362
+
363
+ moduleErrors.push(message);
364
+ }
365
+
366
+ const displayDocumentationErrors = () => {
367
+ let errorsCount = 0;
368
+ [...documentationErrors.keys()].forEach(modulePath => {
369
+ const moduleErrors = documentationErrors.get(modulePath);
370
+
371
+ console.log(`=== ERROR: ${moduleErrors.length > 1 ? `${moduleErrors.length} problems` : "Problem"} found in file: ${modulePath}:`)
372
+ moduleErrors.forEach(moduleError => {
373
+ errorsCount++;
374
+ console.log(`\t- ${moduleError}`)
375
+ })
376
+ })
377
+
378
+ if(errorsCount) {
379
+ throw new Error(`Found ${errorsCount} errors in the description of the public API.`);
380
+ }
381
+ }
382
+
383
+ const formatArrays = (typeText) => {
384
+ return typeText?.replaceAll(/(\S+)\[\]/g, "Array<$1>")
385
+ }
386
+
387
+ export {
388
+ getPrivacyStatus,
389
+ getSinceStatus,
390
+ getDeprecatedStatus,
391
+ getExperimentalStatus,
392
+ getType,
393
+ getReference,
394
+ validateJSDocComment,
395
+ findDecorator,
396
+ findAllDecorators,
397
+ hasTag,
398
+ findTag,
399
+ findAllTags,
400
+ getTypeRefs,
401
+ normalizeDescription,
402
+ formatArrays,
403
+ isClass,
404
+ normalizeTagType,
405
+ displayDocumentationErrors,
406
+ logDocumentationError,
407
+ toKebabCase
408
+ };
@@ -0,0 +1,70 @@
1
+ const fs = require('fs');
2
+ const Ajv = require('ajv');
3
+ const path = require('path');
4
+ const yargs = require('yargs/yargs')
5
+ const { hideBin } = require('yargs/helpers')
6
+ const argv = yargs(hideBin(process.argv))
7
+ .argv;
8
+
9
+ // Load your JSON schema
10
+ const extenalSchema = require('./schema.json');
11
+ const internalSchema = require('./schema-internal.json');
12
+
13
+ // Load your JSON data from the input file
14
+ const inputFilePath = path.join(process.cwd(), "dist/custom-elements.json"); // Update with your file path
15
+ const customManifest = fs.readFileSync(inputFilePath, 'utf8');
16
+ const inputDataInternal = JSON.parse(customManifest);
17
+
18
+ inputDataInternal.modules.forEach(moduleDoc => {
19
+ moduleDoc.exports = moduleDoc.exports.
20
+ filter(e => moduleDoc.declarations.find(d => d.name === e.declaration.name && ["class", "function", "variable", "enum"].includes(d.kind)) || e.name === "default");
21
+ })
22
+
23
+ const clearProps = (data) => {
24
+ if (Array.isArray(data)) {
25
+ for (let i = 0; i < data.length; i++) {
26
+ if (typeof data[i] === "object") {
27
+ if (["enum", "interface"].includes(data[i].kind)) {
28
+ data.splice(i, 1);
29
+ i--;
30
+ } else {
31
+ clearProps(data[i]);
32
+ }
33
+ }
34
+ }
35
+ } else if (typeof data === "object") {
36
+ Object.keys(data).forEach(prop => {
37
+ if (prop.startsWith("_ui5")) {
38
+ delete data[prop];
39
+ } else if (typeof data[prop] === "object") {
40
+ clearProps(data[prop]);
41
+ }
42
+ });
43
+ }
44
+
45
+ return data;
46
+ }
47
+
48
+ const ajv = new Ajv({ allowUnionTypes: true, allError: true })
49
+ let validate = ajv.compile(internalSchema)
50
+
51
+ // Validate the JSON data against the schema
52
+ if (argv.dev) {
53
+ if (validate(inputDataInternal)) {
54
+ console.log('Internal custom element manifest is validated successfully');
55
+ } else {
56
+ throw new Error(`Validation of internal custom elements manifest failed: ${validate.errors}`);
57
+ }
58
+ }
59
+
60
+ const inputDataExternal = clearProps(JSON.parse(JSON.stringify(inputDataInternal)));
61
+ validate = ajv.compile(extenalSchema)
62
+
63
+ // Validate the JSON data against the schema
64
+ if (validate(inputDataExternal)) {
65
+ console.log('Custom element manifest is validated successfully');
66
+ fs.writeFileSync(inputFilePath, JSON.stringify(inputDataExternal, null, 2), 'utf8');
67
+ fs.writeFileSync(inputFilePath.replace("custom-elements", "custom-elements-internal"), JSON.stringify(inputDataInternal, null, 2), 'utf8');
68
+ } else if (argv.dev) {
69
+ throw new Error(`Validation of public custom elements manifest failed: ${validate.errors}`);
70
+ }
@@ -38,14 +38,16 @@ export { pathData, ltr, accData };`;
38
38
 
39
39
 
40
40
 
41
- const collectionTemplate = (name, versions, fullName) => `import { isLegacyThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
41
+ const collectionTemplate = (name, versions, fullName) => `import { isLegacyThemeFamilyAsync } from "@ui5/webcomponents-base/dist/config/Theme.js";
42
42
  import { pathData as pathData${versions[0]}, ltr, accData } from "./${versions[0]}/${name}.js";
43
43
  import { pathData as pathData${versions[1]} } from "./${versions[1]}/${name}.js";
44
44
 
45
- const pathData = isLegacyThemeFamily() ? pathData${versions[0]} : pathData${versions[1]};
45
+ const getPathData = async() => {
46
+ return await isLegacyThemeFamilyAsync() ? pathDatav4 : pathDatav5;
47
+ };
46
48
 
47
49
  export default "${fullName}";
48
- export { pathData, ltr, accData };`;
50
+ export { getPathData, ltr, accData };`;
49
51
 
50
52
 
51
53
  const typeDefinitionTemplate = (name, accData, collection) => `declare const pathData: string;
@@ -56,13 +58,13 @@ declare const _default: "${collection}/${name}";
56
58
  export default _default;
57
59
  export { pathData, ltr, accData };`
58
60
 
59
- const collectionTypeDefinitionTemplate = (name, accData) => `declare const pathData: string;
61
+ const collectionTypeDefinitionTemplate = (name, accData) => `declare const getPathData: () => Promise<string>;
60
62
  declare const ltr: boolean;
61
63
  declare const accData: ${accData ? '{ key: string; defaultText: string; }' : null}
62
64
  declare const _default: "${name}";
63
65
 
64
66
  export default _default;
65
- export { pathData, ltr, accData };`
67
+ export { getPathData, ltr, accData };`
66
68
 
67
69
 
68
70
  const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
@@ -91,7 +93,7 @@ const createIcons = async (file) => {
91
93
 
92
94
  // For versioned icons collections, the script creates top level (unversioned) module that internally imports the versioned ones.
93
95
  // For example, the top level "@ui5/ui5-webcomponents-icons/dist/accept.js" imports:
94
- // - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
96
+ // - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
95
97
  // - "@ui5/ui5-webcomponents-icons/dist/v4/accept.js"
96
98
 
97
99
  if (json.version) {
@@ -59,9 +59,11 @@ const generate = async () => {
59
59
  const destPath = process.argv[6];
60
60
  const collection = process.argv[7];
61
61
  const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
62
- // collect each illustration name because each one should have Sample.js file
62
+ // collect each illustration name because each one should have Sample.js file
63
63
  const fileNames = new Set();
64
64
 
65
+ let dotIllustrationNames = [];
66
+
65
67
  try {
66
68
  await fs.access(srcPath);
67
69
  } catch (error) {
@@ -75,10 +77,16 @@ const generate = async () => {
75
77
  return `export default \`${svgContent}\`;`
76
78
  };
77
79
  const svgToJs = async fileName => {
78
- const svg = await fs.readFile(path.join(srcPath, fileName), {encoding: "utf-8"});
80
+ const svg = await fs.readFile(path.join(srcPath, fileName), { encoding: "utf-8" });
79
81
  const fileContent = svgImportTemplate(svg);
82
+ const fileNameSplitArr = fileName.split('-');
80
83
  fileName = fileName.replace(/\.svg$/, ".js");
81
84
 
85
+ if (fileNameSplitArr[1] === 'Dot') {
86
+ // we keep the Dot illustration names to import them later. If no Dot is present, Spot will be used
87
+ dotIllustrationNames.push(fileNameSplitArr[2].split('.')[0]);
88
+ }
89
+
82
90
  return fs.writeFile(path.join(destPath, fileName), fileContent);
83
91
  };
84
92
  const illustrationImportTemplate = illustrationName => {
@@ -93,59 +101,54 @@ const generate = async () => {
93
101
  }
94
102
 
95
103
  const illustrationNameUpperCase = illustrationNameForTranslation.toUpperCase();
104
+ // If no Dot is present, Spot will be imported as Dot
105
+ const hasDot = dotIllustrationNames.indexOf(illustrationName) !== -1 ? 'Dot' : 'Spot';
96
106
 
97
- return defaultText ? `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
107
+ return `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
98
108
  import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
99
109
  import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
100
110
  import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
101
- import {
111
+ import dotSvg from "./${illustrationsPrefix}-${hasDot}-${illustrationName}.js";${
112
+ defaultText ? `import {
102
113
  IM_TITLE_${illustrationNameUpperCase},
103
114
  IM_SUBTITLE_${illustrationNameUpperCase},
104
- } from "../generated/i18n/i18n-defaults.js";
115
+ } from "../generated/i18n/i18n-defaults.js";` : ``}
105
116
 
106
117
  const name = "${illustrationName}";
107
118
  const set = "${illustrationSet}";
108
- const collection = "${collection}";
119
+ const collection = "${collection}";${defaultText ? `
109
120
  const title = IM_TITLE_${illustrationNameUpperCase};
110
- const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};
121
+ const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};` : ``}
111
122
 
112
123
  registerIllustration(name, {
113
124
  dialogSvg,
114
125
  sceneSvg,
115
126
  spotSvg,
127
+ dotSvg,${defaultText ? `
116
128
  title,
117
- subtitle,
129
+ subtitle,` : ``}
118
130
  set,
119
131
  collection,
120
132
  });
121
133
 
134
+ export default "${illustrationSet === "fiori" ? "" : `${illustrationSet}/`}${illustrationName}";
122
135
  export {
123
136
  dialogSvg,
124
137
  sceneSvg,
125
138
  spotSvg,
126
- };` :
127
- `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
128
- import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
129
- import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
130
- import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
131
-
132
- const name = "${illustrationName}";
133
- const set = "${illustrationSet}";
134
- const collection = "${collection}";
139
+ dotSvg,
140
+ };`
141
+ };
135
142
 
136
- registerIllustration(name, {
137
- dialogSvg,
138
- sceneSvg,
139
- spotSvg,
140
- set,
141
- collection,
142
- });
143
+ const illustrationTypeDefinition = illustrationName => {
144
+ return `declare const dialogSvg: string;
145
+ declare const sceneSvg: string;
146
+ declare const spotSvg: string;
147
+ declare const dotSvg: string;
148
+ declare const _default: "${illustrationSet === "fiori" ? "" : `${illustrationSet}/`}${illustrationName}";
143
149
 
144
- export {
145
- dialogSvg,
146
- sceneSvg,
147
- spotSvg,
148
- };`
150
+ export default _default;
151
+ export { dialogSvg, sceneSvg, spotSvg, dotSvg };`
149
152
  };
150
153
 
151
154
  await fs.mkdir(destPath, { recursive: true });
@@ -163,11 +166,15 @@ export {
163
166
  }
164
167
  });
165
168
 
166
- for (let illustrationName of fileNames) {
167
- promises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
168
- }
169
+ return Promise.all(promises).then(() => {
170
+ const nestedPromises = [];
171
+ for (let illustrationName of fileNames) {
172
+ nestedPromises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
173
+ nestedPromises.push(fs.writeFile(path.join(destPath, `${illustrationName}.d.ts`), illustrationTypeDefinition(illustrationName)));
174
+ }
169
175
 
170
- return Promise.all(promises);
176
+ return Promise.all(nestedPromises);
177
+ });
171
178
  };
172
179
 
173
180
  generate().then(() => {