@ui5/webcomponents-tools 0.0.0-7c7170d4a → 0.0.0-7d8c57f70

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.
@@ -0,0 +1,271 @@
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 moduleDeclarations = new Map();
9
+
10
+ const generateJavaScriptExport = entity => {
11
+ return {
12
+ declaration: {
13
+ name: entity.basename,
14
+ module: `dist/${entity.resource}`,
15
+ },
16
+ kind: "js",
17
+ name: "default",
18
+ };
19
+ };
20
+
21
+ const generateCustomElementExport = entity => {
22
+ if (!entity.tagname) return;
23
+
24
+ return {
25
+ declaration: {
26
+ name: entity.basename,
27
+ module: `dist/${entity.resource}`,
28
+ },
29
+ kind: "custom-element-definition",
30
+ name: entity.basename,
31
+ };
32
+ };
33
+
34
+ const generateSingleClassField = classField => {
35
+ let generatedClassField = {
36
+ kind: "field",
37
+ name: classField.name,
38
+ type: generateType(classField.type),
39
+ privacy: classField.visibility,
40
+ deprecated: !!classField.deprecated || undefined,
41
+ static: !!classField.static || undefined,
42
+ };
43
+
44
+ if (classField.defaultValue) {
45
+ generatedClassField.default = classField.defaultValue;
46
+ }
47
+
48
+ if (classField.description) {
49
+ generatedClassField.description = classField.description;
50
+ }
51
+
52
+ return generatedClassField;
53
+ };
54
+
55
+ const generateSingleParameter = parameter => {
56
+ let generatedParameter = {
57
+ deprecated: !!parameter.deprecated || undefined,
58
+ name: parameter.name,
59
+ type: generateType(parameter.type),
60
+ };
61
+
62
+ if (parameter.description) {
63
+ generatedParameter.description = parameter.description;
64
+ }
65
+
66
+ if (parameter.optional) {
67
+ generatedParameter.optional = parameter.optional;
68
+ generatedParameter.default = parameter.defaultValue;
69
+ }
70
+
71
+ return generatedParameter;
72
+ };
73
+
74
+ const generateParameters = (parameters) => {
75
+ return parameters.reduce((newParametersArray, parameter) => {
76
+ newParametersArray.push(generateSingleParameter(parameter));
77
+
78
+ return newParametersArray;
79
+ }, []);
80
+ };
81
+
82
+ const generateSingleClassMethod = classMethod => {
83
+ let generatedClassMethod = {
84
+ deprecated: !!classMethod.deprecated || undefined,
85
+ kind: "method",
86
+ name: classMethod.name,
87
+ privacy: classMethod.visibility,
88
+ static: classMethod.static,
89
+ };
90
+
91
+ if (classMethod.description) {
92
+ generatedClassMethod.description = classMethod.description;
93
+ }
94
+
95
+ if (classMethod.parameters && classMethod.parameters.length) {
96
+ generatedClassMethod.parameters = generateParameters(classMethod.parameters);
97
+ }
98
+
99
+ if (classMethod.returnValue) {
100
+ generatedClassMethod.return = {
101
+ type: generateType(classMethod.returnValue.type),
102
+ };
103
+
104
+ if (classMethod.returnValue.description) {
105
+ generatedClassMethod.return.description = classMethod.returnValue.description;
106
+ }
107
+ }
108
+
109
+ return generatedClassMethod;
110
+ };
111
+
112
+ const generateClassFields = classFields => {
113
+ return classFields.reduce((newClassFieldsArray, classField) => {
114
+ newClassFieldsArray.push(generateSingleClassField(classField));
115
+
116
+ return newClassFieldsArray;
117
+ }, []);
118
+ };
119
+
120
+ const generateClassMethods = classMethods => {
121
+ return classMethods.reduce((newClassMethodsArray, classMethod) => {
122
+ newClassMethodsArray.push(generateSingleClassMethod(classMethod));
123
+
124
+ return newClassMethodsArray;
125
+ }, []);
126
+ };
127
+
128
+ const generateMembers = (classFields, classMethods) => {
129
+ return [...generateClassFields(classFields), ...generateClassMethods(classMethods)];
130
+ };
131
+
132
+ const generateType = type => {
133
+ return {
134
+ text: type,
135
+ };
136
+ };
137
+
138
+ const generateSingleEvent = event => {
139
+ let generatedEvent = {
140
+ deprecated: !!event.deprecated || undefined,
141
+ name: event.name,
142
+ type: generateType(event.native === "true" ? "NativeEvent" : "CustomEvent")
143
+ };
144
+
145
+ if (event.description) {
146
+ generatedEvent.description = event.description;
147
+ }
148
+
149
+ return generatedEvent;
150
+ };
151
+
152
+ const generateEvents = events => {
153
+ events = events.reduce((newEventsArray, event) => {
154
+ newEventsArray.push(generateSingleEvent(event));
155
+
156
+ return newEventsArray;
157
+ }, []);
158
+
159
+ return events;
160
+ };
161
+
162
+ const generateSingleSlot = slot => {
163
+ return {
164
+ deprecated: !!slot.deprecated || undefined,
165
+ description: slot.description,
166
+ name: slot.name,
167
+ };
168
+ };
169
+
170
+ const generateSlots = slots => {
171
+ slots = slots.reduce((newSlotsArray, event) => {
172
+ newSlotsArray.push(generateSingleSlot(event));
173
+
174
+ return newSlotsArray;
175
+ }, []);
176
+
177
+ return slots;
178
+ };
179
+
180
+ const generateCustomElementDeclaration = entity => {
181
+ let generatedCustomElementDeclaration = {
182
+ deprecated: !!entity.deprecated || undefined,
183
+ customElement: true,
184
+ kind: entity.kind,
185
+ name: entity.basename,
186
+ tagName: entity.tagname,
187
+ };
188
+
189
+ const slots = filterPublicApi(entity.slots);
190
+ const events = filterPublicApi(entity.events);
191
+ const classFields = filterPublicApi(entity.properties);
192
+ const classMethods = filterPublicApi(entity.methods);
193
+
194
+ if (slots.length) {
195
+ generatedCustomElementDeclaration.slots = generateSlots(slots);
196
+ }
197
+
198
+ if (events.length) {
199
+ generatedCustomElementDeclaration.events = generateEvents(events);
200
+ }
201
+
202
+ if (entity.description) {
203
+ generatedCustomElementDeclaration.description = entity.description;
204
+ }
205
+
206
+ if (classFields.length || classMethods.length) {
207
+ generatedCustomElementDeclaration.members = generateMembers(classFields, classMethods);
208
+ }
209
+
210
+ if (entity.extends && entity.extends !== "HTMLElement") {
211
+ generatedCustomElementDeclaration.superclass = generateRefenrece(entity.extends);
212
+ }
213
+
214
+ return generatedCustomElementDeclaration;
215
+ };
216
+
217
+ const generateRefenrece = (entityName) => {
218
+ return {
219
+ name: entityName,
220
+ };
221
+ };
222
+
223
+ const filterPublicApi = array => {
224
+ return (array || []).filter(el => el.visibility === "public");
225
+ };
226
+
227
+ const generate = async () => {
228
+ const file = JSON.parse(await fs.readFile(path.join(inputDir, "api.json")));
229
+ let customElementsManifest = {
230
+ schemaVersion: "1.0.0",
231
+ readme: "",
232
+ modules: [],
233
+ };
234
+
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));
252
+ }
253
+ });
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
+
266
+ await fs.writeFile(path.join(outputDir, "custom-elements.json"), JSON.stringify(customElementsManifest));
267
+ };
268
+
269
+ generate().then(() => {
270
+ console.log("Custom elements manifest generated.");
271
+ });
@@ -9,6 +9,7 @@ const generate = async () => {
9
9
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
10
10
 
11
11
  const inputFolder = path.normalize(process.argv[2]);
12
+ const outputFile = path.normalize(`${process.argv[3]}/i18n-static.${ext}`);
12
13
  const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.${ext}`);
13
14
 
14
15
  // All languages present in the file system
@@ -18,16 +19,46 @@ const generate = async () => {
18
19
  return matches ? matches[1] : undefined;
19
20
  }).filter(key => !!key);
20
21
 
21
- let contentDynamic;
22
+ let contentStatic, contentDynamic;
22
23
 
23
24
  // No i18n - just import dependencies, if any
24
25
  if (languages.length === 0) {
26
+ contentStatic = "";
25
27
  contentDynamic = "";
26
28
  // There is i18n - generate the full file
27
29
  } else {
28
30
  // Keys for the array
31
+ const languagesKeysString = languages.map(key => `"${key}": _${key},`).join("\n\t");
29
32
  const languagesKeysStringArray = languages.map(key => `"${key}",`).join("\n\t");
30
33
 
34
+ // Actual imports for json assets
35
+ const assetsImportsString = languages.map(key => `import _${key} from "../assets/i18n/messagebundle_${key}.json";`).join("\n");
36
+
37
+ // static imports
38
+ contentStatic = `// @ts-nocheck
39
+ import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";
40
+
41
+ ${assetsImportsString}
42
+
43
+ const bundleMap = {
44
+ ${languagesKeysString}
45
+ };
46
+
47
+ const fetchMessageBundle = async (localeId) => {
48
+ if (typeof bundleMap[localeId] === "object") {
49
+ // inlined from build
50
+ throw new Error("[i18n] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs")
51
+ }
52
+ return (await fetch(bundleMap[localeId])).json()
53
+ }
54
+
55
+ const localeIds = [${languagesKeysStringArray}];
56
+
57
+ localeIds.forEach(localeId => {
58
+ registerI18nLoader("${packageName}", localeId, fetchMessageBundle);
59
+ });
60
+ `;
61
+
31
62
  // Actual imports for json assets
32
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");
33
64
 
@@ -45,7 +76,7 @@ import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registrie
45
76
  const importAndCheck = async (localeId) => {
46
77
  const data = await importMessageBundle(localeId);
47
78
  if (typeof data === "string" && data.endsWith(".json")) {
48
- throw new Error(\`[i18n] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build. Check the \"Assets\" documentation for more information.\`);
79
+ 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.\`);
49
80
  }
50
81
  return data;
51
82
  }
@@ -60,8 +91,9 @@ import { registerI18nLoader } from "@ui5/webcomponents-base/dist/asset-registrie
60
91
 
61
92
  }
62
93
 
63
- await fs.mkdir(path.dirname(outputFileDynamic), { recursive: true });
94
+ await fs.mkdir(path.dirname(outputFile), { recursive: true });
64
95
  return Promise.all([
96
+ fs.writeFile(outputFile, contentStatic),
65
97
  fs.writeFile(outputFileDynamic, contentDynamic),
66
98
  ]);
67
99
  }
@@ -7,6 +7,7 @@ const ext = isTypeScript ? 'ts' : 'js';
7
7
 
8
8
  const generate = async () => {
9
9
  const inputFolder = path.normalize(process.argv[2]);
10
+ const outputFile = path.normalize(`${process.argv[3]}/Themes-static.${ext}`);
10
11
  const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes.${ext}`);
