@ui5/webcomponents-tools 0.0.0-dc606098a → 0.0.0-ddc5fe31b

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 (100) hide show
  1. package/CHANGELOG.md +908 -0
  2. package/README.md +6 -6
  3. package/assets-meta.js +29 -3
  4. package/bin/dev.js +12 -1
  5. package/components-package/eslint.js +36 -0
  6. package/components-package/nps.js +119 -44
  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 -297
  11. package/components-package/wdio.sync.js +368 -0
  12. package/icons-collection/nps.js +55 -12
  13. package/lib/amd-to-es6/index.js +104 -0
  14. package/lib/cem/custom-elements-manifest.config.mjs +482 -0
  15. package/lib/cem/event.mjs +131 -0
  16. package/lib/cem/schema-internal.json +1357 -0
  17. package/lib/cem/schema.json +1098 -0
  18. package/lib/cem/types-internal.d.ts +802 -0
  19. package/lib/cem/types.d.ts +736 -0
  20. package/lib/cem/utils.mjs +379 -0
  21. package/lib/cem/validate.js +65 -0
  22. package/lib/copy-and-watch/index.js +145 -0
  23. package/lib/copy-list/index.js +28 -0
  24. package/lib/create-icons/index.js +124 -54
  25. package/lib/create-illustrations/index.js +165 -0
  26. package/lib/create-new-component/index.js +72 -93
  27. package/lib/create-new-component/jsFileContentTemplate.js +73 -0
  28. package/lib/create-new-component/tsFileContentTemplate.js +71 -0
  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 +46 -0
  32. package/lib/css-processors/shared.mjs +76 -0
  33. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  34. package/lib/dev-server/dev-server.js +66 -0
  35. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  36. package/lib/generate-custom-elements-manifest/index.js +271 -0
  37. package/lib/generate-js-imports/illustrations.js +86 -0
  38. package/lib/generate-json-imports/i18n.js +80 -30
  39. package/lib/generate-json-imports/themes.js +70 -18
  40. package/lib/hbs2lit/index.js +2 -4
  41. package/lib/hbs2lit/src/compiler.js +30 -9
  42. package/lib/hbs2lit/src/includesReplacer.js +23 -17
  43. package/lib/hbs2lit/src/litVisitor2.js +125 -26
  44. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  45. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +35 -7
  46. package/lib/hbs2ui5/index.js +69 -30
  47. package/lib/i18n/defaults.js +65 -57
  48. package/lib/i18n/toJSON.js +13 -12
  49. package/lib/jsdoc/config.json +1 -1
  50. package/lib/jsdoc/configTypescript.json +29 -0
  51. package/lib/jsdoc/plugin.js +65 -4
  52. package/lib/jsdoc/preprocess.js +146 -0
  53. package/lib/jsdoc/template/publish.js +32 -4
  54. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  55. package/lib/scoping/get-all-tags.js +37 -0
  56. package/lib/scoping/lint-src.js +31 -0
  57. package/lib/scoping/missing-dependencies.js +65 -0
  58. package/lib/scoping/report-tags-usage.js +28 -0
  59. package/lib/scoping/scope-test-pages.js +41 -0
  60. package/lib/test-runner/test-runner.js +71 -0
  61. package/package.json +55 -54
  62. package/bin/init-ui5-package.js +0 -3
  63. package/components-package/rollup.js +0 -134
  64. package/components-package/serve.json +0 -3
  65. package/lib/documentation/index.js +0 -143
  66. package/lib/documentation/templates/api-component-since.js +0 -3
  67. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  68. package/lib/documentation/templates/api-events-section.js +0 -35
  69. package/lib/documentation/templates/api-methods-section.js +0 -26
  70. package/lib/documentation/templates/api-properties-section.js +0 -40
  71. package/lib/documentation/templates/api-slots-section.js +0 -28
  72. package/lib/documentation/templates/template.js +0 -38
  73. package/lib/init-package/index.js +0 -119
  74. package/lib/init-package/resources/.eslintignore +0 -3
  75. package/lib/init-package/resources/bundle.es5.js +0 -25
  76. package/lib/init-package/resources/bundle.esm.js +0 -34
  77. package/lib/init-package/resources/config/.eslintrc.js +0 -1
  78. package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
  79. package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
  80. package/lib/init-package/resources/config/rollup.config.js +0 -1
  81. package/lib/init-package/resources/config/wdio.conf.js +0 -1
  82. package/lib/init-package/resources/package-scripts.js +0 -11
  83. package/lib/init-package/resources/src/Assets.js +0 -5
  84. package/lib/init-package/resources/src/Demo.hbs +0 -1
  85. package/lib/init-package/resources/src/Demo.js +0 -56
  86. package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
  87. package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
  88. package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
  89. package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
  90. package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
  91. package/lib/init-package/resources/src/themes/Demo.css +0 -11
  92. package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
  93. package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
  94. package/lib/init-package/resources/src/themes/sap_belize_hcw/parameters-bundle.css +0 -3
  95. package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  96. package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
  97. package/lib/init-package/resources/test/pages/index.html +0 -51
  98. package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
  99. package/lib/postcss-css-to-esm/index.js +0 -42
  100. package/lib/postcss-css-to-json/index.js +0 -27
