@ui5/webcomponents-tools 0.0.0-fb61e9889 → 0.0.0-fca1107e7

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 (82) hide show
  1. package/CHANGELOG.md +980 -0
  2. package/README.md +6 -6
  3. package/assets-meta.js +16 -3
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +36 -0
  6. package/components-package/nps.js +108 -70
  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 -353
  11. package/components-package/wdio.sync.js +26 -2
  12. package/icons-collection/nps.js +51 -18
  13. package/lib/amd-to-es6/index.js +102 -0
  14. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  15. package/lib/cem/custom-elements-manifest.config.mjs +501 -0
  16. package/lib/cem/event.mjs +131 -0
  17. package/lib/cem/schema-internal.json +1357 -0
  18. package/lib/cem/schema.json +1098 -0
  19. package/lib/cem/types-internal.d.ts +796 -0
  20. package/lib/cem/types.d.ts +736 -0
  21. package/lib/cem/utils.mjs +384 -0
  22. package/lib/cem/validate.js +70 -0
  23. package/lib/copy-and-watch/index.js +24 -1
  24. package/lib/copy-list/index.js +17 -17
  25. package/lib/create-icons/index.js +124 -58
  26. package/lib/create-illustrations/index.js +153 -66
  27. package/lib/create-new-component/index.js +71 -104
  28. package/lib/create-new-component/jsFileContentTemplate.js +73 -0
  29. package/lib/create-new-component/tsFileContentTemplate.js +71 -0
  30. package/lib/css-processors/css-processor-component-styles.mjs +47 -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 +66 -0
  37. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  38. package/lib/generate-custom-elements-manifest/index.js +271 -0
  39. package/lib/generate-js-imports/illustrations.js +86 -0
  40. package/lib/generate-json-imports/i18n.js +43 -31
  41. package/lib/generate-json-imports/themes.js +36 -24
  42. package/lib/hbs2lit/src/compiler.js +24 -4
  43. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  44. package/lib/hbs2lit/src/litVisitor2.js +95 -24
  45. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  46. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
  47. package/lib/hbs2ui5/index.js +56 -23
  48. package/lib/i18n/defaults.js +65 -57
  49. package/lib/i18n/toJSON.js +12 -11
  50. package/lib/jsdoc/configTypescript.json +29 -0
  51. package/lib/jsdoc/plugin.js +41 -0
  52. package/lib/jsdoc/preprocess.js +146 -0
  53. package/lib/jsdoc/template/publish.js +21 -2
  54. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  55. package/lib/scoping/get-all-tags.js +2 -9
  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 +32 -29
  61. package/components-package/rollup-plugins/empty-module.js +0 -15
  62. package/components-package/rollup.js +0 -237
  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/esm-abs-to-rel/index.js +0 -54
  72. package/lib/hash/config.js +0 -10
  73. package/lib/hash/generate.js +0 -19
  74. package/lib/hash/upToDate.js +0 -31
  75. package/lib/polyfill-placeholder/index.js +0 -5
  76. package/lib/postcss-css-to-esm/index.js +0 -45
  77. package/lib/postcss-css-to-json/index.js +0 -31
  78. package/lib/postcss-new-files/index.js +0 -36
  79. package/lib/replace-global-core/index.js +0 -20
  80. package/lib/serve/index.js +0 -46
  81. package/lib/serve/serve.json +0 -3
  82. package/package-lock.json +0 -48