11
12
 
12
13
  // All supported optional themes
@@ -21,9 +22,34 @@ const generate = async () => {
21
22
 
22
23
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
23
24
 
25
+ const importLines = themesOnFileSystem.map(theme => `import ${theme} from "../assets/themes/${theme}/parameters-bundle.css.json";`).join("\n");
26
+ const themeUrlsByName = "{\n" + themesOnFileSystem.join(",\n") + "\n}";
24
27
  const availableThemesArray = `[${themesOnFileSystem.map(theme => `"${theme}"`).join(", ")}]`;
25
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
 
30
+
31
+ // static imports file content
32
+ const contentStatic = `// @ts-nocheck
33
+ import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
34
+
35
+ ${importLines}
36
+
37
+ const themeUrlsByName = ${themeUrlsByName};
38
+ const isInlined = obj => typeof (obj) === "object";
39
+
40
+ const loadThemeProperties = async (themeName) => {
41
+ if (typeof themeUrlsByName[themeName] === "object") {
42
+ // inlined from build
43
+ throw new Error("[themes] Inlined JSON not supported with static imports of assets. Use dynamic imports of assets or configure JSON imports as URLs");
44
+ }
45
+ return (await fetch(themeUrlsByName[themeName])).json();
46
+ };
47
+
48
+ ${availableThemesArray}
49
+ .forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadThemeProperties));
50
+ `;
51
+
52
+
27
53
  // dynamic imports file content
28
54
  const contentDynamic = `// @ts-nocheck
29
55
  import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
@@ -38,7 +64,7 @@ ${dynamicImportLines}
38
64
  const loadAndCheck = async (themeName) => {
39
65
  const data = await loadThemeProperties(themeName);
40
66
  if (typeof data === "string" && data.endsWith(".json")) {
41
- throw new Error(\`[themes] Invalid bundling detected - dynamic JSON imports bundled as URLs. Switch to inlining JSON files from the build. Check the \"Assets\" documentation for more information.\`);
67
+ 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.\`);
42
68
  }
43
69
  return data;
44
70
  };
@@ -47,8 +73,9 @@ ${availableThemesArray}
47
73
  .forEach(themeName => registerThemePropertiesLoader("${packageName}", themeName, loadAndCheck));
48
74
  `;
49
75
 
50
- await fs.mkdir(path.dirname(outputFileDynamic), { recursive: true });
76
+ await fs.mkdir(path.dirname(outputFile), { recursive: true });
51
77
  return Promise.all([
78
+ fs.writeFile(outputFile, contentStatic),
52
79
  fs.writeFile(outputFileDynamic, contentDynamic)
53
80
  ]);
54
81
  };
