@ui5/webcomponents-tools 0.0.0-d0bcf47c7 → 0.0.0-d479b681b

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 (58) hide show
  1. package/CHANGELOG.md +510 -1
  2. package/README.md +5 -6
  3. package/assets-meta.js +153 -0
  4. package/bin/dev.js +12 -1
  5. package/components-package/eslint.js +34 -0
  6. package/components-package/nps.js +112 -44
  7. package/components-package/postcss.components.js +13 -13
  8. package/components-package/postcss.themes.js +19 -16
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +393 -327
  11. package/components-package/wdio.sync.js +360 -0
  12. package/icons-collection/nps.js +69 -28
  13. package/lib/copy-and-watch/index.js +145 -0
  14. package/lib/copy-list/index.js +28 -0
  15. package/lib/create-icons/index.js +124 -0
  16. package/lib/create-illustrations/index.js +161 -0
  17. package/lib/create-new-component/index.js +128 -0
  18. package/lib/create-new-component/jsFileContentTemplate.js +77 -0
  19. package/lib/create-new-component/tsFileContentTemplate.js +84 -0
  20. package/lib/dev-server/dev-server.js +66 -0
  21. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  22. package/lib/esm-abs-to-rel/index.js +58 -0
  23. package/lib/generate-custom-elements-manifest/index.js +327 -0
  24. package/lib/generate-js-imports/illustrations.js +72 -0
  25. package/lib/generate-json-imports/i18n.js +98 -0
  26. package/lib/generate-json-imports/themes.js +80 -0
  27. package/lib/hbs2lit/index.js +3 -0
  28. package/lib/hbs2lit/src/compiler.js +57 -0
  29. package/lib/hbs2lit/src/extendedAttributeMapping.js +12 -0
  30. package/lib/hbs2lit/src/includesReplacer.js +31 -0
  31. package/lib/hbs2lit/src/litVisitor2.js +253 -0
  32. package/lib/hbs2lit/src/partials2.js +51 -0
  33. package/lib/hbs2lit/src/partialsVisitor.js +187 -0
  34. package/lib/hbs2lit/src/svgProcessor.js +69 -0
  35. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +12 -0
  36. package/lib/hbs2ui5/index.js +102 -0
  37. package/lib/i18n/defaults.js +82 -0
  38. package/lib/i18n/toJSON.js +43 -0
  39. package/lib/jsdoc/config.json +29 -0
  40. package/lib/jsdoc/configTypescript.json +29 -0
  41. package/lib/jsdoc/plugin.js +2468 -0
  42. package/lib/jsdoc/preprocess.js +146 -0
  43. package/lib/jsdoc/template/publish.js +4120 -0
  44. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  45. package/lib/postcss-css-to-esm/index.js +90 -0
  46. package/lib/postcss-css-to-json/index.js +47 -0
  47. package/lib/postcss-new-files/index.js +36 -0
  48. package/lib/postcss-p/postcss-p.mjs +14 -0
  49. package/lib/replace-global-core/index.js +25 -0
  50. package/lib/scoping/get-all-tags.js +37 -0
  51. package/lib/scoping/lint-src.js +31 -0
  52. package/lib/scoping/missing-dependencies.js +65 -0
  53. package/lib/scoping/report-tags-usage.js +28 -0
  54. package/lib/scoping/scope-test-pages.js +40 -0
  55. package/lib/test-runner/test-runner.js +71 -0
  56. package/package.json +55 -55
  57. package/bin/init-ui5-package.js +0 -3
  58. package/package-lock.json +0 -9994
