@ui5/webcomponents-tools 0.0.0-4180fe799 → 0.0.0-4237771ff
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 +781 -0
- package/README.md +6 -6
- package/assets-meta.js +17 -4
- package/bin/dev.js +1 -5
- package/components-package/eslint.js +35 -0
- package/components-package/nps.js +103 -69
- package/components-package/postcss.components.js +1 -21
- package/components-package/postcss.themes.js +1 -26
- package/components-package/vite.config.js +13 -0
- package/components-package/wdio.js +405 -353
- package/components-package/wdio.sync.js +26 -2
- package/icons-collection/nps.js +13 -14
- package/lib/copy-and-watch/index.js +24 -1
- package/lib/copy-list/index.js +17 -17
- package/lib/create-icons/index.js +124 -72
- package/lib/create-illustrations/index.js +118 -38
- package/lib/create-new-component/index.js +71 -104
- package/lib/create-new-component/jsFileContentTemplate.js +73 -0
- package/lib/create-new-component/tsFileContentTemplate.js +80 -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 +46 -0
- package/lib/css-processors/shared.mjs +76 -0
- package/lib/dev-server/custom-hot-update-plugin.js +39 -0
- package/lib/dev-server/dev-server.js +66 -0
- package/lib/dev-server/virtual-index-html-plugin.js +52 -0
- package/lib/esm-abs-to-rel/index.js +17 -10
- package/lib/generate-custom-elements-manifest/index.js +327 -0
- package/lib/generate-js-imports/illustrations.js +86 -0
- package/lib/generate-json-imports/i18n.js +43 -31
- package/lib/generate-json-imports/themes.js +36 -24
- package/lib/hbs2lit/src/compiler.js +24 -4
- package/lib/hbs2lit/src/includesReplacer.js +5 -5
- package/lib/hbs2lit/src/litVisitor2.js +85 -22
- package/lib/hbs2lit/src/svgProcessor.js +12 -5
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
- package/lib/hbs2ui5/index.js +56 -23
- package/lib/i18n/defaults.js +65 -57
- package/lib/i18n/toJSON.js +12 -11
- package/lib/jsdoc/configTypescript.json +29 -0
- package/lib/jsdoc/plugin.js +41 -0
- package/lib/jsdoc/preprocess.js +146 -0
- package/lib/jsdoc/template/publish.js +21 -2
- package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
- package/lib/replace-global-core/index.js +13 -8
- package/lib/scoping/get-all-tags.js +2 -9
- package/lib/scoping/missing-dependencies.js +65 -0
- package/lib/scoping/report-tags-usage.js +28 -0
- package/lib/scoping/scope-test-pages.js +2 -1
- package/lib/test-runner/test-runner.js +71 -0
- package/package.json +27 -30
- package/components-package/rollup-plugins/empty-module.js +0 -15
- package/components-package/rollup.js +0 -239
- package/lib/documentation/index.js +0 -165
- package/lib/documentation/templates/api-component-since.js +0 -3
- package/lib/documentation/templates/api-css-variables-section.js +0 -24
- package/lib/documentation/templates/api-events-section.js +0 -35
- package/lib/documentation/templates/api-methods-section.js +0 -26
- package/lib/documentation/templates/api-properties-section.js +0 -40
- package/lib/documentation/templates/api-slots-section.js +0 -28
- package/lib/documentation/templates/template.js +0 -38
- package/lib/hash/config.js +0 -10
- package/lib/hash/generate.js +0 -19
- package/lib/hash/upToDate.js +0 -31
- package/lib/polyfill-placeholder/index.js +0 -5
- package/lib/postcss-css-to-esm/index.js +0 -45
- package/lib/postcss-css-to-json/index.js +0 -36
- package/lib/postcss-new-files/index.js +0 -36
- package/lib/serve/index.js +0 -46
- package/lib/serve/serve.json +0 -3
- package/package-lock.json +0 -48
@@ -0,0 +1,66 @@
|
|
1
|
+
const fs = require("fs/promises");
|
2
|
+
const { createServer } = require('vite');
|
3
|
+
const yargs = require('yargs/yargs')
|
4
|
+
const { hideBin } = require('yargs/helpers')
|
5
|
+
|
6
|
+
const argv = yargs(hideBin(process.argv))
|
7
|
+
.alias("c", "config")
|
8
|
+
.argv;
|
9
|
+
|
10
|
+
const startVite = async (port) => {
|
11
|
+
const server = await createServer({
|
12
|
+
configFile: argv.config,
|
13
|
+
server: {
|
14
|
+
port: port,
|
15
|
+
strictPort: true,
|
16
|
+
open: true,
|
17
|
+
host: true,
|
18
|
+
},
|
19
|
+
logLevel: 'info',
|
20
|
+
clearScreen: false,
|
21
|
+
})
|
22
|
+
await server.listen()
|
23
|
+
server.printUrls()
|
24
|
+
return server;
|
25
|
+
};
|
26
|
+
|
27
|
+
const rmPortFile = async () => {
|
28
|
+
// exit handler must be sync
|
29
|
+
try {
|
30
|
+
await fs.rm(".dev-server-port");
|
31
|
+
} catch (e) {}
|
32
|
+
process.exit();
|
33
|
+
}
|
34
|
+
|
35
|
+
["exit", "SIGINT", "SIGUSR1", "SIGUSR2", "uncaughtException", "SIGTERM"].forEach((eventType) => {
|
36
|
+
process.on(eventType, rmPortFile);
|
37
|
+
});
|
38
|
+
|
39
|
+
(async () => {
|
40
|
+
let retries = 10;
|
41
|
+
let port = 8080;
|
42
|
+
while (retries--) {
|
43
|
+
console.log(`taking port ${port}`);
|
44
|
+
await fs.writeFile(".dev-server-port", `${port}`);
|
45
|
+
try {
|
46
|
+
// execSync(command, {stdio: 'pipe'});
|
47
|
+
const server = await startVite(port);
|
48
|
+
if (server) {
|
49
|
+
// server started, don't try other ports
|
50
|
+
break;
|
51
|
+
}
|
52
|
+
} catch (e) {
|
53
|
+
// uncomment for debug
|
54
|
+
// console.log(e.toString());
|
55
|
+
if (e.toString().includes("already in use")) {
|
56
|
+
console.log(`Port ${port} already in use`)
|
57
|
+
port++;
|
58
|
+
continue;
|
59
|
+
}
|
60
|
+
// other error or CTRL-C
|
61
|
+
process.exit();
|
62
|
+
}
|
63
|
+
// no error normal exit
|
64
|
+
// process.exit();
|
65
|
+
}
|
66
|
+
})();
|
@@ -0,0 +1,52 @@
|
|
1
|
+
const virtualIndexPlugin = async () => {
|
2
|
+
const path = await import("path");
|
3
|
+
const { globby } = await import("globby");
|
4
|
+
const files = await globby(["test/pages/**/*.html", "packages/*/test/pages/**/*.html"]);
|
5
|
+
|
6
|
+
const pagesPerFolder = {};
|
7
|
+
files.forEach(file => {
|
8
|
+
let folder = pagesPerFolder[path.dirname(file)] = pagesPerFolder[path.dirname(file)] || [];
|
9
|
+
folder.push(path.basename(file));
|
10
|
+
});
|
11
|
+
|
12
|
+
const rollupInput = {};
|
13
|
+
|
14
|
+
files.forEach(file => {
|
15
|
+
rollupInput[file] = path.resolve(process.cwd(), file);
|
16
|
+
})
|
17
|
+
|
18
|
+
return {
|
19
|
+
name: 'virtual-index-html',
|
20
|
+
config() {
|
21
|
+
return {
|
22
|
+
build: {
|
23
|
+
rollupOptions: {
|
24
|
+
input: rollupInput
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
},
|
29
|
+
configureServer(server) {
|
30
|
+
server.middlewares.use((req, res, next) => {
|
31
|
+
if (req.url === "/") {
|
32
|
+
const folders = Object.keys(pagesPerFolder);
|
33
|
+
|
34
|
+
res.statusCode = 200;
|
35
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
36
|
+
res.end(`${folders.map(folder => {
|
37
|
+
const pages = pagesPerFolder[folder];
|
38
|
+
return `<h1>${folder}</h1>
|
39
|
+
${pages.map(page => {
|
40
|
+
return `<li><a href='${folder}/${page}'>${page}</a></li>`
|
41
|
+
}).join("")}
|
42
|
+
`
|
43
|
+
}).join("")}`);
|
44
|
+
} else {
|
45
|
+
next();
|
46
|
+
}
|
47
|
+
})
|
48
|
+
},
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
module.exports = virtualIndexPlugin;
|
@@ -1,15 +1,17 @@
|
|
1
1
|
const esprima = require("esprima");
|
2
2
|
const escodegen = require("escodegen");
|
3
3
|
|
4
|
-
const fs = require("fs");
|
4
|
+
const fs = require("fs").promises;
|
5
5
|
const path = require("path");
|
6
|
-
const glob = require("glob");
|
7
6
|
const basePath = process.argv[2];
|
8
7
|
|
9
|
-
const convertImports = (srcPath) => {
|
8
|
+
const convertImports = async (srcPath) => {
|
10
9
|
let changed = false;
|
11
|
-
|
12
|
-
|
10
|
+
let code = (await fs.readFile(srcPath)).toString();
|
11
|
+
if (code.includes("import(")) {
|
12
|
+
// esprima can't parse this, but it's from the project files
|
13
|
+
return;
|
14
|
+
}
|
13
15
|
const tree = esprima.parseModule(code);
|
14
16
|
const importer = srcPath.replace(basePath, "");
|
15
17
|
const importerDir = path.dirname(importer);
|
@@ -44,11 +46,16 @@ const convertImports = (srcPath) => {
|
|
44
46
|
});
|
45
47
|
|
46
48
|
if (changed) {
|
47
|
-
fs.
|
49
|
+
return fs.writeFile(srcPath, escodegen.generate(tree));
|
48
50
|
}
|
49
51
|
}
|
50
52
|
|
51
|
-
const
|
52
|
-
|
53
|
-
fileNames.
|
54
|
-
|
53
|
+
const generate = async () => {
|
54
|
+
const { globby } = await import("globby");
|
55
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
56
|
+
return Promise.all(fileNames.map(convertImports).filter(x => !!x));
|
57
|
+
};
|
58
|
+
|
59
|
+
generate().then(() => {
|
60
|
+
console.log("Success: Converted absolute imports to relative for files in:", basePath);
|
61
|
+
});
|
@@ -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 || entity.kind === "class") {
|
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,86 @@
|
|
1
|
+
const fs = require("fs").promises;
|
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, 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 = "${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(\`${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));
|
52
|
+
};
|
53
|
+
|
54
|
+
const generateIllustrations = async (config) => {
|
55
|
+
const { inputFolder, outputFile, collection, location, prefix, filterOut } = config;
|
56
|
+
|
57
|
+
const normalizedInputFolder = path.normalize(inputFolder);
|
58
|
+
const normalizedOutputFile = path.normalize(outputFile);
|
59
|
+
|
60
|
+
const illustrations = await getMatchingFiles(normalizedInputFolder, /^.*\.js$/);
|
61
|
+
|
62
|
+
const dynamicImports = await generateDynamicImportLines(illustrations, location, filterOut);
|
63
|
+
const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
|
64
|
+
|
65
|
+
const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, prefix);
|
66
|
+
|
67
|
+
await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
|
68
|
+
await fs.writeFile(normalizedOutputFile, contentDynamic);
|
69
|
+
|
70
|
+
console.log(`Generated ${normalizedOutputFile}`);
|
71
|
+
};
|
72
|
+
|
73
|
+
// Parse configuration from command-line arguments
|
74
|
+
const config = {
|
75
|
+
inputFolder: process.argv[2],
|
76
|
+
outputFile: process.argv[3],
|
77
|
+
collection: process.argv[4],
|
78
|
+
location: process.argv[5],
|
79
|
+
prefix: process.argv[6],
|
80
|
+
filterOut: process.argv.slice(7),
|
81
|
+
};
|
82
|
+
|
83
|
+
// Run the generation process
|
84
|
+
generateIllustrations(config).catch((error) => {
|
85
|
+
console.error("Error generating illustrations:", error);
|
86
|
+
});
|
@@ -1,37 +1,42 @@
|
|
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
|
-
const
|
4
|
+
const isTypeScript = process.env.UI5_TS;
|
5
|
+
const ext = isTypeScript ? 'ts' : 'js';
|
6
6
|
|
7
|
-
const
|
8
|
-
|
9
|
-
const
|
7
|
+
const generate = async () => {
|
8
|
+
|
9
|
+
const packageName = JSON.parse(await fs.readFile("package.json")).name;
|
10
|
+
|
11
|
+
const inputFolder = path.normalize(process.argv[2]);
|
12
|
+
const outputFile = path.normalize(`${process.argv[3]}/i18n-static.${ext}`);
|
13
|
+
const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.${ext}`);
|
10
14
|
|
11
15
|
// All languages present in the file system
|
12
|
-
const files = fs.
|
13
|
-
const languages = files.map(file => {
|
14
|
-
|
15
|
-
|
16
|
-
}).filter(key => !!key);
|
16
|
+
const files = await fs.readdir(inputFolder);
|
17
|
+
const languages = files.map(file => {
|
18
|
+
const matches = file.match(/messagebundle_(.+?).json$/);
|
19
|
+
return matches ? matches[1] : undefined;
|
20
|
+
}).filter(key => !!key);
|
17
21
|
|
18
|
-
let contentStatic, contentDynamic;
|
22
|
+
let contentStatic, contentDynamic;
|
19
23
|
|
20
24
|
// No i18n - just import dependencies, if any
|
21
|
-
if (languages.length === 0) {
|
22
|
-
|
23
|
-
|
25
|
+
if (languages.length === 0) {
|
26
|
+
contentStatic = "";
|
27
|
+
contentDynamic = "";
|
24
28
|
// There is i18n - generate the full file
|
25
|
-
} else {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
} else {
|
30
|
+
// Keys for the array
|
31
|
+
const languagesKeysString = languages.map(key => `"${key}": _${key},`).join("\n\t");
|
32
|
+
const languagesKeysStringArray = languages.map(key => `"${key}",`).join("\n\t");
|
29
33
|
|
30
|
-
|
31
|
-
|
34
|
+
// Actual imports for json assets
|
35
|
+
const assetsImportsString = languages.map(key => `import _${key} from "../assets/i18n/messagebundle_${key}.json";`).join("\n");
|
32
36
|
|
33
|
-
|
34
|
-
|
37
|
+
// static imports
|
38
|
+
contentStatic = `// @ts-nocheck
|
39
|
+
import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
|
35
40
|
|
36
41
|
${assetsImportsString}
|
37
42
|
|
@@ -54,11 +59,12 @@ localeIds.forEach(localeId => {
|
|
54
59
|
});
|
55
60
|
`;
|
56
61
|
|
57
|
-
|
58
|
-
|
62
|
+
// Actual imports for json assets
|
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");
|
59
64
|
|
60
|
-
|
61
|
-
|
65
|
+
// Resulting file content
|
66
|
+
contentDynamic = `// @ts-nocheck
|
67
|
+
import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
|
62
68
|
|
63
69
|
const importMessageBundle = async (localeId) => {
|
64
70
|
switch (localeId) {
|
@@ -83,9 +89,15 @@ localeIds.forEach(localeId => {
|
|
83
89
|
`;
|
84
90
|
|
85
91
|
|
86
|
-
}
|
92
|
+
}
|
87
93
|
|
94
|
+
await fs.mkdir(path.dirname(outputFile), { recursive: true });
|
95
|
+
return Promise.all([
|
96
|
+
fs.writeFile(outputFile, contentStatic),
|
97
|
+
fs.writeFile(outputFileDynamic, contentDynamic),
|
98
|
+
]);
|
99
|
+
}
|
88
100
|
|
89
|
-
|
90
|
-
|
91
|
-
|
101
|
+
generate().then(() => {
|
102
|
+
console.log("Generated i18n JSON imports.");
|
103
|
+
});
|