@ui5/webcomponents-tools 0.0.0-918b4fbe7 → 0.0.0-9261ac932

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 (69) hide show
  1. package/CHANGELOG.md +1305 -0
  2. package/README.md +3 -5
  3. package/assets-meta.js +15 -10
  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 +61 -15
  10. package/components-package/nps.js +68 -49
  11. package/components-package/postcss.components.js +1 -21
  12. package/components-package/postcss.themes.js +1 -26
  13. package/components-package/vite.config.js +6 -5
  14. package/components-package/wdio.js +42 -13
  15. package/icons-collection/nps.js +13 -8
  16. package/lib/amd-to-es6/index.js +102 -0
  17. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  18. package/lib/cem/custom-elements-manifest.config.mjs +527 -0
  19. package/lib/cem/event.mjs +148 -0
  20. package/lib/cem/schema-internal.json +1413 -0
  21. package/lib/cem/schema.json +1098 -0
  22. package/lib/cem/types-internal.d.ts +808 -0
  23. package/lib/cem/types.d.ts +736 -0
  24. package/lib/cem/utils.mjs +398 -0
  25. package/lib/cem/validate.js +70 -0
  26. package/lib/copy-list/index.js +2 -2
  27. package/lib/create-icons/index.js +38 -13
  28. package/lib/create-illustrations/index.js +51 -30
  29. package/lib/create-new-component/index.js +59 -101
  30. package/lib/create-new-component/tsFileContentTemplate.js +71 -0
  31. package/lib/css-processors/css-processor-components.mjs +77 -0
  32. package/lib/css-processors/css-processor-themes.mjs +79 -0
  33. package/lib/css-processors/scope-variables.mjs +49 -0
  34. package/lib/css-processors/shared.mjs +76 -0
  35. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  36. package/lib/dev-server/{dev-server.js → dev-server.mjs} +4 -4
  37. package/lib/dev-server/virtual-index-html-plugin.js +2 -2
  38. package/lib/generate-js-imports/illustrations.js +78 -64
  39. package/lib/generate-json-imports/i18n.js +45 -61
  40. package/lib/generate-json-imports/themes.js +16 -33
  41. package/lib/hbs2lit/src/compiler.js +9 -6
  42. package/lib/hbs2lit/src/litVisitor2.js +42 -17
  43. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  44. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
  45. package/lib/hbs2ui5/index.js +23 -6
  46. package/lib/i18n/defaults.js +11 -3
  47. package/lib/i18n/toJSON.js +1 -1
  48. package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
  49. package/lib/remove-dev-mode/remove-dev-mode.mjs +37 -0
  50. package/lib/scoping/get-all-tags.js +10 -3
  51. package/lib/scoping/lint-src.js +8 -7
  52. package/lib/scoping/scope-test-pages.js +2 -1
  53. package/lib/test-runner/test-runner.js +10 -2
  54. package/package.json +26 -12
  55. package/tsconfig.json +16 -0
  56. package/types/index.d.ts +1 -0
  57. package/components-package/wdio.sync.js +0 -360
  58. package/lib/esm-abs-to-rel/index.js +0 -58
  59. package/lib/generate-custom-elements-manifest/index.js +0 -369
  60. package/lib/jsdoc/config.json +0 -29
  61. package/lib/jsdoc/configTypescript.json +0 -29
  62. package/lib/jsdoc/plugin.js +0 -2468
  63. package/lib/jsdoc/preprocess.js +0 -60
  64. package/lib/jsdoc/template/publish.js +0 -4120
  65. package/lib/postcss-css-to-esm/index.js +0 -57
  66. package/lib/postcss-css-to-json/index.js +0 -47
  67. package/lib/postcss-new-files/index.js +0 -36
  68. package/lib/postcss-p/postcss-p.mjs +0 -14
  69. package/lib/replace-global-core/index.js +0 -25