@@ -0,0 +1,58 @@
1
+ const esprima = require("esprima");
2
+ const escodegen = require("escodegen");
3
+
4
+ const fs = require("fs").promises;
5
+ const path = require("path");
6
+ const basePath = process.argv[2];
7
+
8
+ const convertImports = async (srcPath) => {
9
+ let changed = false;
10
+ // console.log("scanning imports of", srcPath);
11
+ let code = (await fs.readFile(srcPath)).toString();
12
+ const tree = esprima.parseModule(code);
13
+ const importer = srcPath.replace(basePath, "");
14
+ const importerDir = path.dirname(importer);
15
+ // console.log("-> ", importer);
16
+ tree.body.forEach(node => {
17
+ if (node.type === "ImportDeclaration") {
18
+ let importee = node.source.value;
19
+ if (importee.startsWith(".")) {
20
+ // add .js extension if missing
21
+ if (!importee.endsWith(".js")) {
22
+ node.source.value += ".js"
23
+ changed = true;
24
+ }
25
+ return;
26
+ }
27
+ let importeeDir = path.dirname(importee);
28
+ let importeeFile = path.basename(importee);
29
+ let relativePath = path.relative(importerDir, importeeDir);
30
+ if (relativePath.length === 0) {
31
+ relativePath = "."
32
+ }
33
+ if (!relativePath.startsWith(".")) {
34
+ relativePath = "./" + relativePath;
35
+ }
36
+
37
+ relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
38
+ let relativeImport = `${relativePath}/${importeeFile}.js`;
39
+ // console.log(importee + " --> " + relativeImport);
40
+ node.source.value = relativeImport;
41
+ changed = true;
42
+ }
43
+ });
44
+
45
+ if (changed) {
46
+ return fs.writeFile(srcPath, escodegen.generate(tree));
47
+ }
48
+ }
49
+
50
+ const generate = async () => {
51
+ const { globby } = await import("globby");
52
+ const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
53
+ return Promise.all(fileNames.map(convertImports).filter(x => !!x));
54
+ };
55
+
56
+ generate().then(() => {
57
+ console.log("Success: Converted absolute imports to relative for files in:", basePath);
58
+ });
@@ -0,0 +1,327 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+ // https://github.com/webcomponents/custom-elements-manifest/blob/main/schema.json
4
+
5
+ const inputDir = process.argv[2];
6
+ const outputDir = process.argv[3];
7
+
8
+ const camelToKebabMap = new Map();
9
+ const apiIndex = new Map();
10
+ const forbiddenAttributeTypes = ["object", "array"];
11
+
12
+ const camelToKebabCase = string => {
13
+ if (!camelToKebabMap.has(string)) {
14
+ const result = string.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
15
+ camelToKebabMap.set(string, result);
16
+ }
17
+ return camelToKebabMap.get(string);
18
+ };
19
+
20
+ const generateJavaScriptExport = entity => {
21
+ return {
22
+ declaration: generateRefenrece(entity.name),
23
+ deprecated: !!entity.deprecated,
24
+ kind: "js",
25
+ name: "default",
26
+ };
27
+ };
28
+
29
+ const generateCustomElementExport = entity => {
30
+ return {
31
+ declaration: {
32
+ name: entity.basename,
33
+ module: `${entity.module}.js`,
34
+ },
35
+ deprecated: !!entity.deprecated,
36
+ kind: "custom-element-definition",
37
+ name: entity.tagname,
38
+ };
39
+ };
40
+
41
+ const generateJavaScriptModule = entity => {
42
+ return {
43
+ kind: "javascript-module",
44
+ path: `${entity.basename}.js`,
45
+ declarations: [
46
+ generateCustomElementDeclaration(entity),
47
+ ],
48
+ exports: [
49
+ generateJavaScriptExport(entity),
50
+ generateCustomElementExport(entity),
51
+ ],
52
+ };
53
+ };
54
+
55
+ const generateSingleClassField = classField => {
56
+ let generatedClassField = {
57
+ deprecated: !!classField.deprecated,
58
+ kind: "field",
59
+ name: classField.name,
60
+ privacy: classField.visibility,
61
+ static: !!classField.static,
62
+ type: generateType(classField.type),
63
+ };
64
+
65
+ if (classField.defaultValue) {
66
+ generatedClassField.default = classField.defaultValue;
67
+ }
68
+
69
+ if (classField.description) {
70
+ generatedClassField.description = classField.description;
71
+ }
72
+
73
+ return generatedClassField;
74
+ };
75
+
76
+ const generateSingleParameter = parameter => {
77
+ let generatedParameter = {
78
+ deprecated: !!parameter.deprecated,
79
+ name: parameter.name,
80
+ type: generateType(parameter.type),
81
+ };
82
+
83
+ if (parameter.description) {
84
+ generatedParameter.description = parameter.description;
85
+ }
86
+
87
+ if (parameter.optional) {
88
+ generatedParameter.optional = parameter.optional;
89
+ }
90
+
91
+ return generatedParameter;
92
+ };
93
+
94
+ const generateParameters = (parameters) => {
95
+ return parameters.reduce((newParametersArray, parameter) => {
96
+ newParametersArray.push(generateSingleParameter(parameter));
97
+
98
+ return newParametersArray;
99
+ }, []);
100
+ };
101
+
102
+ const generateSingleClassMethod = classMethod => {
103
+ let generatedClassMethod = {
104
+ deprecated: !!classMethod.deprecated,
105
+ kind: "method",
106
+ name: classMethod.name,
107
+ privacy: classMethod.visibility,
108
+ static: classMethod.static,
109
+ };
110
+
111
+ if (classMethod.description) {
112
+ generatedClassMethod.description = classMethod.description;
113
+ }
114
+
115
+ if (classMethod.parameters && classMethod.parameters.length) {
116
+ generatedClassMethod.parameters = generateParameters(classMethod.parameters);
117
+ }
118
+
119
+ if (classMethod.returnValue) {
120
+ generatedClassMethod.return = {
121
+ type: generateType(classMethod.returnValue.type),
122
+ };
123
+
124
+ if (classMethod.returnValue.description) {
125
+ generatedClassMethod.return.description = classMethod.returnValue.type;
126
+ }
127
+ }
128
+
129
+ return generatedClassMethod;
130
+ };
131
+
132
+ const generateClassFields = classFields => {
133
+ return classFields.reduce((newClassFieldsArray, classField) => {
134
+ newClassFieldsArray.push(generateSingleClassField(classField));
135
+
136
+ return newClassFieldsArray;
137
+ }, []);
138
+ };
139
+
140
+ const generateClassMethods = classMethods => {
141
+ return classMethods.reduce((newClassMethodsArray, classMethod) => {
142
+ newClassMethodsArray.push(generateSingleClassMethod(classMethod));
143
+
144
+ return newClassMethodsArray;
145
+ }, []);
146
+ };
147
+
148
+ const generateMembers = (classFields, classMethods) => {
149
+ return [...generateClassFields(classFields), ...generateClassMethods(classMethods)];
150
+ };
151
+
152
+ const generateType = type => {
153
+ const dataType = apiIndex.get(type);
154
+
155
+ return {
156
+ text: dataType && dataType.name.includes(".types.") ?
157
+ filterPublicApi(dataType.properties)
158
+ .map(prop => `"${prop.name}"`)
159
+ .join(" | ") : type,
160
+ };
161
+ };
162
+
163
+ const generateSingleAttribute = attribute => {
164
+ let generatedAttribute = {
165
+ default: attribute.defaultValue,
166
+ deprecated: !!attribute.deprecated,
167
+ fieldName: attribute.name,
168
+ name: camelToKebabCase(attribute.name),
169
+ type: generateType(attribute.type),
170
+ };
171
+
172
+ if (attribute.description) {
173
+ generatedAttribute.description = attribute.description;
174
+ }
175
+
176
+ return generatedAttribute;
177
+ };
178
+
179
+ const generateAttributes = attributes => {
180
+ attributes = attributes.reduce((newAttributesArray, attribute) => {
181
+ newAttributesArray.push(generateSingleAttribute(attribute));
182
+
183
+ return newAttributesArray;
184
+ }, []);
185
+
186
+ return attributes;
187
+ };
188
+
189
+ const generateSingleEvent = event => {
190
+ let generatedEvent = {
191
+ deprecated: !!event.deprecated,
192
+ name: event.name,
193
+ type: event.native === "true" ? "NativeEvent" : "CustomEvent",
194
+ };
195
+
196
+ if (event.description) {
197
+ generatedEvent.description = event.description;
198
+ }
199
+
200
+ return generatedEvent;
201
+ };
202
+
203
+ const generateEvents = events => {
204
+ events = events.reduce((newEventsArray, event) => {
205
+ newEventsArray.push(generateSingleEvent(event));
206
+
207
+ return newEventsArray;
208
+ }, []);
209
+
210
+ return events;
211
+ };
212
+
213
+ const generateSingleSlot = slot => {
214
+ return {
215
+ deprecated: !!slot.deprecated,
216
+ description: slot.description,
217
+ name: slot.name,
218
+ };
219
+ };
220
+
221
+ const generateSlots = slots => {
222
+ slots = slots.reduce((newSlotsArray, event) => {
223
+ newSlotsArray.push(generateSingleSlot(event));
224
+
225
+ return newSlotsArray;
226
+ }, []);
227
+
228
+ return slots;
229
+ };
230
+
231
+ const generateCustomElementDeclaration = entity => {
232
+ let generatedCustomElementDeclaration = {
233
+ deprecated: !!entity.deprecated,
234
+ customElement: true,
235
+ kind: entity.basename,
236
+ name: entity.basename,
237
+ tagName: entity.tagname,
238
+ };
239
+
240
+ const slots = filterPublicApi(entity.slots);
241
+ const events = filterPublicApi(entity.events);
242
+ const classFields = filterPublicApi(entity.properties);
243
+ const classMethods = filterPublicApi(entity.methods);
244
+ const attributes = classFields.filter(property => {
245
+ return property.noattribute !== "true" && property.readonly !== "true" && !forbiddenAttributeTypes.includes(property.type.toLowerCase());
246
+ });
247
+
248
+ if (slots.length) {
249
+ generatedCustomElementDeclaration.slots = generateSlots(slots);
250
+ }
251
+
252
+ if (events.length) {
253
+ generatedCustomElementDeclaration.events = generateEvents(events);
254
+ }
255
+
256
+ if (attributes.length) {
257
+ generatedCustomElementDeclaration.attributes = generateAttributes(attributes);
258
+ }
259
+
260
+ if (entity.description) {
261
+ generatedCustomElementDeclaration.description = entity.description;
262
+ }
263
+
264
+ if (classFields.length || classMethods.length) {
265
+ generatedCustomElementDeclaration.members = generateMembers(classFields, classMethods);
266
+ }
267
+
268
+ if (entity.extends && entity.extends !== "HTMLElement") {
269
+ generatedCustomElementDeclaration.superclass = generateRefenrece(entity.extends);
270
+ }
271
+
272
+ return generatedCustomElementDeclaration;
273
+ };
274
+
275
+ const generateRefenrece = (entityName) => {
276
+ let packageName;
277
+ let basename;
278
+
279
+ if (!entityName) {
280
+ throw new Error("JSDoc error: entity not found in api.json.");
281
+ }
282
+
283
+ if (entityName.includes(".")) {
284
+ basename = entityName.split(".").pop();
285
+ } else {
286
+ basename = entityName
287
+ }
288
+
289
+ if (entityName.includes("sap.ui.webc.main")) {
290
+ packageName = "@ui5/webcomponents";
291
+ } else if (entityName.includes("sap.ui.webc.fiori")) {
292
+ packageName = "@ui5/webcomponents-fiori";
293
+ } else if (entityName.includes("sap.ui.webc.base")) {
294
+ packageName = "@ui5/webcomponents-base";
295
+ }
296
+
297
+ return {
298
+ module: `${basename}.js`,
299
+ name: `${basename}`,
300
+ package: packageName,
301
+ };
302
+ };
303
+
304
+ const filterPublicApi = array => {
305
+ return (array || []).filter(el => el.visibility === "public");
306
+ };
307
+
308
+ const generate = async () => {
309
+ const file = JSON.parse(await fs.readFile(path.join(inputDir, "api.json")));
310
+ let customElementsManifest = {
311
+ schemaVersion: "1.0.0",
312
+ readme: "",
313
+ modules: [],
314
+ };
315
+
316
+ file.symbols.forEach(entity => {
317
+ if (entity.tagname) {
318
+ customElementsManifest.modules.push(generateJavaScriptModule(entity));
319
+ }
320
+ });
321
+
322
+ await fs.writeFile(path.join(outputDir, "custom-elements.json"), JSON.stringify(customElementsManifest));
323
+ };
324
+
325
+ generate().then(() => {
326
+ console.log("Custom elements manifest generated.");
327
+ });
@@ -0,0 +1,72 @@
1
+ const fs = require("fs").promises;
2
+ const path = require('path');
3
+
4
+ const generate = async () => {
5
+ const fioriInputFolder = path.normalize(process.argv[2]);
6
+ const tntInputFolder = path.normalize(process.argv[3]);
7
+ const outputFile = path.normalize(`${process.argv[4]}/Illustrations.js`);
8
+
9
+ const dir = await fs.readdir(fioriInputFolder);
10
+ const fioriIllustrationsOnFileSystem = dir.map(illustrationName => {
11
+ const fioriMatches = illustrationName.match(/.*\.js$/);
12
+ return fioriMatches ? illustrationName : undefined;
13
+ }).filter(key => !!key);
14
+
15
+ const tntDir = await fs.readdir(tntInputFolder);
16
+ const tntIllustrationsOnFileSystem = tntDir.map(illustrationName => {
17
+ const tntMatches = illustrationName.match(/.*\.js$/);
18
+ return tntMatches ? illustrationName : undefined;
19
+ }).filter(key => !!key);
20
+
21
+ // dynamic imports for Fiori illustrations
22
+ const fioriAvailableIllustrationsArray = `[${fioriIllustrationsOnFileSystem.filter(
23
+ // skipping the items starting with sapIllus-Dialog, sapIllus-Scene, sapIllus-Spot since they are included in the illustration's js file
24
+ line => !line.startsWith("sapIllus-Dialog") && !line.startsWith("sapIllus-Scene") && !line.startsWith("sapIllus-Spot") && !line.startsWith("AllIllustrations")).map(illustrationName => `"${illustrationName.replace('.js', '')}"`).join(", ")}]`;
25
+
26
+ const fioriDynamicImportLines = fioriIllustrationsOnFileSystem.map(illustrationName =>
27
+ `\t\tcase "${illustrationName.replace('.js', '')}": return (await import("../../illustrations/${illustrationName}")).default;`).filter(
28
+ // skipping the items starting with sapIllus-Dialog, sapIllus-Scene, sapIllus-Spot since they are included in the illustration's js file
29
+ line => !line.startsWith("\t\tcase \"sapIllus-Dialog") && !line.startsWith("\t\tcase \"sapIllus-Scene") && !line.startsWith("\t\tcase \"sapIllus-Spot") && !line.startsWith("\t\tcase \"AllIllustrations")).join("\n");
30
+
31
+ // dynamic imports for Tnt illustrations
32
+ const tntAvailableIllustrationsArray = `[${tntIllustrationsOnFileSystem.filter(
33
+ // skipping the items starting with tnt-Dialog, tnt-Scene, tnt-Spot since they are included in the illustration's js file
34
+ line => !line.startsWith("tnt-Dialog") && !line.startsWith("tnt-Scene") && !line.startsWith("tnt-Spot")).map(illustrationName => `"Tnt${illustrationName.replace('.js', '')}"`).join(", ")}]`;
35
+
36
+ const tntDynamicImportLines = tntIllustrationsOnFileSystem.map(illustrationName =>
37
+ `\t\tcase "Tnt${illustrationName.replace('.js', '')}": return (await import("../../illustrations/tnt/${illustrationName}")).default;`).filter(
38
+ // skipping the items starting with tnt-Dialog, tnt-Scene, tnt-Spot since they are included in the illustration's js file
39
+ line => !line.startsWith("\t\tcase \"Tnttnt-Dialog") && !line.startsWith("\t\tcase \"Tnttnt-Scene") && !line.startsWith("\t\tcase \"Tnttnt-Spot")).join("\n");
40
+
41
+
42
+ // dynamic imports file content
43
+ const contentDynamic = `import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
44
+
45
+ const loadIllustration = async (illustrationName) => {
46
+ switch (illustrationName) {
47
+ ${fioriDynamicImportLines}
48
+ ${tntDynamicImportLines}
49
+ default: throw new Error("[Illustrations] Illustration not found: " + illustrationName);
50
+ }
51
+ };
52
+ const loadAndCheck = async (illustrationName) => {
53
+ const data = await loadIllustration(illustrationName);
54
+ return data;
55
+ }
56
+
57
+
58
+ ${fioriAvailableIllustrationsArray}.forEach(illustrationName => registerIllustrationLoader(illustrationName, loadAndCheck));
59
+ ${tntAvailableIllustrationsArray}.forEach(illustrationName => registerIllustrationLoader(illustrationName, loadAndCheck));`;
60
+
61
+
62
+ await fs.mkdir(path.dirname(outputFile), { recursive: true });
63
+ return Promise.all([fs.writeFile(outputFile, contentDynamic)]);
64
+ };
65
+
66
+ generate().then(() => {
67
+ console.log("Generated Illustrations.js");
68
+ })
69
+ .catch(err => {
70
+ console.error(err);
71
+ process.exit(1);
72
+ });
@@ -0,0 +1,98 @@
1
+ const fs = require("fs").promises;
2
+ const path = require('path');
3
+
4
+ const generate = async () => {
5
+
6
+ const packageName = JSON.parse(await fs.readFile("package.json")).name;
7
+
8
+ const inputFolder = path.normalize(process.argv[2]);
9
+ const outputFile = path.normalize(`${process.argv[3]}/i18n-static.js`);
10
+ const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.js`);
11
+
12
+ // All languages present in the file system
13
+ const files = await fs.readdir(inputFolder);
14
+ const languages = files.map(file => {
15
+ const matches = file.match(/messagebundle_(.+?).json$/);
16
+ return matches ? matches[1] : undefined;
17
+ }).filter(key => !!key);
18
+
19
+ let contentStatic, contentDynamic;
20
+
21
+ // No i18n - just import dependencies, if any
22
+ if (languages.length === 0) {
23
+ contentStatic = "";
24
+ contentDynamic = "";
25
+ // There is i18n - generate the full file
26
+ } else {
27
+ // Keys for the array
28
+ const languagesKeysString = languages.map(key => `"${key}": _${key},`).join("\n\t");
29
+ const languagesKeysStringArray = languages.map(key => `"${key}",`).join("\n\t");
30
+
31
+ // Actual imports for json assets
32
+ const assetsImportsString = languages.map(key => `import _${key} from "../assets/i18n/messagebundle_${key}.json";`).join("\n");
33
+
34
+ // static imports
35
+ contentStatic = `import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
36
+
37
+ ${assetsImportsString}
38
+
39
+ const bundleMap = {
40
+ ${languagesKeysString}
41
+ };
42
+
43
+ const fetchMessageBundle = async (localeId) => {
44
+ if (typeof bundleMap[localeId] === "object") {
45
+ // inlined from build
46
+ throw new Error("[i18n] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs")
47
+ }
48
+ return (await fetch(bundleMap[localeId])).json()
49
+ }
50
+
51
+ const localeIds = [${languagesKeysStringArray}];
52
+
53
+ localeIds.forEach(localeId => {
54
+ registerI18nLoader("${packageName}", localeId, fetchMessageBundle);
55
+ });
56
+ `;
57
+
58
+ // Actual imports for json assets
59
+ const dynamicImportsString = languages.map(key => ` case "${key}": return (await import("../assets/i18n/messagebundle_${key}.json")).default;`).join("\n");
60
+
61
+ // Resulting file content
62
+ contentDynamic = `import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
63
+
64
+ const importMessageBundle = async (localeId) => {
65
+ switch (localeId) {
66
+ ${dynamicImportsString}
67
+ default: throw "unknown locale"
68
+ }
69
+ }
70
+
71
+ const importAndCheck = async (localeId) => {
72
+ const data = await importMessageBundle(localeId);
73
+ if (typeof data === "string" && data.endsWith(".json")) {
74
+ throw new Error(\`[i18n] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build or use 'import ".../Assets-static.js"'. Check the \"Assets\" documentation for more information.\`);
75
+ }
76
+ return data;
77
+ }
78
+
79
+ const localeIds = [${languagesKeysStringArray}];
80
+
81
+ localeIds.forEach(localeId => {
82
+ registerI18nLoader("${packageName}", localeId, importAndCheck);
83
+ });
84
+ `;
85
+
86
+
87
+ }
88
+
89
+ await fs.mkdir(path.dirname(outputFile), { recursive: true });
90
+ return Promise.all([
91
+ fs.writeFile(outputFile, contentStatic),
92
+ fs.writeFile(outputFileDynamic, contentDynamic),
93
+ ]);
94
+ }
95
+
96
+ generate().then(() => {
97
+ console.log("Generated i18n JSON imports.");
98
+ });
@@ -0,0 +1,80 @@
1
+ const fs = require("fs").promises;
2
+ const path = require('path');
3
+ const assets = require("../../assets-meta.js");
4
+
5
+ const generate = async () => {
6
+ const inputFolder = path.normalize(process.argv[2]);
7
+ const outputFile = path.normalize(`${process.argv[3]}/Themes-static.js`);
8
+ const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes.js`);
9
+
10
+ // All supported optional themes
11
+ const allThemes = assets.themes.all;
12
+
13
+ // All themes present in the file system
14
+ const dirs = await fs.readdir(inputFolder);
15
+ const themesOnFileSystem = dirs.map(dir => {
16
+ const matches = dir.match(/sap_.*$/);
17
+ return matches ? dir : undefined;
18
+ }).filter(key => !!key && allThemes.includes(key));
19
+
20
+ const packageName = JSON.parse(await fs.readFile("package.json")).name;
21
+
22
+ const importLines = themesOnFileSystem.map(theme => `import ${theme} from "../assets/themes/${theme}/parameters-bundle.css.json";`).join("\n");
23
+ const themeUrlsByName = "{\n" + themesOnFileSystem.join(",\n") + "\n}";
24
+ const availableThemesArray = `[${themesOnFileSystem.map(theme => `"${theme}"`).join(", ")}]`;
25
+ const dynamicImportLines = themesOnFileSystem.map(theme => `\t\tcase "${theme}": return (await import("../assets/themes/${theme}/parameters-bundle.css.json")).default;`).join("\n");
26
+
27
+
28
+ // static imports file content
29
+ const contentStatic = `import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
30
+
31
+ ${importLines}
32
+
33
+ const themeUrlsByName = ${themeUrlsByName};
34
+ const isInlined = obj => typeof (obj) === "object";
35
+
36
+ const loadThemeProperties = async (themeName) => {
37
+ if (typeof themeUrlsByName[themeName] === "object") {
38
+ // inlined from build
39
+ throw new Error("[themes] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs");
40
+ }
41
+ return (await fetch(themeUrlsByName[themeName])).json();
42
+ };
43
+
44
+ ${availableThemesArray}
45
+ .forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadThemeProperties));
46
+ `;
47
+
48
+
49
+ // dynamic imports file content
50
+ const contentDynamic = `import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
51
+
52
+ const loadThemeProperties = async (themeName) => {
53
+ switch (themeName) {
54
+ ${dynamicImportLines}
55
+ default: throw "unknown theme"
56
+ }
57
+ };
58
+
59
+ const loadAndCheck = async (themeName) => {
60
+ const data = await loadThemeProperties(themeName);
61
+ if (typeof data === "string" && data.endsWith(".json")) {
62
+ throw new Error(\`[themes] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build or use 'import ".../Assets-static.js"'. Check the \"Assets\" documentation for more information.\`);
63
+ }
64
+ return data;
65
+ };
66
+
67
+ ${availableThemesArray}
68
+ .forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadAndCheck));
69
+ `;
70
+
71
+ await fs.mkdir(path.dirname(outputFile), { recursive: true });
72
+ return Promise.all([
73
+ fs.writeFile(outputFile, contentStatic),
74
+ fs.writeFile(outputFileDynamic, contentDynamic)
75
+ ]);
76
+ };
77
+
78
+ generate().then(() => {
79
+ console.log("Generated themes JSON imports.");
80
+ });
@@ -0,0 +1,3 @@
1
+ const hbs2lit = require("./src/compiler");
2
+
3
+ module.exports = hbs2lit;
@@ -0,0 +1,57 @@
1
+ const HTMLLitVisitor = require("./litVisitor2");
2
+ const PartialsVisitor = require("./partialsVisitor");
3
+ const Handlebars = require("handlebars/dist/handlebars.min.js");
4
+ const includesReplacer = require("./includesReplacer");
5
+ const svgProcessor = require("./svgProcessor");
6
+
7
+ const removeWhiteSpaces = (source) => {
8
+ return source
9
+ .replace(/\s*\r*\n+\s*/g, " ") // Replace new lines and all whitespace between them with a space
10
+ .replace(/\s*<\s*/g, "<") // Strip whitespace round <
11
+ .replace(/\s*>\s*/g, ">") // Strip whitespace round >
12
+ .replace(/}}\s+{{/g, "}}{{"); // Remove whitespace between }} and {{
13
+ };
14
+
15
+ const hbs2lit = async (file) => {
16
+ let sPreprocessed = await includesReplacer.replace(file);
17
+
18
+ sPreprocessed = removeWhiteSpaces(sPreprocessed);
19
+
20
+ // icons hack
21
+ if (sPreprocessed.startsWith("<g ") || sPreprocessed.startsWith("<g>")) {
22
+ return `
23
+ let block0 = () => {
24
+ return svg\`${sPreprocessed}\`
25
+ }`;
26
+ }
27
+
28
+ const ast = Handlebars.parse(sPreprocessed);
29
+
30
+ const pv = new PartialsVisitor();
31
+ const lv = new HTMLLitVisitor();
32
+
33
+ let result = "";
34
+
35
+ pv.accept(ast);
36
+ pv.modify(ast);
37
+
38
+ lv.accept(ast);
39
+
40
+ for (let key in lv.blocks) {
41
+ let block = lv.blocks[key];
42
+
43
+ if (block.match(/scopeTag/)) {
44
+ const matches = block.match(/^(.*?)( => )(.*?);$/);
45
+ const scopedCode = matches[3];
46
+ const normalCode = scopedCode.replace(/\${scopeTag\("/g, "").replace(/", tags, suffix\)}/g, "");
47
+ block = `${matches[1]}${matches[2]}suffix ? ${scopedCode} : ${normalCode};`;
48
+ }
49
+
50
+ result += block + "\n";
51
+ }
52
+
53
+ result = svgProcessor.process(result);
54
+ return result;
55
+ };
56
+
57
+ module.exports = hbs2lit;