@@ -0,0 +1,384 @@
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 toKebabCase = str => {
18
+ return str.replaceAll(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase())
19
+ }
20
+
21
+ const normalizeDescription = (description) => {
22
+ return typeof description === 'string' ? description.replaceAll(/^-\s+|^(\n)+|(\n)+$/g, ""): description;
23
+ }
24
+
25
+ const getTypeRefs = (ts, node, member) => {
26
+ const extractTypeRefs = (type) => {
27
+ if (type?.kind === ts.SyntaxKind.TypeReference) {
28
+ return type.typeArguments?.length
29
+ ? type.typeArguments.map((typeRef) => typeRef.typeName?.text)
30
+ : [type.typeName?.text];
31
+ } else if (type?.kind === ts.SyntaxKind.ArrayType) {
32
+ return [type.elementType?.typeName?.text];
33
+ } else if (type?.kind === ts.SyntaxKind.UnionType) {
34
+ return type.types
35
+ .map((type) => extractTypeRefs(type))
36
+ .flat(1);
37
+ } else if (type?.kind === ts.SyntaxKind.TemplateLiteralType) {
38
+ if (member?.type) {
39
+ member.type.text = member.type.text.replaceAll?.(/`|\${|}/g, "");
40
+ }
41
+
42
+ return type.templateSpans?.length
43
+ ? type.templateSpans.map((typeRef) => typeRef.type?.typeName?.text)
44
+ : [type.typeName?.text];
45
+ }
46
+ };
47
+
48
+ let typeRefs = extractTypeRefs(node.type) || node?.typeArguments?.map(n => extractTypeRefs(n)).flat(2);
49
+
50
+ if (typeRefs) {
51
+ typeRefs = typeRefs.filter((e) => !!e);
52
+ }
53
+
54
+ return typeRefs?.length ? typeRefs : undefined;
55
+ };
56
+
57
+ const getSinceStatus = (jsdocComment) => {
58
+ const sinceTag = findTag(jsdocComment, "since");
59
+ return sinceTag
60
+ ? sinceTag.description
61
+ ? `${sinceTag.name} ${sinceTag.description}`
62
+ : sinceTag.name
63
+ : undefined;
64
+ };
65
+
66
+ const getPrivacyStatus = (jsdocComment) => {
67
+ const privacyTag = findTag(jsdocComment, ["public", "private", "protected"]);
68
+ return privacyTag?.tag || "private";
69
+ };
70
+
71
+ const findPackageName = (ts, sourceFile, typeName) => {
72
+ const localStatements = [
73
+ ts.SyntaxKind.EnumDeclaration,
74
+ ts.SyntaxKind.InterfaceDeclaration,
75
+ ts.SyntaxKind.ClassDeclaration,
76
+ ts.SyntaxKind.TypeAliasDeclaration,
77
+ ];
78
+
79
+ const isLocalDeclared = sourceFile.statements.some(
80
+ (statement) =>
81
+ localStatements.includes(statement.kind) && statement?.name?.text === typeName
82
+ );
83
+
84
+ if (isLocalDeclared) {
85
+ return packageJSON?.name;
86
+ } else {
87
+ const importStatements = sourceFile.statements?.filter(
88
+ (statement) => statement.kind === ts.SyntaxKind.ImportDeclaration
89
+ );
90
+ const currentModuleSpecifier = importStatements.find((statement) => {
91
+ if (statement.importClause?.name?.text === typeName) {
92
+ return true;
93
+ }
94
+
95
+ return statement.importClause?.namedBindings?.elements?.some(
96
+ (element) => element.name?.text === typeName
97
+ );
98
+ })?.moduleSpecifier;
99
+
100
+ if (currentModuleSpecifier?.text?.startsWith(".")) {
101
+ return packageJSON?.name;
102
+ } else {
103
+ return Object.keys(packageJSON?.dependencies || {}).find(
104
+ (dependency) =>
105
+ currentModuleSpecifier?.text?.startsWith(`${dependency}/`)
106
+ );
107
+ }
108
+ }
109
+ };
110
+
111
+ const findImportPath = (ts, sourceFile, typeName, modulePath) => {
112
+ const localStatements = [
113
+ ts.SyntaxKind.EnumDeclaration,
114
+ ts.SyntaxKind.InterfaceDeclaration,
115
+ ts.SyntaxKind.ClassDeclaration,
116
+ ts.SyntaxKind.TypeAliasDeclaration,
117
+ ];
118
+
119
+ const isLocalDeclared = sourceFile.statements.some(
120
+ (statement) =>
121
+ localStatements.includes(statement.kind) && statement?.name?.text === typeName
122
+ );
123
+
124
+ if (isLocalDeclared) {
125
+ return (
126
+ modulePath?.replace("src", "dist")?.replace(".ts", ".js") || undefined
127
+ );
128
+ } else {
129
+ const importStatements = sourceFile.statements?.filter(
130
+ (statement) => statement.kind === ts.SyntaxKind.ImportDeclaration
131
+ );
132
+ const currentModuleSpecifier = importStatements.find((statement) => {
133
+ if (statement.importClause?.name?.text === typeName) {
134
+ return true;
135
+ }
136
+
137
+ return statement.importClause?.namedBindings?.elements?.some(
138
+ (element) => element.name?.text === typeName
139
+ );
140
+ })?.moduleSpecifier;
141
+
142
+ if (currentModuleSpecifier?.text?.startsWith(".")) {
143
+ return (
144
+ path.join(path.dirname(modulePath), currentModuleSpecifier.text)
145
+ ?.replace("src", "dist")?.replace(".ts", ".js") || undefined
146
+ );
147
+ } else {
148
+ const packageName = Object.keys(packageJSON?.dependencies || {}).find(
149
+ (dependency) =>
150
+ currentModuleSpecifier?.text?.startsWith(dependency)
151
+ );
152
+ return currentModuleSpecifier?.text
153
+ ?.replace(`${packageName}/`, "") || undefined;
154
+ }
155
+ }
156
+ };
157
+
158
+
159
+ const isClass = text => {
160
+ return text.includes("@abstract") || text.includes("@class") || text.includes("@constructor");
161
+ };
162
+
163
+ const normalizeTagType = (type) => {
164
+ return type?.trim();
165
+ }
166
+
167
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
168
+
169
+ const getReference = (ts, type, classNode, modulePath) => {
170
+ let sourceFile = classNode.parent;
171
+
172
+ while (sourceFile && sourceFile.kind !== ts.SyntaxKind.SourceFile) {
173
+ sourceFile = sourceFile.parent;
174
+ }
175
+
176
+ const typeName =
177
+ typeof type === "string"
178
+ ? normalizeTagType(type)
179
+ : type.class?.expression?.text ||
180
+ type.typeExpression?.type?.getText() ||
181
+ type.typeExpression?.type?.elementType?.typeName?.text;
182
+ const packageName = findPackageName(ts, sourceFile, typeName);
183
+ const importPath = findImportPath(
184
+ ts,
185
+ sourceFile,
186
+ typeName,
187
+ modulePath
188
+ )?.replace(`${packageName}/`, "");
189
+
190
+ return packageName && {
191
+ name: typeName,
192
+ package: packageName,
193
+ module: importPath,
194
+ };
195
+ };
196
+
197
+ const getType = (type) => {
198
+ const typeName = typeof type === "string" ? normalizeTagType(type) : type?.type;
199
+
200
+ const multiple =
201
+ typeName?.endsWith("[]") || typeName?.startsWith("Array<");
202
+ const name = multiple
203
+ ? typeName?.replace("[]", "")?.replace("Array<", "")?.replace(">", "")
204
+ : typeName;
205
+
206
+ return typeName ? { typeName: multiple ? `Array<${name}>` : typeName, name, multiple } : undefined;
207
+ };
208
+
209
+ const commonTags = ["public", "protected", "private", "since", "deprecated"];
210
+
211
+ const allowedTags = {
212
+ field: [...commonTags, "formEvents", "formProperty", "default"],
213
+ slot: [...commonTags, "default"],
214
+ event: [...commonTags, "param", "allowPreventDefault", "native"],
215
+ eventParam: [...commonTags],
216
+ method: [...commonTags, "param", "returns", "override"],
217
+ class: [...commonTags, "constructor", "class", "abstract", "implements", "extends", "slot", "csspart"],
218
+ enum: [...commonTags],
219
+ enumMember: [...commonTags],
220
+ interface: [...commonTags],
221
+ };
222
+ allowedTags.getter = [...allowedTags.field, "override"]
223
+
224
+ const tagMatchCallback = (tag, tagName) => {
225
+ const currentTagName = tag.tag;
226
+
227
+ return typeof tagName === "string"
228
+ ? currentTagName === tagName
229
+ : tagName.includes(currentTagName);
230
+ };
231
+
232
+ const findDecorator = (node, decoratorName) => {
233
+ return node?.decorators?.find(
234
+ (decorator) =>
235
+ decorator?.expression?.expression?.text === decoratorName
236
+ );
237
+ };
238
+
239
+ const findAllDecorators = (node, decoratorName) => {
240
+ return (
241
+ node?.decorators?.filter(
242
+ (decorator) =>
243
+ decorator?.expression?.expression?.text === decoratorName
244
+ ) || []
245
+ );
246
+ };
247
+
248
+ const hasTag = (jsDoc, tagName) => {
249
+ if (!jsDoc) {
250
+ return;
251
+ }
252
+
253
+ return jsDoc?.tags?.some((tag) => tagMatchCallback(tag, tagName));
254
+ };
255
+
256
+ const findTag = (jsDoc, tagName) => {
257
+ if (!jsDoc) {
258
+ return;
259
+ }
260
+
261
+ return jsDoc?.tags?.find((tag) => tagMatchCallback(tag, tagName));
262
+ };
263
+
264
+ const findAllTags = (jsDoc, tagName) => {
265
+ if (!jsDoc) {
266
+ return [];
267
+ }
268
+
269
+ const foundTags = jsDoc?.tags?.filter((tag) => tagMatchCallback(tag, tagName));
270
+
271
+ return foundTags || [];
272
+ };
273
+
274
+ const validateJSDocTag = (tag) => {
275
+ const booleanTags = ["private", "protected", "public", "abstract", "allowPreventDefault", "native", "formProperty", "constructor", "override"];
276
+ let tagName = tag.tag;
277
+
278
+ if (booleanTags.includes(tag.tag)) {
279
+ tagName = "boolean";
280
+ }
281
+
282
+ switch (tagName) {
283
+ case "boolean":
284
+ return !tag.name && !tag.type && !tag.description;
285
+ case "deprecated":
286
+ return !tag.type;
287
+ case "extends":
288
+ return !tag.type && tag.name && !tag.description;
289
+ case "implements":
290
+ return tag.type && !tag.name && !tag.description;
291
+ case "slot":
292
+ return tag.type && tag.name && tag.description;
293
+ case "csspart":
294
+ return !tag.type && tag.name && tag.description;
295
+ case "since":
296
+ return !tag.type && tag.name;
297
+ case "returns":
298
+ return !tag.type && tag.name;
299
+ case "default":
300
+ return !tag.type && !tag.description;
301
+ case "class":
302
+ return !tag.type;
303
+ case "param":
304
+ return !tag.type && tag.name;
305
+ case "eventparam":
306
+ return tag.type && tag.name;
307
+ case "formEvents":
308
+ return !tag.type && tag.name;
309
+ default:
310
+ return false;
311
+ }
312
+ };
313
+
314
+ const validateJSDocComment = (fieldType, jsdocComment, node, moduleDoc) => {
315
+ return !!jsdocComment?.tags?.every((tag) => {
316
+ let isValid = false
317
+
318
+ if (fieldType === "event" && tag?.tag === "param") {
319
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag({...tag, tag: "eventparam"});
320
+ } else {
321
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag(tag);
322
+ }
323
+
324
+ if (!isValid) {
325
+ logDocumentationError(moduleDoc.path, `Incorrect use of @${tag.tag}. Ensure it is part of ${fieldType} JSDoc tags.`)
326
+ }
327
+
328
+ return !!isValid;
329
+ });
330
+ };
331
+
332
+ const logDocumentationError = (modulePath, message) => {
333
+ let moduleErrors = documentationErrors.get(modulePath);
334
+
335
+ if (!moduleErrors) {
336
+ documentationErrors.set(modulePath, []);
337
+ moduleErrors = documentationErrors.get(modulePath);
338
+ }
339
+
340
+ moduleErrors.push(message);
341
+ }
342
+
343
+ const displayDocumentationErrors = () => {
344
+ let errorsCount = 0;
345
+ [...documentationErrors.keys()].forEach(modulePath => {
346
+ const moduleErrors = documentationErrors.get(modulePath);
347
+
348
+ console.log(`=== ERROR: ${moduleErrors.length > 1 ? `${moduleErrors.length} problems` : "Problem"} found in file: ${modulePath}:`)
349
+ moduleErrors.forEach(moduleError => {
350
+ errorsCount++;
351
+ console.log(`\t- ${moduleError}`)
352
+ })
353
+ })
354
+
355
+ if(errorsCount) {
356
+ throw new Error(`Found ${errorsCount} errors in the description of the public API.`);
357
+ }
358
+ }
359
+
360
+ const formatArrays = (typeText) => {
361
+ return typeText?.replaceAll(/(\S+)\[\]/g, "Array<$1>")
362
+ }
363
+
364
+ export {
365
+ getPrivacyStatus,
366
+ getSinceStatus,
367
+ getDeprecatedStatus,
368
+ getType,
369
+ getReference,
370
+ validateJSDocComment,
371
+ findDecorator,
372
+ findAllDecorators,
373
+ hasTag,
374
+ findTag,
375
+ findAllTags,
376
+ getTypeRefs,
377
+ normalizeDescription,
378
+ formatArrays,
379
+ isClass,
380
+ normalizeTagType,
381
+ displayDocumentationErrors,
382
+ logDocumentationError,
383
+ toKebabCase
384
+ };
@@ -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
+ }
@@ -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
  });