@ui5/webcomponents-tools 0.0.0-f734ea2da → 0.0.0-f79db712b

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 (108) hide show
  1. package/CHANGELOG.md +808 -0
  2. package/README.md +6 -6
  3. package/assets-meta.js +18 -3
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +36 -0
  6. package/components-package/nps.js +108 -66
  7. package/components-package/postcss.components.js +1 -21
  8. package/components-package/postcss.themes.js +1 -23
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +405 -344
  11. package/components-package/wdio.sync.js +368 -0
  12. package/icons-collection/nps.js +51 -18
  13. package/lib/cem/custom-elements-manifest.config.mjs +499 -0
  14. package/lib/cem/event.mjs +135 -0
  15. package/lib/cem/schema-internal.json +1354 -0
  16. package/lib/cem/schema.json +1098 -0
  17. package/lib/cem/types-internal.d.ts +801 -0
  18. package/lib/cem/types.d.ts +736 -0
  19. package/lib/cem/utils.mjs +354 -0
  20. package/lib/cem/validate.js +67 -0
  21. package/lib/copy-and-watch/index.js +24 -1
  22. package/lib/copy-list/index.js +17 -17
  23. package/lib/create-icons/index.js +124 -58
  24. package/lib/create-illustrations/index.js +165 -0
  25. package/lib/create-new-component/index.js +72 -97
  26. package/lib/create-new-component/jsFileContentTemplate.js +73 -0
  27. package/lib/create-new-component/tsFileContentTemplate.js +71 -0
  28. package/lib/css-processors/css-processor-components.mjs +77 -0
  29. package/lib/css-processors/css-processor-themes.mjs +79 -0
  30. package/lib/css-processors/scope-variables.mjs +46 -0
  31. package/lib/css-processors/shared.mjs +76 -0
  32. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  33. package/lib/dev-server/dev-server.js +66 -0
  34. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  35. package/lib/esm-abs-to-rel/index.js +17 -10
  36. package/lib/generate-custom-elements-manifest/index.js +327 -0
  37. package/lib/generate-js-imports/illustrations.js +86 -0
  38. package/lib/generate-json-imports/i18n.js +43 -31
  39. package/lib/generate-json-imports/themes.js +36 -24
  40. package/lib/hbs2lit/src/compiler.js +24 -4
  41. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  42. package/lib/hbs2lit/src/litVisitor2.js +95 -24
  43. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  44. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +33 -11
  45. package/lib/hbs2ui5/index.js +56 -23
  46. package/lib/i18n/defaults.js +65 -57
  47. package/lib/i18n/toJSON.js +12 -11
  48. package/lib/jsdoc/configTypescript.json +29 -0
  49. package/lib/jsdoc/plugin.js +41 -0
  50. package/lib/jsdoc/preprocess.js +146 -0
  51. package/lib/jsdoc/template/publish.js +21 -2
  52. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  53. package/lib/replace-global-core/index.js +13 -8
  54. package/lib/scoping/get-all-tags.js +2 -9
  55. package/lib/scoping/lint-src.js +1 -1
  56. package/lib/scoping/missing-dependencies.js +65 -0
  57. package/lib/scoping/report-tags-usage.js +28 -0
  58. package/lib/scoping/scope-test-pages.js +2 -1
  59. package/lib/test-runner/test-runner.js +71 -0
  60. package/package.json +36 -38
  61. package/bin/init-ui5-package.js +0 -3
  62. package/components-package/rollup.js +0 -216
  63. package/lib/documentation/index.js +0 -165
  64. package/lib/documentation/templates/api-component-since.js +0 -3
  65. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  66. package/lib/documentation/templates/api-events-section.js +0 -35
  67. package/lib/documentation/templates/api-methods-section.js +0 -26
  68. package/lib/documentation/templates/api-properties-section.js +0 -40
  69. package/lib/documentation/templates/api-slots-section.js +0 -28
  70. package/lib/documentation/templates/template.js +0 -38
  71. package/lib/hash/config.js +0 -10
  72. package/lib/hash/generate.js +0 -19
  73. package/lib/hash/upToDate.js +0 -31
  74. package/lib/init-package/index.js +0 -136
  75. package/lib/init-package/resources/.eslintignore +0 -3
  76. package/lib/init-package/resources/bundle.es5.js +0 -25
  77. package/lib/init-package/resources/bundle.esm.js +0 -31
  78. package/lib/init-package/resources/config/.eslintrc.js +0 -1
  79. package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
  80. package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
  81. package/lib/init-package/resources/config/rollup.config.js +0 -1
  82. package/lib/init-package/resources/config/wdio.conf.js +0 -1
  83. package/lib/init-package/resources/package-scripts.js +0 -11
  84. package/lib/init-package/resources/src/Assets.js +0 -5
  85. package/lib/init-package/resources/src/MyFirstComponent.hbs +0 -1
  86. package/lib/init-package/resources/src/MyFirstComponent.js +0 -56
  87. package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
  88. package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
  89. package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
  90. package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
  91. package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
  92. package/lib/init-package/resources/src/themes/MyFirstComponent.css +0 -11
  93. package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
  94. package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
  95. package/lib/init-package/resources/src/themes/sap_belize_hcw/parameters-bundle.css +0 -3
  96. package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  97. package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
  98. package/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css +0 -3
  99. package/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css +0 -3
  100. package/lib/init-package/resources/test/pages/index.html +0 -56
  101. package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
  102. package/lib/polyfill-placeholder/index.js +0 -5
  103. package/lib/postcss-css-to-esm/index.js +0 -45
  104. package/lib/postcss-css-to-json/index.js +0 -31
  105. package/lib/postcss-new-files/index.js +0 -36
  106. package/lib/serve/index.js +0 -46
  107. package/lib/serve/serve.json +0 -3
  108. package/package-lock.json +0 -48
