@ui5/webcomponents-tools 0.0.0-fc993d8cd → 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.
- package/CHANGELOG.md +623 -0
- package/README.md +2 -1
- package/assets-meta.js +15 -7
- package/components-package/eslint.js +2 -0
- package/components-package/nps.js +41 -32
- package/components-package/postcss.components.js +1 -21
- package/components-package/postcss.themes.js +1 -26
- package/components-package/wdio.js +15 -3
- package/components-package/wdio.sync.js +9 -1
- package/icons-collection/nps.js +8 -6
- package/lib/amd-to-es6/index.js +102 -0
- package/lib/amd-to-es6/no-remaining-require.js +33 -0
- package/lib/cem/custom-elements-manifest.config.mjs +501 -0
- package/lib/cem/event.mjs +131 -0
- package/lib/cem/schema-internal.json +1357 -0
- package/lib/cem/schema.json +1098 -0
- package/lib/cem/types-internal.d.ts +796 -0
- package/lib/cem/types.d.ts +736 -0
- package/lib/cem/utils.mjs +384 -0
- package/lib/cem/validate.js +70 -0
- package/lib/create-illustrations/index.js +51 -30
- package/lib/create-new-component/index.js +28 -58
- package/lib/create-new-component/jsFileContentTemplate.js +1 -5
- package/lib/create-new-component/tsFileContentTemplate.js +3 -16
- package/lib/css-processors/css-processor-component-styles.mjs +47 -0
- package/lib/css-processors/css-processor-components.mjs +77 -0
- package/lib/css-processors/css-processor-themes.mjs +79 -0
- package/lib/css-processors/scope-variables.mjs +49 -0
- package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
- package/lib/dev-server/custom-hot-update-plugin.js +39 -0
- package/lib/generate-custom-elements-manifest/index.js +51 -107
- package/lib/generate-js-imports/illustrations.js +78 -64
- package/lib/generate-json-imports/i18n.js +10 -5
- package/lib/generate-json-imports/themes.js +10 -5
- package/lib/hbs2lit/src/compiler.js +9 -6
- package/lib/hbs2lit/src/litVisitor2.js +42 -17
- package/lib/hbs2lit/src/svgProcessor.js +12 -5
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
- package/lib/hbs2ui5/index.js +21 -4
- package/lib/i18n/toJSON.js +1 -1
- package/lib/jsdoc/preprocess.js +3 -3
- package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
- package/lib/scoping/get-all-tags.js +1 -1
- package/lib/scoping/scope-test-pages.js +2 -1
- package/lib/test-runner/test-runner.js +2 -2
- package/package.json +13 -10
- package/lib/esm-abs-to-rel/index.js +0 -58
- package/lib/postcss-css-to-json/index.js +0 -47
- package/lib/postcss-new-files/index.js +0 -36
- package/lib/postcss-p/postcss-p.mjs +0 -14
- package/lib/replace-global-core/index.js +0 -25
@@ -5,61 +5,40 @@ const path = require("path");
|
|
5
5
|
const inputDir = process.argv[2];
|
6
6
|
const outputDir = process.argv[3];
|
7
7
|
|
8
|
-
const
|
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
|
-
};
|
8
|
+
const moduleDeclarations = new Map();
|
19
9
|
|
20
10
|
const generateJavaScriptExport = entity => {
|
21
11
|
return {
|
22
|
-
declaration:
|
23
|
-
|
12
|
+
declaration: {
|
13
|
+
name: entity.basename,
|
14
|
+
module: `dist/${entity.resource}`,
|
15
|
+
},
|
24
16
|
kind: "js",
|
25
17
|
name: "default",
|
26
18
|
};
|
27
19
|
};
|
28
20
|
|
29
21
|
const generateCustomElementExport = entity => {
|
22
|
+
if (!entity.tagname) return;
|
23
|
+
|
30
24
|
return {
|
31
25
|
declaration: {
|
32
26
|
name: entity.basename,
|
33
|
-
module:
|
27
|
+
module: `dist/${entity.resource}`,
|
34
28
|
},
|
35
|
-
deprecated: !!entity.deprecated,
|
36
29
|
kind: "custom-element-definition",
|
37
|
-
name: entity.
|
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
|
-
],
|
30
|
+
name: entity.basename,
|
52
31
|
};
|
53
32
|
};
|
54
33
|
|
55
34
|
const generateSingleClassField = classField => {
|
56
35
|
let generatedClassField = {
|
57
|
-
deprecated: !!classField.deprecated,
|
58
36
|
kind: "field",
|
59
37
|
name: classField.name,
|
60
|
-
privacy: classField.visibility,
|
61
|
-
static: !!classField.static,
|
62
38
|
type: generateType(classField.type),
|
39
|
+
privacy: classField.visibility,
|
40
|
+
deprecated: !!classField.deprecated || undefined,
|
41
|
+
static: !!classField.static || undefined,
|
63
42
|
};
|
64
43
|
|
65
44
|
if (classField.defaultValue) {
|
@@ -75,7 +54,7 @@ const generateSingleClassField = classField => {
|
|
75
54
|
|
76
55
|
const generateSingleParameter = parameter => {
|
77
56
|
let generatedParameter = {
|
78
|
-
deprecated: !!parameter.deprecated,
|
57
|
+
deprecated: !!parameter.deprecated || undefined,
|
79
58
|
name: parameter.name,
|
80
59
|
type: generateType(parameter.type),
|
81
60
|
};
|
@@ -86,6 +65,7 @@ const generateSingleParameter = parameter => {
|
|
86
65
|
|
87
66
|
if (parameter.optional) {
|
88
67
|
generatedParameter.optional = parameter.optional;
|
68
|
+
generatedParameter.default = parameter.defaultValue;
|
89
69
|
}
|
90
70
|
|
91
71
|
return generatedParameter;
|
@@ -101,7 +81,7 @@ const generateParameters = (parameters) => {
|
|
101
81
|
|
102
82
|
const generateSingleClassMethod = classMethod => {
|
103
83
|
let generatedClassMethod = {
|
104
|
-
deprecated: !!classMethod.deprecated,
|
84
|
+
deprecated: !!classMethod.deprecated || undefined,
|
105
85
|
kind: "method",
|
106
86
|
name: classMethod.name,
|
107
87
|
privacy: classMethod.visibility,
|
@@ -122,7 +102,7 @@ const generateSingleClassMethod = classMethod => {
|
|
122
102
|
};
|
123
103
|
|
124
104
|
if (classMethod.returnValue.description) {
|
125
|
-
generatedClassMethod.return.description = classMethod.returnValue.
|
105
|
+
generatedClassMethod.return.description = classMethod.returnValue.description;
|
126
106
|
}
|
127
107
|
}
|
128
108
|
|
@@ -150,47 +130,16 @@ const generateMembers = (classFields, classMethods) => {
|
|
150
130
|
};
|
151
131
|
|
152
132
|
const generateType = type => {
|
153
|
-
const dataType = apiIndex.get(type);
|
154
|
-
|
155
133
|
return {
|
156
|
-
text:
|
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),
|
134
|
+
text: type,
|
170
135
|
};
|
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
136
|
};
|
188
137
|
|
189
138
|
const generateSingleEvent = event => {
|
190
139
|
let generatedEvent = {
|
191
|
-
deprecated: !!event.deprecated,
|
140
|
+
deprecated: !!event.deprecated || undefined,
|
192
141
|
name: event.name,
|
193
|
-
type: event.native === "true" ? "NativeEvent" : "CustomEvent"
|
142
|
+
type: generateType(event.native === "true" ? "NativeEvent" : "CustomEvent")
|
194
143
|
};
|
195
144
|
|
196
145
|
if (event.description) {
|
@@ -212,7 +161,7 @@ const generateEvents = events => {
|
|
212
161
|
|
213
162
|
const generateSingleSlot = slot => {
|
214
163
|
return {
|
215
|
-
deprecated: !!slot.deprecated,
|
164
|
+
deprecated: !!slot.deprecated || undefined,
|
216
165
|
description: slot.description,
|
217
166
|
name: slot.name,
|
218
167
|
};
|
@@ -230,9 +179,9 @@ const generateSlots = slots => {
|
|
230
179
|
|
231
180
|
const generateCustomElementDeclaration = entity => {
|
232
181
|
let generatedCustomElementDeclaration = {
|
233
|
-
deprecated: !!entity.deprecated,
|
182
|
+
deprecated: !!entity.deprecated || undefined,
|
234
183
|
customElement: true,
|
235
|
-
kind: entity.
|
184
|
+
kind: entity.kind,
|
236
185
|
name: entity.basename,
|
237
186
|
tagName: entity.tagname,
|
238
187
|
};
|
@@ -241,9 +190,6 @@ const generateCustomElementDeclaration = entity => {
|
|
241
190
|
const events = filterPublicApi(entity.events);
|
242
191
|
const classFields = filterPublicApi(entity.properties);
|
243
192
|
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
193
|
|
248
194
|
if (slots.length) {
|
249
195
|
generatedCustomElementDeclaration.slots = generateSlots(slots);
|
@@ -253,10 +199,6 @@ const generateCustomElementDeclaration = entity => {
|
|
253
199
|
generatedCustomElementDeclaration.events = generateEvents(events);
|
254
200
|
}
|
255
201
|
|
256
|
-
if (attributes.length) {
|
257
|
-
generatedCustomElementDeclaration.attributes = generateAttributes(attributes);
|
258
|
-
}
|
259
|
-
|
260
202
|
if (entity.description) {
|
261
203
|
generatedCustomElementDeclaration.description = entity.description;
|
262
204
|
}
|
@@ -273,31 +215,8 @@ const generateCustomElementDeclaration = entity => {
|
|
273
215
|
};
|
274
216
|
|
275
217
|
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
218
|
return {
|
298
|
-
|
299
|
-
name: `${basename}`,
|
300
|
-
package: packageName,
|
219
|
+
name: entityName,
|
301
220
|
};
|
302
221
|
};
|
303
222
|
|
@@ -313,12 +232,37 @@ const generate = async () => {
|
|
313
232
|
modules: [],
|
314
233
|
};
|
315
234
|
|
316
|
-
file.symbols.forEach(entity => {
|
317
|
-
|
318
|
-
|
235
|
+
filterPublicApi(file.symbols).forEach(entity => {
|
236
|
+
let declaration = moduleDeclarations.get(entity.resource);
|
237
|
+
|
238
|
+
if (!declaration) {
|
239
|
+
moduleDeclarations.set(entity.resource, {
|
240
|
+
declarations: [],
|
241
|
+
exports: [],
|
242
|
+
});
|
243
|
+
declaration = moduleDeclarations.get(entity.resource);
|
244
|
+
}
|
245
|
+
|
246
|
+
if (entity.kind === "class" && entity.tagname) {
|
247
|
+
declaration.declarations.push(generateCustomElementDeclaration(entity));
|
248
|
+
declaration.exports.push(generateJavaScriptExport(entity));
|
249
|
+
declaration.exports.push(generateCustomElementExport(entity));
|
250
|
+
} else if (entity.kind === "class" && entity.static) {
|
251
|
+
declaration.exports.push(generateJavaScriptExport(entity));
|
319
252
|
}
|
320
253
|
});
|
321
254
|
|
255
|
+
[...moduleDeclarations.keys()].forEach(key => {
|
256
|
+
let declaration = moduleDeclarations.get(key);
|
257
|
+
|
258
|
+
customElementsManifest.modules.push({
|
259
|
+
kind: "javascript-module",
|
260
|
+
path: `dist/${key}`,
|
261
|
+
declarations: declaration.declarations,
|
262
|
+
exports: declaration.exports
|
263
|
+
})
|
264
|
+
})
|
265
|
+
|
322
266
|
await fs.writeFile(path.join(outputDir, "custom-elements.json"), JSON.stringify(customElementsManifest));
|
323
267
|
};
|
324
268
|
|
@@ -1,72 +1,86 @@
|
|
1
1
|
const fs = require("fs").promises;
|
2
|
-
const path = require(
|
3
|
-
|
4
|
-
const
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
2
|
+
const path = require("path");
|
3
|
+
|
4
|
+
const generateDynamicImportLines = async (fileNames, location, exclusionPatterns = []) => {
|
5
|
+
const packageName = JSON.parse(await fs.readFile("package.json")).name;
|
6
|
+
return fileNames
|
7
|
+
.filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
|
8
|
+
.map((fileName) => {
|
9
|
+
const illustrationName = fileName.replace(".js", "");
|
10
|
+
const illustrationPath = `${location}/${illustrationName}`;
|
11
|
+
return `\t\tcase "${fileName.replace('.js', '')}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-${illustrationName.toLowerCase()}" */ "${illustrationPath}.js")).default;`;
|
12
|
+
})
|
13
|
+
.join("\n");
|
14
|
+
};
|
15
|
+
|
16
|
+
const generateAvailableIllustrationsArray = (fileNames, exclusionPatterns = []) => {
|
17
|
+
return JSON.stringify(
|
18
|
+
fileNames
|
19
|
+
.filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
|
20
|
+
.map((fileName) => fileName.replace(".js", ""))
|
21
|
+
);
|
22
|
+
};
|
23
|
+
|
24
|
+
const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, set, prefix = "") => {
|
25
|
+
return `// @ts-nocheck
|
26
|
+
import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
|
27
|
+
|
28
|
+
export const loadIllustration = async (illustrationName) => {
|
29
|
+
const collectionAndPrefix = "${set}/${collection}/${prefix}";
|
30
|
+
const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
|
31
|
+
switch (cleanIllustrationName) {
|
32
|
+
${dynamicImports}
|
33
|
+
default:
|
34
|
+
throw new Error("[Illustrations] Illustration not found: " + illustrationName);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
const loadAndCheck = async (illustrationName) => {
|
39
|
+
const data = await loadIllustration(illustrationName);
|
40
|
+
return data;
|
41
|
+
};
|
42
|
+
|
43
|
+
${availableIllustrations}.forEach((illustrationName) =>
|
44
|
+
registerIllustrationLoader(\`${set}/${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
|
45
|
+
);
|
46
|
+
`;
|
47
|
+
};
|
48
|
+
|
49
|
+
const getMatchingFiles = async (folder, pattern) => {
|
50
|
+
const dir = await fs.readdir(folder);
|
51
|
+
return dir.filter((fileName) => fileName.match(pattern));
|
51
52
|
};
|
52
|
-
const loadAndCheck = async (illustrationName) => {
|
53
|
-
const data = await loadIllustration(illustrationName);
|
54
|
-
return data;
|
55
|
-
}
|
56
53
|
|
54
|
+
const generateIllustrations = async (config) => {
|
55
|
+
const { inputFolder, outputFile, collection, location, prefix, filterOut, set } = config;
|
56
|
+
|
57
|
+
const normalizedInputFolder = path.normalize(inputFolder);
|
58
|
+
const normalizedOutputFile = path.normalize(outputFile);
|
59
|
+
|
60
|
+
const illustrations = await getMatchingFiles(normalizedInputFolder, /^.*\.js$/);
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
|
62
|
+
const dynamicImports = await generateDynamicImportLines(illustrations, location, filterOut);
|
63
|
+
const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
|
64
|
+
|
65
|
+
const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, set, prefix);
|
66
|
+
|
67
|
+
await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
|
68
|
+
await fs.writeFile(normalizedOutputFile, contentDynamic);
|
69
|
+
|
70
|
+
console.log(`Generated ${normalizedOutputFile}`);
|
71
|
+
};
|
61
72
|
|
62
|
-
|
63
|
-
|
73
|
+
// Parse configuration from command-line arguments
|
74
|
+
const config = {
|
75
|
+
inputFolder: process.argv[2],
|
76
|
+
outputFile: process.argv[3],
|
77
|
+
set: process.argv[4],
|
78
|
+
collection: process.argv[5],
|
79
|
+
location: process.argv[6],
|
80
|
+
filterOut: process.argv.slice[7],
|
64
81
|
};
|
65
82
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
.catch(err => {
|
70
|
-
console.error(err);
|
71
|
-
process.exit(1);
|
83
|
+
// Run the generation process
|
84
|
+
generateIllustrations(config).catch((error) => {
|
85
|
+
console.error("Error generating illustrations:", error);
|
72
86
|
});
|
@@ -1,13 +1,16 @@
|
|
1
1
|
const fs = require("fs").promises;
|
2
2
|
const path = require('path');
|
3
3
|
|
4
|
+
const isTypeScript = process.env.UI5_TS;
|
5
|
+
const ext = isTypeScript ? 'ts' : 'js';
|
6
|
+
|
4
7
|
const generate = async () => {
|
5
8
|
|
6
9
|
const packageName = JSON.parse(await fs.readFile("package.json")).name;
|
7
10
|
|
8
11
|
const inputFolder = path.normalize(process.argv[2]);
|
9
|
-
const outputFile = path.normalize(`${process.argv[3]}/i18n-static
|
10
|
-
const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n
|
12
|
+
const outputFile = path.normalize(`${process.argv[3]}/i18n-static.${ext}`);
|
13
|
+
const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.${ext}`);
|
11
14
|
|
12
15
|
// All languages present in the file system
|
13
16
|
const files = await fs.readdir(inputFolder);
|
@@ -32,7 +35,8 @@ const generate = async () => {
|
|
32
35
|
const assetsImportsString = languages.map(key => `import _${key} from "../assets/i18n/messagebundle_${key}.json";`).join("\n");
|
33
36
|
|
34
37
|
// static imports
|
35
|
-
contentStatic =
|
38
|
+
contentStatic = `// @ts-nocheck
|
39
|
+
import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
|
36
40
|
|
37
41
|
${assetsImportsString}
|
38
42
|
|
@@ -56,10 +60,11 @@ localeIds.forEach(localeId => {
|
|
56
60
|
`;
|
57
61
|
|
58
62
|
// Actual imports for json assets
|
59
|
-
const dynamicImportsString = languages.map(key => ` case "${key}": return (await import("../assets/i18n/messagebundle_${key}.json")).default;`).join("\n");
|
63
|
+
const dynamicImportsString = languages.map(key => ` case "${key}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-messagebundle-${key}" */ "../assets/i18n/messagebundle_${key}.json")).default;`).join("\n");
|
60
64
|
|
61
65
|
// Resulting file content
|
62
|
-
contentDynamic =
|
66
|
+
contentDynamic = `// @ts-nocheck
|
67
|
+
import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
|
63
68
|
|
64
69
|
const importMessageBundle = async (localeId) => {
|
65
70
|
switch (localeId) {
|
@@ -2,10 +2,13 @@ const fs = require("fs").promises;
|
|
2
2
|
const path = require('path');
|
3
3
|
const assets = require("../../assets-meta.js");
|
4
4
|
|
5
|
+
const isTypeScript = process.env.UI5_TS;
|
6
|
+
const ext = isTypeScript ? 'ts' : 'js';
|
7
|
+
|
5
8
|
const generate = async () => {
|
6
9
|
const inputFolder = path.normalize(process.argv[2]);
|
7
|
-
const outputFile = path.normalize(`${process.argv[3]}/Themes-static
|
8
|
-
const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes
|
10
|
+
const outputFile = path.normalize(`${process.argv[3]}/Themes-static.${ext}`);
|
11
|
+
const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes.${ext}`);
|
9
12
|
|
10
13
|
// All supported optional themes
|
11
14
|
const allThemes = assets.themes.all;
|
@@ -22,11 +25,12 @@ const generate = async () => {
|
|
22
25
|
const importLines = themesOnFileSystem.map(theme => `import ${theme} from "../assets/themes/${theme}/parameters-bundle.css.json";`).join("\n");
|
23
26
|
const themeUrlsByName = "{\n" + themesOnFileSystem.join(",\n") + "\n}";
|
24
27
|
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");
|
28
|
+
const dynamicImportLines = themesOnFileSystem.map(theme => `\t\tcase "${theme}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-${theme.replace("_", "-")}-parameters-bundle" */"../assets/themes/${theme}/parameters-bundle.css.json")).default;`).join("\n");
|
26
29
|
|
27
30
|
|
28
31
|
// static imports file content
|
29
|
-
const contentStatic =
|
32
|
+
const contentStatic = `// @ts-nocheck
|
33
|
+
import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
|
30
34
|
|
31
35
|
${importLines}
|
32
36
|
|
@@ -47,7 +51,8 @@ ${availableThemesArray}
|
|
47
51
|
|
48
52
|
|
49
53
|
// dynamic imports file content
|
50
|
-
const contentDynamic =
|
54
|
+
const contentDynamic = `// @ts-nocheck
|
55
|
+
import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
|
51
56
|
|
52
57
|
const loadThemeProperties = async (themeName) => {
|
53
58
|
switch (themeName) {
|
@@ -12,15 +12,17 @@ const removeWhiteSpaces = (source) => {
|
|
12
12
|
.replace(/}}\s+{{/g, "}}{{"); // Remove whitespace between }} and {{
|
13
13
|
};
|
14
14
|
|
15
|
-
const hbs2lit = async (file) => {
|
15
|
+
const hbs2lit = async (file, componentName) => {
|
16
16
|
let sPreprocessed = await includesReplacer.replace(file);
|
17
17
|
|
18
18
|
sPreprocessed = removeWhiteSpaces(sPreprocessed);
|
19
19
|
|
20
|
+
const blockSignature = process.env.UI5_TS ? `this: ${componentName}` : ""
|
21
|
+
|
20
22
|
// icons hack
|
21
23
|
if (sPreprocessed.startsWith("<g ") || sPreprocessed.startsWith("<g>")) {
|
22
24
|
return `
|
23
|
-
|
25
|
+
function block0 (${blockSignature}) {
|
24
26
|
return svg\`${sPreprocessed}\`
|
25
27
|
}`;
|
26
28
|
}
|
@@ -28,7 +30,7 @@ const hbs2lit = async (file) => {
|
|
28
30
|
const ast = Handlebars.parse(sPreprocessed);
|
29
31
|
|
30
32
|
const pv = new PartialsVisitor();
|
31
|
-
const lv = new HTMLLitVisitor();
|
33
|
+
const lv = new HTMLLitVisitor(componentName);
|
32
34
|
|
33
35
|
let result = "";
|
34
36
|
|
@@ -41,10 +43,11 @@ const hbs2lit = async (file) => {
|
|
41
43
|
let block = lv.blocks[key];
|
42
44
|
|
43
45
|
if (block.match(/scopeTag/)) {
|
44
|
-
const matches = block.match(/^(.*?)( => )(.*?);$/);
|
45
|
-
const
|
46
|
+
// const matches = block.match(/^(.*?)( => )(.*?);$/);
|
47
|
+
const matches = block.match(/^(function .*? \{ return )(.*?);\}$/);
|
48
|
+
const scopedCode = matches[2];
|
46
49
|
const normalCode = scopedCode.replace(/\${scopeTag\("/g, "").replace(/", tags, suffix\)}/g, "");
|
47
|
-
block = `${matches[1]}
|
50
|
+
block = `${matches[1]}suffix ? ${scopedCode} : ${normalCode};}`;
|
48
51
|
}
|
49
52
|
|
50
53
|
result += block + "\n";
|