@@ -0,0 +1,379 @@
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 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.ArrayType) {
28
+ return [type.elementType?.typeName?.text];
29
+ } else if (type?.kind === ts.SyntaxKind.UnionType) {
30
+ return type.types
31
+ .map((type) => extractTypeRefs(type))
32
+ .flat(1);
33
+ } else if (type?.kind === ts.SyntaxKind.TemplateLiteralType) {
34
+ if (member?.type) {
35
+ member.type.text = member.type.text.replaceAll?.(/`|\${|}/g, "");
36
+ }
37
+
38
+ return type.templateSpans?.length
39
+ ? type.templateSpans.map((typeRef) => typeRef.type?.typeName?.text)
40
+ : [type.typeName?.text];
41
+ }
42
+ };
43
+
44
+ let typeRefs = extractTypeRefs(node.type) || node?.typeArguments?.map(n => extractTypeRefs(n)).flat(2);
45
+
46
+ if (typeRefs) {
47
+ typeRefs = typeRefs.filter((e) => !!e);
48
+ }
49
+
50
+ return typeRefs?.length ? typeRefs : undefined;
51
+ };
52
+
53
+ const getSinceStatus = (jsdocComment) => {
54
+ const sinceTag = findTag(jsdocComment, "since");
55
+ return sinceTag
56
+ ? sinceTag.description
57
+ ? `${sinceTag.name} ${sinceTag.description}`
58
+ : sinceTag.name
59
+ : undefined;
60
+ };
61
+
62
+ const getPrivacyStatus = (jsdocComment) => {
63
+ const privacyTag = findTag(jsdocComment, ["public", "private", "protected"]);
64
+ return privacyTag?.tag || "private";
65
+ };
66
+
67
+ const findPackageName = (ts, sourceFile, typeName) => {
68
+ const localStatements = [
69
+ ts.SyntaxKind.EnumDeclaration,
70
+ ts.SyntaxKind.InterfaceDeclaration,
71
+ ts.SyntaxKind.ClassDeclaration,
72
+ ts.SyntaxKind.TypeAliasDeclaration,
73
+ ];
74
+
75
+ const isLocalDeclared = sourceFile.statements.some(
76
+ (statement) =>
77
+ localStatements.includes(statement.kind) && statement?.name?.text === typeName
78
+ );
79
+
80
+ if (isLocalDeclared) {
81
+ return packageJSON?.name;
82
+ } else {
83
+ const importStatements = sourceFile.statements?.filter(
84
+ (statement) => statement.kind === ts.SyntaxKind.ImportDeclaration
85
+ );
86
+ const currentModuleSpecifier = importStatements.find((statement) => {
87
+ if (statement.importClause?.name?.text === typeName) {
88
+ return true;
89
+ }
90
+
91
+ return statement.importClause?.namedBindings?.elements?.some(
92
+ (element) => element.name?.text === typeName
93
+ );
94
+ })?.moduleSpecifier;
95
+
96
+ if (currentModuleSpecifier?.text?.startsWith(".")) {
97
+ return packageJSON?.name;
98
+ } else {
99
+ return Object.keys(packageJSON?.dependencies || {}).find(
100
+ (dependency) =>
101
+ currentModuleSpecifier?.text?.startsWith(`${dependency}/`)
102
+ );
103
+ }
104
+ }
105
+ };
106
+
107
+ const findImportPath = (ts, sourceFile, typeName, modulePath) => {
108
+ const localStatements = [
109
+ ts.SyntaxKind.EnumDeclaration,
110
+ ts.SyntaxKind.InterfaceDeclaration,
111
+ ts.SyntaxKind.ClassDeclaration,
112
+ ts.SyntaxKind.TypeAliasDeclaration,
113
+ ];
114
+
115
+ const isLocalDeclared = sourceFile.statements.some(
116
+ (statement) =>
117
+ localStatements.includes(statement.kind) && statement?.name?.text === typeName
118
+ );
119
+
120
+ if (isLocalDeclared) {
121
+ return (
122
+ modulePath?.replace("src", "dist")?.replace(".ts", ".js") || undefined
123
+ );
124
+ } else {
125
+ const importStatements = sourceFile.statements?.filter(
126
+ (statement) => statement.kind === ts.SyntaxKind.ImportDeclaration
127
+ );
128
+ const currentModuleSpecifier = importStatements.find((statement) => {
129
+ if (statement.importClause?.name?.text === typeName) {
130
+ return true;
131
+ }
132
+
133
+ return statement.importClause?.namedBindings?.elements?.some(
134
+ (element) => element.name?.text === typeName
135
+ );
136
+ })?.moduleSpecifier;
137
+
138
+ if (currentModuleSpecifier?.text?.startsWith(".")) {
139
+ return (
140
+ path.join(path.dirname(modulePath), currentModuleSpecifier.text)
141
+ ?.replace("src", "dist")?.replace(".ts", ".js") || undefined
142
+ );
143
+ } else {
144
+ const packageName = Object.keys(packageJSON?.dependencies || {}).find(
145
+ (dependency) =>
146
+ currentModuleSpecifier?.text?.startsWith(dependency)
147
+ );
148
+ return currentModuleSpecifier?.text
149
+ ?.replace(`${packageName}/`, "") || undefined;
150
+ }
151
+ }
152
+ };
153
+
154
+
155
+ const isClass = text => {
156
+ return text.includes("@abstract") || text.includes("@class") || text.includes("@constructor");
157
+ };
158
+
159
+ const normalizeTagType = (type) => {
160
+ return type?.trim();
161
+ }
162
+
163
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
164
+
165
+ const getReference = (ts, type, classNode, modulePath) => {
166
+ let sourceFile = classNode.parent;
167
+
168
+ while (sourceFile && sourceFile.kind !== ts.SyntaxKind.SourceFile) {
169
+ sourceFile = sourceFile.parent;
170
+ }
171
+
172
+ const typeName =
173
+ typeof type === "string"
174
+ ? normalizeTagType(type)
175
+ : type.class?.expression?.text ||
176
+ type.typeExpression?.type?.getText() ||
177
+ type.typeExpression?.type?.elementType?.typeName?.text;
178
+ const packageName = findPackageName(ts, sourceFile, typeName);
179
+ const importPath = findImportPath(
180
+ ts,
181
+ sourceFile,
182
+ typeName,
183
+ modulePath
184
+ )?.replace(`${packageName}/`, "");
185
+
186
+ return packageName && {
187
+ name: typeName,
188
+ package: packageName,
189
+ module: importPath,
190
+ };
191
+ };
192
+
193
+ const getType = (type) => {
194
+ const typeName = typeof type === "string" ? normalizeTagType(type) : type?.type;
195
+
196
+ const multiple =
197
+ typeName?.endsWith("[]") || typeName?.startsWith("Array<");
198
+ const name = multiple
199
+ ? typeName?.replace("[]", "")?.replace("Array<", "")?.replace(">", "")
200
+ : typeName;
201
+
202
+ return typeName ? { typeName: multiple ? `Array<${name}>` : typeName, name, multiple } : undefined;
203
+ };
204
+
205
+ const commonTags = ["public", "protected", "private", "since", "deprecated"];
206
+
207
+ const allowedTags = {
208
+ field: [...commonTags, "formEvents", "formProperty", "default"],
209
+ slot: [...commonTags, "default"],
210
+ event: [...commonTags, "param", "allowPreventDefault", "native"],
211
+ eventParam: [...commonTags],
212
+ method: [...commonTags, "param", "returns", "override"],
213
+ class: [...commonTags, "constructor", "class", "abstract", "implements", "extends", "slot", "csspart"],
214
+ enum: [...commonTags],
215
+ enumMember: [...commonTags],
216
+ interface: [...commonTags],
217
+ };
218
+ allowedTags.getter = [...allowedTags.field, "override"]
219
+
220
+ const tagMatchCallback = (tag, tagName) => {
221
+ const currentTagName = tag.tag;
222
+
223
+ return typeof tagName === "string"
224
+ ? currentTagName === tagName
225
+ : tagName.includes(currentTagName);
226
+ };
227
+
228
+ const findDecorator = (node, decoratorName) => {
229
+ return node?.decorators?.find(
230
+ (decorator) =>
231
+ decorator?.expression?.expression?.text === decoratorName
232
+ );
233
+ };
234
+
235
+ const findAllDecorators = (node, decoratorName) => {
236
+ return (
237
+ node?.decorators?.filter(
238
+ (decorator) =>
239
+ decorator?.expression?.expression?.text === decoratorName
240
+ ) || []
241
+ );
242
+ };
243
+
244
+ const hasTag = (jsDoc, tagName) => {
245
+ if (!jsDoc) {
246
+ return;
247
+ }
248
+
249
+ return jsDoc?.tags?.some((tag) => tagMatchCallback(tag, tagName));
250
+ };
251
+
252
+ const findTag = (jsDoc, tagName) => {
253
+ if (!jsDoc) {
254
+ return;
255
+ }
256
+
257
+ return jsDoc?.tags?.find((tag) => tagMatchCallback(tag, tagName));
258
+ };
259
+
260
+ const findAllTags = (jsDoc, tagName) => {
261
+ if (!jsDoc) {
262
+ return [];
263
+ }
264
+
265
+ const foundTags = jsDoc?.tags?.filter((tag) => tagMatchCallback(tag, tagName));
266
+
267
+ return foundTags || [];
268
+ };
269
+
270
+ const validateJSDocTag = (tag) => {
271
+ const booleanTags = ["private", "protected", "public", "abstract", "allowPreventDefault", "native", "formProperty", "constructor", "override"];
272
+ let tagName = tag.tag;
273
+
274
+ if (booleanTags.includes(tag.tag)) {
275
+ tagName = "boolean";
276
+ }
277
+
278
+ switch (tagName) {
279
+ case "boolean":
280
+ return !tag.name && !tag.type && !tag.description;
281
+ case "deprecated":
282
+ return !tag.type;
283
+ case "extends":
284
+ return !tag.type && tag.name && !tag.description;
285
+ case "implements":
286
+ return tag.type && !tag.name && !tag.description;
287
+ case "slot":
288
+ return tag.type && tag.name && tag.description;
289
+ case "csspart":
290
+ return !tag.type && tag.name && tag.description;
291
+ case "since":
292
+ return !tag.type && tag.name;
293
+ case "returns":
294
+ return !tag.type && tag.name;
295
+ case "default":
296
+ return !tag.type && !tag.description;
297
+ case "class":
298
+ return !tag.type;
299
+ case "param":
300
+ return !tag.type && tag.name;
301
+ case "eventparam":
302
+ return tag.type && tag.name;
303
+ case "formEvents":
304
+ return !tag.type && tag.name;
305
+ default:
306
+ return false;
307
+ }
308
+ };
309
+
310
+ const validateJSDocComment = (fieldType, jsdocComment, node, moduleDoc) => {
311
+ return !!jsdocComment?.tags?.every((tag) => {
312
+ let isValid = false
313
+
314
+ if (fieldType === "event" && tag?.tag === "param") {
315
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag({...tag, tag: "eventparam"});
316
+ } else {
317
+ isValid = allowedTags[fieldType]?.includes(tag.tag) && validateJSDocTag(tag);
318
+ }
319
+
320
+ if (!isValid) {
321
+ logDocumentationError(moduleDoc.path, `Incorrect use of @${tag.tag}. Ensure it is part of ${fieldType} JSDoc tags.`)
322
+ }
323
+
324
+ return !!isValid;
325
+ });
326
+ };
327
+
328
+ const logDocumentationError = (modulePath, message) => {
329
+ let moduleErrors = documentationErrors.get(modulePath);
330
+
331
+ if (!moduleErrors) {
332
+ documentationErrors.set(modulePath, []);
333
+ moduleErrors = documentationErrors.get(modulePath);
334
+ }
335
+
336
+ moduleErrors.push(message);
337
+ }
338
+
339
+ const displayDocumentationErrors = () => {
340
+ let errorsCount = 0;
341
+ [...documentationErrors.keys()].forEach(modulePath => {
342
+ const moduleErrors = documentationErrors.get(modulePath);
343
+
344
+ console.log(`=== ERROR: ${moduleErrors.length > 1 ? `${moduleErrors.length} problems` : "Problem"} found in file: ${modulePath}:`)
345
+ moduleErrors.forEach(moduleError => {
346
+ errorsCount++;
347
+ console.log(`\t- ${moduleError}`)
348
+ })
349
+ })
350
+
351
+ if(errorsCount) {
352
+ throw new Error(`Found ${errorsCount} errors in the description of the public API.`);
353
+ }
354
+ }
355
+
356
+ const formatArrays = (typeText) => {
357
+ return typeText?.replaceAll(/(\S+)\[\]/g, "Array<$1>")
358
+ }
359
+
360
+ export {
361
+ getPrivacyStatus,
362
+ getSinceStatus,
363
+ getDeprecatedStatus,
364
+ getType,
365
+ getReference,
366
+ validateJSDocComment,
367
+ findDecorator,
368
+ findAllDecorators,
369
+ hasTag,
370
+ findTag,
371
+ findAllTags,
372
+ getTypeRefs,
373
+ normalizeDescription,
374
+ formatArrays,
375
+ isClass,
376
+ normalizeTagType,
377
+ displayDocumentationErrors,
378
+ logDocumentationError,
379
+ };
@@ -0,0 +1,65 @@
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 if (argv.dev) {
64
+ throw new Error(`Validation of public custom elements manifest failed: ${validate.errors}`);
65
+ }
@@ -0,0 +1,145 @@
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
+
25
+ const fs = require('fs');
26
+ const path = require('path');
27
+ const chokidar = require('chokidar');
28
+ const glob = require('glob');
29
+ const globParent = require('glob-parent');
30
+
31
+ /* CODE */
32
+
33
+ const args = process.argv.slice(2);
34
+ const options = {};
35
+
36
+ ['watch', 'clean', 'skip-initial-copy', 'safe', 'silent'].forEach(key => {
37
+ const index = args.indexOf(`--${key}`);
38
+ if (index >= 0) {
39
+ options[key] = true;
40
+ args.splice(index, 1);
41
+ }
42
+ });
43
+
44
+ if (args.length < 2) {
45
+ console.error('Not enough arguments: copy-and-watch [options] <sources> <target>'.red);
46
+ process.exit(1);
47
+ }
48
+
49
+ if (options['skip-initial-copy'] && !options['watch']) {
50
+ console.error('--skip-initial-copy argument is meant to be used with --watch, otherwise no files will be copied'.red);
51
+ process.exit(1);
52
+ }
53
+
54
+ const target = args.pop();
55
+ const sources = args;
56
+ const parents = [...new Set(sources.map(globParent))];
57
+
58
+ const findTarget = from => {
59
+ const parent = parents
60
+ .filter(p => from.indexOf(p) >= 0)
61
+ .sort()
62
+ .reverse()[0];
63
+ return path.join(target, path.relative(parent, from));
64
+ };
65
+ const createDirIfNotExist = to => {
66
+ 'use strict';
67
+
68
+ const dirs = [];
69
+ let dir = path.dirname(to);
70
+
71
+ while (dir !== path.dirname(dir)) {
72
+ dirs.unshift(dir);
73
+ dir = path.dirname(dir);
74
+ }
75
+
76
+ dirs.forEach(dir => {
77
+ if (!fs.existsSync(dir)) {
78
+ fs.mkdirSync(dir);
79
+ }
80
+ });
81
+ };
82
+ const copy = from => {
83
+ const to = findTarget(from);
84
+ createDirIfNotExist(to);
85
+ const stats = fs.statSync(from);
86
+ if (stats.isDirectory()) {
87
+ return;
88
+ }
89
+ fs.writeFileSync(to, fs.readFileSync(from));
90
+ options.silent || console.log('[COPY]'.yellow, from, 'to'.yellow, to);
91
+ };
92
+ const remove = from => {
93
+ const to = findTarget(from);
94
+ fs.unlinkSync(to);
95
+ options.silent || console.log('[DELETE]'.yellow, to);
96
+ };
97
+ const rimraf = dir => {
98
+ if (fs.existsSync(dir)) {
99
+ fs.readdirSync(dir).forEach(entry => {
100
+ const entryPath = path.join(dir, entry);
101
+ if (fs.lstatSync(entryPath).isDirectory()) {
102
+ rimraf(entryPath);
103
+ } else {
104
+ fs.unlinkSync(entryPath);
105
+ }
106
+ });
107
+ fs.rmdirSync(dir);
108
+ }
109
+ };
110
+
111
+ // clean
112
+ if (options.clean) {
113
+ rimraf(target);
114
+ }
115
+
116
+ // initial copy
117
+ if (!options['skip-initial-copy']) {
118
+ sources.forEach(s => glob.sync(s).forEach(copy));
119
+ }
120
+
121
+ // watch
122
+ if (options.watch) {
123
+ const chokidarOptions = {
124
+ ignoreInitial: true
125
+ };
126
+
127
+ if (options.safe) {
128
+ chokidarOptions.awaitWriteFinish = {
129
+ stabilityThreshold: 500,
130
+ pollInterval: 100
131
+ };
132
+ }
133
+
134
+ chokidar
135
+ .watch(sources, chokidarOptions)
136
+ .on('ready', () => sources.forEach(s => {
137
+ options.silent || console.log('[WATCH]'.yellow, s);
138
+ }))
139
+ .on('add', copy)
140
+ .on('addDir', copy)
141
+ .on('change', copy)
142
+ .on('unlink', remove)
143
+ .on('unlinkDir', remove)
144
+ .on('error', e => console.log('[ERROR]'.red, e));
145
+ }
@@ -0,0 +1,28 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const fileList = process.argv[2];
5
+ const dest = process.argv[3];
6
+ const src = "@openui5/sap.ui.core/src/";
7
+
8
+ const generate = async () => {
9
+ const filesToCopy = (await fs.readFile(fileList)).toString();
10
+ // console.log(filesToCopy);
11
+
12
+ // Support full-line comments starting with # in the used-modules.txt file
13
+ const shouldCopy = file => file.length && !file.startsWith("#");
14
+
15
+ const trimFile = file => file.trim();
16
+
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
+
21
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
22
+ return fs.copyFile(srcPath, destPath);
23
+ });
24
+ };
25
+
26
+ generate().then(() => {
27
+ console.log("Files copied.");
28
+ });