@@ -0,0 +1,398 @@
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
+ const packageName = Object.keys(packageJSON?.dependencies || {}).find(
160
+ (dependency) =>
161
+ currentModuleSpecifier?.text?.startsWith(dependency)
162
+ );
163
+ return currentModuleSpecifier?.text
164
+ ?.replace(`${packageName}/`, "") || undefined;
165
+ }
166
+ }
167
+ };
168
+
169
+
170
+ const isClass = text => {
171
+ return text.includes("@abstract") || text.includes("@class") || text.includes("@constructor");
172
+ };
173
+
174
+ const normalizeTagType = (type) => {
175
+ return type?.trim();
176
+ }
177
+
178
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
179
+
180
+ const getReference = (ts, type, classNode, modulePath) => {
181
+ let sourceFile = classNode.parent;
182
+
183
+ while (sourceFile && sourceFile.kind !== ts.SyntaxKind.SourceFile) {
184
+ sourceFile = sourceFile.parent;
185
+ }
186
+
187
+ const typeName =
188
+ typeof type === "string"
189
+ ? normalizeTagType(type)
190
+ : type.class?.expression?.text ||
191
+ type.typeExpression?.type?.getText() ||
192
+ type.typeExpression?.type?.elementType?.typeName?.text;
193
+ const packageName = findPackageName(ts, sourceFile, typeName);
194
+ const importPath = findImportPath(
195
+ ts,
196
+ sourceFile,
197
+ typeName,
198
+ modulePath
199
+ )?.replace(`${packageName}/`, "");
200
+
201
+ return packageName && {
202
+ name: typeName,
203
+ package: packageName,
204
+ module: importPath,
205
+ };
206
+ };
207
+
208
+ const getType = (type) => {
209
+ const typeName = typeof type === "string" ? normalizeTagType(type) : type?.type;
210
+
211
+ const multiple =
212
+ typeName?.endsWith("[]") || typeName?.startsWith("Array<");
213
+ const name = multiple
214
+ ? typeName?.replace("[]", "")?.replace("Array<", "")?.replace(">", "")
215
+ : typeName;
216
+
217
+ return typeName ? { typeName: multiple ? `Array<${name}>` : typeName, name, multiple } : undefined;
218
+ };
219
+
220
+ const commonTags = ["public", "protected", "private", "since", "deprecated"];
221
+
222
+ const allowedTags = {
223
+ field: [...commonTags, "formEvents", "formProperty", "default"],
224
+ slot: [...commonTags, "default"],
225
+ event: [...commonTags, "param", "native", "allowPreventDefault"],
226
+ eventParam: [...commonTags],
227
+ method: [...commonTags, "param", "returns", "override"],
228
+ class: [...commonTags, "constructor", "class", "abstract", "experimental", "implements", "extends", "slot", "csspart"],
229
+ enum: [...commonTags],
230
+ enumMember: [...commonTags, "experimental",],
231
+ interface: [...commonTags, "experimental",],
232
+ };
233
+ allowedTags.getter = [...allowedTags.field, "override"]
234
+
235
+ const tagMatchCallback = (tag, tagName) => {
236
+ const currentTagName = tag.tag;
237
+
238
+ return typeof tagName === "string"
239
+ ? currentTagName === tagName
240
+ : tagName.includes(currentTagName);
241
+ };
242
+
243
+ const findDecorator = (node, decoratorName) => {
244
+ return node?.decorators?.find(
245
+ (decorator) =>
246
+ decorator?.expression?.expression?.text === decoratorName
247
+ );
248
+ };
249
+
250
+ const findAllDecorators = (node, decoratorName) => {
251
+ return (
252
+ node?.decorators?.filter(
253
+ (decorator) =>
254
+ decorator?.expression?.expression?.text === decoratorName
255
+ ) || []
256
+ );
257
+ };
258
+
259
+ const hasTag = (jsDoc, tagName) => {
260
+ if (!jsDoc) {
261
+ return;
262
+ }
263
+
264
+ return jsDoc?.tags?.some((tag) => tagMatchCallback(tag, tagName));
265
+ };
266
+
267
+ const findTag = (jsDoc, tagName) => {
268
+ if (!jsDoc) {
269
+ return;
270
+ }
271
+
272
+ return jsDoc?.tags?.find((tag) => tagMatchCallback(tag, tagName));
273
+ };
274
+
275
+ const findAllTags = (jsDoc, tagName) => {
276
+ if (!jsDoc) {
277
+ return [];
278
+ }
279
+
280
+ const foundTags = jsDoc?.tags?.filter((tag) => tagMatchCallback(tag, tagName));
281
+
282
+ return foundTags || [];
283
+ };
284
+
285
+ const validateJSDocTag = (tag) => {
286
+ const booleanTags = ["private", "protected", "public", "abstract", "native", "allowPreventDefault", "formProperty", "constructor", "override"];
287
+ let tagName = tag.tag;
288
+
289
+ if (booleanTags.includes(tag.tag)) {
290
+ tagName = "boolean";
291
+ }
292
+
293
+ switch (tagName) {
294
+ case "boolean":
295
+ return !tag.name && !tag.type && !tag.description;
296
+ case "deprecated":
297
+ return !tag.type;
298
+ case "experimental":
299
+ return !tag.type;
300
+ case "extends":
301
+ return !tag.type && tag.name && !tag.description;
302
+ case "implements":
303
+ return tag.type && !tag.name && !tag.description;
304
+ case "slot":
305
+ return tag.type && tag.name && tag.description;
306
+ case "csspart":
307
+ return !tag.type && tag.name && tag.description;
308
+ case "since":
309
+ return !tag.type && tag.name;
310
+ case "returns":
311
+ return !tag.type && tag.name;
312
+ case "default":
313
+ return !tag.type && !tag.description;
314
+ case "class":
315
+ return !tag.type;
316
+ case "param":
317
+ return !tag.type && tag.name;
318
+ case "eventparam":
319
+ return tag.type && tag.name;
320
+ case "formEvents":
321
+ return !tag.type && tag.name;
322
+ default:
323
+ return false;
324
+ }
325
+ };
326
+
327
+ const validateJSDocComment = (fieldType, jsdocComment, node, moduleDoc) => {
328
+ return !!jsdocComment?.tags?.every((tag) => {
329
+ let isValid = false
330
+
331
+ if (fieldType === "event" && tag?.tag === "param") {
332
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag({...tag, tag: "eventparam"});
333
+ } else {
334
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag(tag);
335
+ }
336
+
337
+ if (!isValid) {
338
+ logDocumentationError(moduleDoc.path, `Incorrect use of @${tag.tag}. Ensure it is part of ${fieldType} JSDoc tags.`)
339
+ }
340
+
341
+ return !!isValid;
342
+ });
343
+ };
344
+
345
+ const logDocumentationError = (modulePath, message) => {
346
+ let moduleErrors = documentationErrors.get(modulePath);
347
+
348
+ if (!moduleErrors) {
349
+ documentationErrors.set(modulePath, []);
350
+ moduleErrors = documentationErrors.get(modulePath);
351
+ }
352
+
353
+ moduleErrors.push(message);
354
+ }
355
+
356
+ const displayDocumentationErrors = () => {
357
+ let errorsCount = 0;
358
+ [...documentationErrors.keys()].forEach(modulePath => {
359
+ const moduleErrors = documentationErrors.get(modulePath);
360
+
361
+ console.log(`=== ERROR: ${moduleErrors.length > 1 ? `${moduleErrors.length} problems` : "Problem"} found in file: ${modulePath}:`)
362
+ moduleErrors.forEach(moduleError => {
363
+ errorsCount++;
364
+ console.log(`\t- ${moduleError}`)
365
+ })
366
+ })
367
+
368
+ if(errorsCount) {
369
+ throw new Error(`Found ${errorsCount} errors in the description of the public API.`);
370
+ }
371
+ }
372
+
373
+ const formatArrays = (typeText) => {
374
+ return typeText?.replaceAll(/(\S+)\[\]/g, "Array<$1>")
375
+ }
376
+
377
+ export {
378
+ getPrivacyStatus,
379
+ getSinceStatus,
380
+ getDeprecatedStatus,
381
+ getExperimentalStatus,
382
+ getType,
383
+ getReference,
384
+ validateJSDocComment,
385
+ findDecorator,
386
+ findAllDecorators,
387
+ hasTag,
388
+ findTag,
389
+ findAllTags,
390
+ getTypeRefs,
391
+ normalizeDescription,
392
+ formatArrays,
393
+ isClass,
394
+ normalizeTagType,
395
+ displayDocumentationErrors,
396
+ logDocumentationError,
397
+ toKebabCase
398
+ };
@@ -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
+ }
@@ -3,7 +3,7 @@ const path = require("path");
3
3
 