@@ -31,7 +31,7 @@ const generate = async () => {
31
31
  // (2) as the messagebundle.properties file is always written in English,
32
32
  // it makes sense to consider the messagebundle.properties content only when the default language is "en".
33
33
  if (defaultLanguage === "en") {
34
- defaultLanguageProperties = Object.assign({}, defaultLanguageProperties, properties);
34
+ defaultLanguageProperties = Object.assign({}, defaultLanguageProperties, properties);
35
35
  }
36
36
 
37
37
  /*
@@ -0,0 +1,29 @@
1
+ {
2
+ "source": {
3
+ "include": "src",
4
+ "excludePattern": "(/|\\\\)library-all\\.js|(/|\\\\).*-preload\\.js|^jquery-.*\\.js|^sap-.*\\.js|.+Renderer\\.lit\\.js|.*library\\.js|thirdparty"
5
+ },
6
+ "opts" : {
7
+ "recurse": true,
8
+ "template" : "template",
9
+ "destination": ""
10
+ },
11
+ "plugins": [
12
+ "./plugin.js"
13
+ ],
14
+ "templates" : {
15
+ "ui5" : {
16
+ "variants": [
17
+ "apijson"
18
+ ],
19
+ "version": "1.62",
20
+ "apiJsonFolder": "",
21
+ "apiJsonFile": "dist/api.json",
22
+ "includeSettingsInConstructor": false
23
+ }
24
+ },
25
+ "tags": {
26
+ "allowUnknownTags": true,
27
+ "dictionaries": ["jsdoc"]
28
+ }
29
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "source": {
3
+ "include": "jsdoc-dist",
4
+ "excludePattern": "(/|\\\\)library-all\\.js|(/|\\\\).*-preload\\.js|^jquery-.*\\.js|^sap-.*\\.js|.+Renderer\\.lit\\.js|.*library\\.js|thirdparty"
5
+ },
6
+ "opts" : {
7
+ "recurse": true,
8
+ "template" : "template",
9
+ "destination": ""
10
+ },
11
+ "plugins": [
12
+ "./plugin.js"
13
+ ],
14
+ "templates" : {
15
+ "ui5" : {
16
+ "variants": [
17
+ "apijson"
18
+ ],
19
+ "version": "1.62",
20
+ "apiJsonFolder": "",
21
+ "apiJsonFile": "dist/api.json",
22
+ "includeSettingsInConstructor": false
23
+ }
24
+ },
25
+ "tags": {
26
+ "allowUnknownTags": true,
27
+ "dictionaries": ["jsdoc"]
28
+ }
29
+ }