@@ -0,0 +1,354 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ let JSDocErrors = [];
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 normalizeDescription = (description) => {
18
+ return typeof description === 'string' ? description.replaceAll(/^-\s+|^(\n)+|(\n)+$/g, ""): description;
19
+ }
20
+
21
+ const getTypeRefs = (ts, node, member) => {
22
+ const extractTypeRefs = (type) => {
23
+ if (type?.kind === ts.SyntaxKind.TypeReference) {
24
+ return type.typeArguments?.length
25
+ ? type.typeArguments.map((typeRef) => typeRef.typeName?.text)
26
+ : [type.typeName?.text];
27
+ } else if (type?.kind === ts.SyntaxKind.UnionType) {
28
+ return type.types
29
+ .map((type) => extractTypeRefs(type))
30
+ .flat(1);
31
+ } else if (type?.kind === ts.SyntaxKind.TemplateLiteralType) {
32
+ if (member?.type) {
33
+ member.type.text = member.type.text.replaceAll?.(/`|\${|}/g, "");
34
+ }
35
+
36
+ return type.templateSpans?.length
37
+ ? type.templateSpans.map((typeRef) => typeRef.type?.typeName?.text)
38
+ : [type.typeName?.text];
39
+ }
40
+ };
41
+
42
+ let typeRefs = extractTypeRefs(node.type) || node?.typeArguments?.map(n => extractTypeRefs(n)).flat(2);
43
+
44
+ if (typeRefs) {
45
+ typeRefs = typeRefs.filter((e) => !!e);
46
+ }
47
+
48
+ return typeRefs?.length ? typeRefs : undefined;
49
+ };
50
+
51
+ const getSinceStatus = (jsdocComment) => {
52
+ const sinceTag = findTag(jsdocComment, "since");
53
+ return sinceTag
54
+ ? sinceTag.description
55
+ ? `${sinceTag.name} ${sinceTag.description}`
56
+ : sinceTag.name
57
+ : undefined;
58
+ };
59
+
60
+ const getPrivacyStatus = (jsdocComment) => {
61
+ const privacyTag = findTag(jsdocComment, ["public", "private", "protected"]);
62
+ return privacyTag?.tag || "private";
63
+ };
64
+
65
+ const findPackageName = (ts, sourceFile, typeName) => {
66
+ const localStatements = [
67
+ ts.SyntaxKind.EnumDeclaration,
68
+ ts.SyntaxKind.InterfaceDeclaration,
69
+ ts.SyntaxKind.ClassDeclaration,
70
+ ts.SyntaxKind.TypeAliasDeclaration,
71
+ ];
72
+
73
+ const isLocalDeclared = sourceFile.statements.some(
74
+ (statement) =>
75
+ localStatements.includes(statement.kind) && statement?.name?.text === typeName
76
+ );
77
+
78
+ if (isLocalDeclared) {
79
+ return packageJSON?.name;
80
+ } else {
81
+ const importStatements = sourceFile.statements?.filter(
82
+ (statement) => statement.kind === ts.SyntaxKind.ImportDeclaration
83
+ );
84
+ const currentModuleSpecifier = importStatements.find((statement) => {
85
+ if (statement.importClause?.name?.text === typeName) {
86
+ return true;
87
+ }
88
+
89
+ return statement.importClause?.namedBindings?.elements?.some(
90
+ (element) => element.name?.text === typeName
91
+ );
92
+ })?.moduleSpecifier;
93
+
94
+ if (currentModuleSpecifier?.text?.startsWith(".")) {
95
+ return packageJSON?.name;
96
+ } else {
97
+ return Object.keys(packageJSON?.dependencies || {}).find(
98
+ (dependency) =>
99
+ currentModuleSpecifier?.text?.startsWith(`${dependency}/`)
100
+ );
101
+ }
102
+ }
103
+ };
104
+
105
+ const findImportPath = (ts, sourceFile, typeName, modulePath) => {
106
+ const localStatements = [
107
+ ts.SyntaxKind.EnumDeclaration,
108
+ ts.SyntaxKind.InterfaceDeclaration,
109
+ ts.SyntaxKind.ClassDeclaration,
110
+ ts.SyntaxKind.TypeAliasDeclaration,
111
+ ];
112
+
113
+ const isLocalDeclared = sourceFile.statements.some(
114
+ (statement) =>
115
+ localStatements.includes(statement.kind) && statement?.name?.text === typeName
116
+ );
117
+
118
+ if (isLocalDeclared) {
119
+ return (
120
+ modulePath?.replace("src", "dist")?.replace(".ts", ".js") || undefined
121
+ );
122
+ } else {
123
+ const importStatements = sourceFile.statements?.filter(
124
+ (statement) => statement.kind === ts.SyntaxKind.ImportDeclaration
125
+ );
126
+ const currentModuleSpecifier = importStatements.find((statement) => {
127
+ if (statement.importClause?.name?.text === typeName) {
128
+ return true;
129
+ }
130
+
131
+ return statement.importClause?.namedBindings?.elements?.some(
132
+ (element) => element.name?.text === typeName
133
+ );
134
+ })?.moduleSpecifier;
135
+
136
+ if (currentModuleSpecifier?.text?.startsWith(".")) {
137
+ return (
138
+ path.join(path.dirname(modulePath), currentModuleSpecifier.text)
139
+ ?.replace("src", "dist")?.replace(".ts", ".js") || undefined
140
+ );
141
+ } else {
142
+ const packageName = Object.keys(packageJSON?.dependencies || {}).find(
143
+ (dependency) =>
144
+ currentModuleSpecifier?.text?.startsWith(dependency)
145
+ );
146
+ return currentModuleSpecifier?.text
147
+ ?.replace(`${packageName}/`, "") || undefined;
148
+ }
149
+ }
150
+ };
151
+
152
+
153
+ const isClass = text => {
154
+ return text.includes("@abstract") || text.includes("@class") || text.includes("@constructor");
155
+ };
156
+
157
+ const normalizeTagType = (type) => {
158
+ return type?.trim();
159
+ }
160
+
161
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
162
+
163
+ const getReference = (ts, type, classNode, modulePath) => {
164
+ let sourceFile = classNode.parent;
165
+
166
+ while (sourceFile && sourceFile.kind !== ts.SyntaxKind.SourceFile) {
167
+ sourceFile = sourceFile.parent;
168
+ }
169
+
170
+ const typeName =
171
+ typeof type === "string"
172
+ ? normalizeTagType(type)
173
+ : type.class?.expression?.text ||
174
+ type.typeExpression?.type?.getText() ||
175
+ type.typeExpression?.type?.elementType?.typeName?.text;
176
+ const packageName = findPackageName(ts, sourceFile, typeName);
177
+ const importPath = findImportPath(
178
+ ts,
179
+ sourceFile,
180
+ typeName,
181
+ modulePath
182
+ )?.replace(`${packageName}/`, "");
183
+
184
+ return packageName && {
185
+ name: typeName,
186
+ package: packageName,
187
+ module: importPath,
188
+ };
189
+ };
190
+
191
+ const getType = (type) => {
192
+ const typeName = typeof type === "string" ? normalizeTagType(type) : type?.type;
193
+
194
+ const multiple =
195
+ typeName?.endsWith("[]") || typeName?.startsWith("Array<");
196
+ const name = multiple
197
+ ? typeName?.replace("[]", "")?.replace("Array<", "")?.replace(">", "")
198
+ : typeName;
199
+
200
+ return typeName ? { typeName: multiple ? `Array<${name}>` : typeName, name, multiple } : undefined;
201
+ };
202
+
203
+ const commonTags = ["public", "protected", "private", "since", "deprecated"];
204
+
205
+ const allowedTags = {
206
+ field: [...commonTags, "formEvents", "formProperty", "default"],
207
+ slot: [...commonTags, "default"],
208
+ event: [...commonTags, "param", "allowPreventDefault", "native"],
209
+ eventParam: [...commonTags],
210
+ method: [...commonTags, "param", "returns", "override"],
211
+ class: [...commonTags, "constructor", "class", "abstract", "implements", "extends", "slot", "csspart"],
212
+ enum: [...commonTags],
213
+ enumMember: [...commonTags],
214
+ interface: [...commonTags],
215
+ };
216
+ allowedTags.getter = [...allowedTags.field, "override"]
217
+
218
+ const tagMatchCallback = (tag, tagName) => {
219
+ const currentTagName = tag.tag;
220
+
221
+ return typeof tagName === "string"
222
+ ? currentTagName === tagName
223
+ : tagName.includes(currentTagName);
224
+ };
225
+
226
+ const findDecorator = (node, decoratorName) => {
227
+ return node?.decorators?.find(
228
+ (decorator) =>
229
+ decorator?.expression?.expression?.text === decoratorName
230
+ );
231
+ };
232
+
233
+ const findAllDecorators = (node, decoratorName) => {
234
+ return (
235
+ node?.decorators?.filter(
236
+ (decorator) =>
237
+ decorator?.expression?.expression?.text === decoratorName
238
+ ) || []
239
+ );
240
+ };
241
+
242
+ const hasTag = (jsDoc, tagName) => {
243
+ if (!jsDoc) {
244
+ return;
245
+ }
246
+
247
+ return jsDoc?.tags?.some((tag) => tagMatchCallback(tag, tagName));
248
+ };
249
+
250
+ const findTag = (jsDoc, tagName) => {
251
+ if (!jsDoc) {
252
+ return;
253
+ }
254
+
255
+ return jsDoc?.tags?.find((tag) => tagMatchCallback(tag, tagName));
256
+ };
257
+
258
+ const findAllTags = (jsDoc, tagName) => {
259
+ if (!jsDoc) {
260
+ return [];
261
+ }
262
+
263
+ const foundTags = jsDoc?.tags?.filter((tag) => tagMatchCallback(tag, tagName));
264
+
265
+ return foundTags || [];
266
+ };
267
+
268
+ const validateJSDocTag = (tag) => {
269
+ const booleanTags = ["private", "protected", "public", "abstract", "allowPreventDefault", "native", "formProperty", "constructor", "override"];
270
+ let tagName = tag.tag;
271
+
272
+ if (booleanTags.includes(tag.tag)) {
273
+ tagName = "boolean";
274
+ }
275
+
276
+ switch (tagName) {
277
+ case "boolean":
278
+ return !tag.name && !tag.type && !tag.description;
279
+ case "deprecated":
280
+ return !tag.type;
281
+ case "extends":
282
+ return !tag.type && tag.name && !tag.description;
283
+ case "implements":
284
+ return tag.type && !tag.name && !tag.description;
285
+ case "slot":
286
+ return tag.type && tag.name && tag.description;
287
+ case "csspart":
288
+ return !tag.type && tag.name && tag.description;
289
+ case "since":
290
+ return !tag.type && tag.name;
291
+ case "returns":
292
+ return !tag.type && tag.name;
293
+ case "default":
294
+ return !tag.type && !tag.description;
295
+ case "class":
296
+ return !tag.type;
297
+ case "param":
298
+ return !tag.type && tag.name;
299
+ case "eventparam":
300
+ return tag.type && tag.name;
301
+ case "formEvents":
302
+ return !tag.type && tag.name;
303
+ default:
304
+ return false;
305
+ }
306
+ };
307
+
308
+ const validateJSDocComment = (fieldType, jsdocComment, node, moduleDoc) => {
309
+ return !!jsdocComment?.tags?.every((tag) => {
310
+ let isValid = false
311
+
312
+ if (fieldType === "event" && tag?.tag === "param") {
313
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag({...tag, tag: "eventparam"});
314
+ } else {
315
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag(tag);
316
+ }
317
+
318
+ if (!isValid) {
319
+ JSDocErrors.push(
320
+ `=== ERROR: Problem found with ${node}'s JSDoc comment in ${moduleDoc.path}: \n\t- @${tag.tag} tag is being used wrong or it's not part of ${fieldType} JSDoc tags`
321
+ );
322
+ }
323
+
324
+ return !!isValid;
325
+ });
326
+ };
327
+
328
+ const getJSDocErrors = () => {
329
+ return JSDocErrors;
330
+ };
331
+
332
+ const formatArrays = (typeText) => {
333
+ return typeText.replaceAll(/(\S+)\[\]/g, "Array<$1>")
334
+ }
335
+
336
+ export {
337
+ getPrivacyStatus,
338
+ getSinceStatus,
339
+ getDeprecatedStatus,
340
+ getType,
341
+ getReference,
342
+ validateJSDocComment,
343
+ findDecorator,
344
+ findAllDecorators,
345
+ hasTag,
346
+ findTag,
347
+ findAllTags,
348
+ getJSDocErrors,
349
+ getTypeRefs,
350
+ normalizeDescription,
351
+ formatArrays,
352
+ isClass,
353
+ normalizeTagType
354
+ };
@@ -0,0 +1,67 @@
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
+ const clearProps = (data) => {
19
+ if (Array.isArray(data)) {
20
+ for (let i = 0; i < data.length; i++) {
21
+ if (typeof data[i] === "object") {
22
+ if (["enum", "interface"].includes(data[i].kind)) {
23
+ data.splice(i, 1);
24
+ i--;
25
+ } else {
26
+ clearProps(data[i]);
27
+ }
28
+ }
29
+ }
30
+ } else if (typeof data === "object") {
31
+ Object.keys(data).forEach(prop => {
32
+ if (prop.startsWith("_ui5")) {
33
+ delete data[prop];
34
+ } else if (typeof data[prop] === "object") {
35
+ clearProps(data[prop]);
36
+ }
37
+ });
38
+ }
39
+
40
+ return data;
41
+ }
42
+
43
+ const ajv = new Ajv({ allowUnionTypes: true, allError: true })
44
+ let validate = ajv.compile(internalSchema)
45
+
46
+ // Validate the JSON data against the schema
47
+ if (argv.dev) {
48
+ if (validate(inputDataInternal)) {
49
+ console.log('Internal custom element manifest is validated successfully');
50
+ } else {
51
+ throw new Error(`Validation of internal custom elements manifest failed: ${validate.errors}`);
52
+ }
53
+ }
54
+
55
+ const inputDataExternal = clearProps(JSON.parse(JSON.stringify(inputDataInternal)));
56
+ validate = ajv.compile(extenalSchema)
57
+
58
+ // Validate the JSON data against the schema
59
+ if (validate(inputDataExternal)) {
60
+ console.log('Custom element manifest is validated successfully');
61
+ fs.writeFileSync(inputFilePath, JSON.stringify(inputDataExternal, null, 2), 'utf8');
62
+ fs.writeFileSync(inputFilePath.replace("custom-elements", "custom-elements-internal"), JSON.stringify(inputDataInternal, null, 2), 'utf8');
63
+ } else {
64
+ if (argv.dev) {
65
+ throw new Error(`Validation of public custom elements manifest failed: ${validate.errors}`);
66
+ }
67
+ }
@@ -1,9 +1,32 @@
1
+ /*
2
+ MIT License
3
+
4
+ Copyright (c) 2017
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
1
25
  const fs = require('fs');
2
26
  const path = require('path');
3
27
  const chokidar = require('chokidar');
4
28
  const glob = require('glob');
5
29
  const globParent = require('glob-parent');
6
- require('colors');
7
30
 
8
31
  /* CODE */
9
32
 
@@ -1,28 +1,28 @@
1
- const fs = require("fs");
1
+ const fs = require("fs").promises;
2
2
  const path = require("path");
3
- const mkdirp = require("mkdirp");
4
3
 
5
4
  const fileList = process.argv[2];
6
5
  const dest = process.argv[3];
7
- const src = "../../node_modules/@openui5/sap.ui.core/src/";
6
+ const src = "@openui5/sap.ui.core/src/";
8
7
 
9
- const filesToCopy = fs.readFileSync(fileList).toString();
10
- // console.log(filesToCopy);
8
+ const generate = async () => {
9
+ const filesToCopy = (await fs.readFile(fileList)).toString();
10
+ // console.log(filesToCopy);
11
11
 
12
- // Support full-line comments starting with # in the used-modules.txt file
13
- const shouldCopy = file => file.length && !file.startsWith("#");
12
+ // Support full-line comments starting with # in the used-modules.txt file
13
+ const shouldCopy = file => file.length && !file.startsWith("#");
14
14
 
15
- const trimFile = file => file.trim();
15
+ const trimFile = file => file.trim();
16
16
 
17
- filesToCopy.split("\n").map(trimFile).filter(shouldCopy).forEach(async moduleName => {
18
- const srcPath = path.join(src, moduleName);
19
- const destPath = path.join(dest, moduleName);
17
+ return filesToCopy.split("\n").map(trimFile).filter(shouldCopy).map(async moduleName => {
18
+ const srcPath = require.resolve(path.join(src, moduleName), {paths: [process.cwd()]});
19
+ const destPath = path.join(dest, moduleName);
20
20
 
21
- await mkdirp(path.dirname(destPath));
22
- fs.copyFile(srcPath, destPath, (err) => {
23
- if (err) {
24
- throw err;
25
- }
26
- console.log(`${destPath} created.`);
21
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
22
+ return fs.copyFile(srcPath, destPath);
27
23
  });
24
+ };
25
+
26
+ generate().then(() => {
27
+ console.log("Files copied.");
28
28
  });
@@ -1,58 +1,124 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const mkdirp = require("mkdirp");
4
-
5
- const collectionName = process.argv[2] || "SAP-icons";
6
- const srcFile = path.normalize(`src/${collectionName}.json`);
7
- const destDir = path.normalize("dist/");
8
-
9
- mkdirp.sync(destDir);
10
-
11
- const template = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
12
-
13
- const name = "${name}";
14
- const pathData = "${pathData}";
15
- const ltr = ${ltr};
16
- const collection = "${collection}";
17
- const packageName = "${packageName}";
18
-
19
- registerIcon(name, { pathData, ltr, collection, packageName });
20
-
21
- export default { pathData };`;
22
-
23
-
24
- const accTemplate = (name, pathData, ltr, accData, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
25
- import { ${accData.key} } from "./generated/i18n/i18n-defaults.js";
26
-
27
- const name = "${name}";
28
- const pathData = "${pathData}";
29
- const ltr = ${ltr};
30
- const accData = ${accData.key};
31
- const collection = "${collection}";
32
- const packageName = "${packageName}";
33
-
34
- registerIcon(name, { pathData, ltr, accData, collection, packageName });
35
-
36
- export default { pathData, accData };`;
37
-
38
- const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
39
- <path d="${pathData}"/>
40
- </svg>`;
41
-
42
- const createIcons = (file) => {
43
- const json = JSON.parse(fs.readFileSync(file));
44
-
45
- for (let name in json.data) {
46
- const iconData = json.data[name];
47
- const pathData = iconData.path;
48
- const ltr = !!iconData.ltr;
49
- const acc = iconData.acc;
50
-
51
- const content = acc ? accTemplate(name, pathData, ltr, acc, json.collection, json.packageName) : template(name, pathData, ltr, json.collection, json.packageName);
52
-
53
- fs.writeFileSync(path.join(destDir, `${name}.js`), content);
54
- fs.writeFileSync(path.join(destDir, `${name}.svg`), svgTemplate(pathData));
55
- }
56
- };
57
-
58
- createIcons(srcFile);
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const collectionName = process.argv[2] || "SAP-icons-v4";
5
+ const collectionVersion = process.argv[3];
6
+ const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
7
+ const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
8
+
9
+ const iconTemplate = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
10
+
11
+ const name = "${name}";
12
+ const pathData = "${pathData}";
13
+ const ltr = ${ltr};
14
+ const accData = null;
15
+ const collection = "${collection}";
16
+ const packageName = "${packageName}";
17
+
18
+ registerIcon(name, { pathData, ltr, collection, packageName });
19
+
20
+ export default "${collection}/${name}";
21
+ export { pathData, ltr, accData };`;
22
+
23
+
24
+ const iconAccTemplate = (name, pathData, ltr, accData, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
25
+ import { ${accData.key} } from "../generated/i18n/i18n-defaults.js";
26
+
27
+ const name = "${name}";
28
+ const pathData = "${pathData}";
29
+ const ltr = ${ltr};
30
+ const accData = ${accData.key};
31
+ const collection = "${collection}";
32
+ const packageName = "${packageName}";
33
+
34
+ registerIcon(name, { pathData, ltr, accData, collection, packageName });
35
+
36
+ export default "${collection}/${name}";
37
+ export { pathData, ltr, accData };`;
38
+
39
+
40
+
41
+ const collectionTemplate = (name, versions, fullName) => `import { isLegacyThemeFamily } 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
+
45
+ const pathData = isLegacyThemeFamily() ? pathData${versions[0]} : pathData${versions[1]};
46
+
47
+ export default "${fullName}";
48
+ export { pathData, ltr, accData };`;
49
+
50
+
51
+ const typeDefinitionTemplate = (name, accData, collection) => `declare const pathData: string;
52
+ declare const ltr: boolean;
53
+ declare const accData: ${accData ? '{ key: string; defaultText: string; }' : null}
54
+ declare const _default: "${collection}/${name}";
55
+
56
+ export default _default;
57
+ export { pathData, ltr, accData };`
58
+
59
+ const collectionTypeDefinitionTemplate = (name, accData) => `declare const pathData: string;
60
+ declare const ltr: boolean;
61
+ declare const accData: ${accData ? '{ key: string; defaultText: string; }' : null}
62
+ declare const _default: "${name}";
63
+
64
+ export default _default;
65
+ export { pathData, ltr, accData };`
66
+
67
+
68
+ const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
69
+ <path d="${pathData}"/>
70
+ </svg>`;
71
+
72
+ const createIcons = async (file) => {
73
+ await fs.mkdir(destDir, { recursive: true });
74
+
75
+ const json = JSON.parse(await fs.readFile(file));
76
+
77
+ const promises = [];
78
+ for (let name in json.data) {
79
+ const iconData = json.data[name];
80
+ const pathData = iconData.path;
81
+ const ltr = !!iconData.ltr;
82
+ const acc = iconData.acc;
83
+ const packageName = json.packageName;
84
+ const collection = json.collection;
85
+
86
+ const content = acc ? iconAccTemplate(name, pathData, ltr, acc, collection, packageName) : iconTemplate(name, pathData, ltr, collection, packageName);
87
+
88
+ promises.push(fs.writeFile(path.join(destDir, `${name}.js`), content));
89
+ promises.push(fs.writeFile(path.join(destDir, `${name}.svg`), svgTemplate(pathData)));
90
+ promises.push(fs.writeFile(path.join(destDir, `${name}.d.ts`), typeDefinitionTemplate(name, acc, collection)));
91
+
92
+ // For versioned icons collections, the script creates top level (unversioned) module that internally imports the versioned ones.
93
+ // For example, the top level "@ui5/ui5-webcomponents-icons/dist/accept.js" imports:
94
+ // - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
95
+ // - "@ui5/ui5-webcomponents-icons/dist/v4/accept.js"
96
+
97
+ if (json.version) {
98
+ // The exported value from the top level (unversioned) icon module depends on whether the collection is the default,
99
+ // to add or not the collection name to the exported value:
100
+ // For the default collection (SAPIcons) we export just the icon name - "export default { 'accept' }"
101
+ // For non-default collections (SAPTNTIcons and SAPBSIcons) we export the full name - "export default { 'tnt/actor' }"
102
+ const effectiveName = isDefaultCollection(collection) ? name : getUnversionedFullIconName(name, collection);
103
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name, json.versions, effectiveName)));
104
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.d.ts`), collectionTypeDefinitionTemplate(effectiveName, acc)));
105
+ }
106
+ }
107
+
108
+ return Promise.all(promises);
109
+ };
110
+
111
+ const isDefaultCollection = collectionName => collectionName === "SAP-icons-v4" || collectionName === "SAP-icons-v5";
112
+ const getUnversionedFullIconName = (name, collection) => `${getUnversionedCollectionName(collection)}/${name}`;
113
+ const getUnversionedCollectionName = collectionName => CollectionVersionedToUnversionedMap[collectionName] || collectionName;
114
+
115
+ const CollectionVersionedToUnversionedMap = {
116
+ "tnt-v2": "tnt",
117
+ "tnt-v3": "tnt",
118
+ "business-suite-v1": "business-suite",
119
+ "business-suite-v2": "business-suite",
120
+ };
121
+
122
+ createIcons(srcFile).then(() => {
123
+ console.log("Icons created.");
124
+ });