4
4
  const fileList = process.argv[2];
5
5
  const dest = process.argv[3];
6
- const src = "../../node_modules/@openui5/sap.ui.core/src/";
6
+ const src = "@openui5/sap.ui.core/src/";
7
7
 
8
8
  const generate = async () => {
9
9
  const filesToCopy = (await fs.readFile(fileList)).toString();
@@ -15,7 +15,7 @@ const generate = async () => {
15
15
  const trimFile = file => file.trim();
16
16
 
17
17
  return filesToCopy.split("\n").map(trimFile).filter(shouldCopy).map(async moduleName => {
18
- const srcPath = path.join(src, moduleName);
18
+ const srcPath = require.resolve(path.join(src, moduleName), {paths: [process.cwd()]});
19
19
  const destPath = path.join(dest, moduleName);
20
20
 
21
21
  await fs.mkdir(path.dirname(destPath), { recursive: true });
@@ -1,7 +1,7 @@
1
1
  const fs = require("fs").promises;
2
2
  const path = require("path");
3
3
 
4
- const collectionName = process.argv[2] || "SAP-icons";
4
+ const collectionName = process.argv[2] || "SAP-icons-v4";
5
5
  const collectionVersion = process.argv[3];
6
6
  const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
7
7
  const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
@@ -38,14 +38,16 @@ export { pathData, ltr, accData };`;
38
38
 
39
39
 
40
40
 
41
- const collectionTemplate = (name) => `import { isThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
42
- import {pathData as pathDataV5, ltr, accData} from "./v5/${name}.js";
43
- import {pathData as pathDataV4} from "./v4/${name}.js";
41
+ const collectionTemplate = (name, versions, fullName) => `import { isLegacyThemeFamilyAsync } from "@ui5/webcomponents-base/dist/config/Theme.js";
42
+ import { pathData as pathData${versions[0]}, ltr, accData } from "./${versions[0]}/${name}.js";
43
+ import { pathData as pathData${versions[1]} } from "./${versions[1]}/${name}.js";
44
44
 
45
- const pathData = isThemeFamily("sap_horizon") ? pathDataV5 : pathDataV4;
45
+ const getPathData = async() => {
46
+ return await isLegacyThemeFamilyAsync() ? pathDatav4 : pathDatav5;
47
+ };
46
48
 
47
- export default "${name}";
48
- export { pathData, ltr, accData };`;
49
+ export default "${fullName}";
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">
@@ -80,22 +82,45 @@ const createIcons = async (file) => {
80
82
  const pathData = iconData.path;
81
83
  const ltr = !!iconData.ltr;
82
84
  const acc = iconData.acc;
85
+ const packageName = json.packageName;
86
+ const collection = json.collection;
83
87
 
84
- const content = acc ? iconAccTemplate(name, pathData, ltr, acc, json.collection, json.packageName) : iconTemplate(name, pathData, ltr, json.collection, json.packageName);
88
+ const content = acc ? iconAccTemplate(name, pathData, ltr, acc, collection, packageName) : iconTemplate(name, pathData, ltr, collection, packageName);
85
89
 
86
90
  promises.push(fs.writeFile(path.join(destDir, `${name}.js`), content));
87
91
  promises.push(fs.writeFile(path.join(destDir, `${name}.svg`), svgTemplate(pathData)));
88
- promises.push(fs.writeFile(path.join(destDir, `${name}.d.ts`), typeDefinitionTemplate(name, acc, json.collection)));
92
+ promises.push(fs.writeFile(path.join(destDir, `${name}.d.ts`), typeDefinitionTemplate(name, acc, collection)));
93
+
94
+ // For versioned icons collections, the script creates top level (unversioned) module that internally imports the versioned ones.
95
+ // For example, the top level "@ui5/ui5-webcomponents-icons/dist/accept.js" imports:
96
+ // - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
97
+ // - "@ui5/ui5-webcomponents-icons/dist/v4/accept.js"
89
98
 
90
99
  if (json.version) {
91
- promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name)));
92
- promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.d.ts`), collectionTypeDefinitionTemplate(name, acc)));
100
+ // The exported value from the top level (unversioned) icon module depends on whether the collection is the default,
101
+ // to add or not the collection name to the exported value:
102
+ // For the default collection (SAPIcons) we export just the icon name - "export default { 'accept' }"
103
+ // For non-default collections (SAPTNTIcons and SAPBSIcons) we export the full name - "export default { 'tnt/actor' }"
104
+ const effectiveName = isDefaultCollection(collection) ? name : getUnversionedFullIconName(name, collection);
105
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name, json.versions, effectiveName)));
106
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.d.ts`), collectionTypeDefinitionTemplate(effectiveName, acc)));
93
107
  }
94
108
  }
95
109
 
96
110
  return Promise.all(promises);
97
111
  };
98
112
 
113
+ const isDefaultCollection = collectionName => collectionName === "SAP-icons-v4" || collectionName === "SAP-icons-v5";
114
+ const getUnversionedFullIconName = (name, collection) => `${getUnversionedCollectionName(collection)}/${name}`;
115
+ const getUnversionedCollectionName = collectionName => CollectionVersionedToUnversionedMap[collectionName] || collectionName;
116
+
117
+ const CollectionVersionedToUnversionedMap = {
118
+ "tnt-v2": "tnt",
119
+ "tnt-v3": "tnt",
120
+ "business-suite-v1": "business-suite",
121
+ "business-suite-v2": "business-suite",
122
+ };
123
+
99
124
  createIcons(srcFile).then(() => {
100
125
  console.log("Icons created.");
101
126
  });