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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +413 -0
  2. package/README.md +2 -1
  3. package/assets-meta.js +16 -7
  4. package/components-package/eslint.js +2 -0
  5. package/components-package/nps.js +38 -31
  6. package/components-package/postcss.components.js +1 -21
  7. package/components-package/postcss.themes.js +1 -26
  8. package/components-package/wdio.js +15 -3
  9. package/components-package/wdio.sync.js +9 -1
  10. package/icons-collection/nps.js +8 -6
  11. package/lib/amd-to-es6/index.js +104 -0
  12. package/lib/cem/custom-elements-manifest.config.mjs +482 -0
  13. package/lib/cem/event.mjs +131 -0
  14. package/lib/cem/schema-internal.json +1357 -0
  15. package/lib/cem/schema.json +1098 -0
  16. package/lib/cem/types-internal.d.ts +802 -0
  17. package/lib/cem/types.d.ts +736 -0
  18. package/lib/cem/utils.mjs +379 -0
  19. package/lib/cem/validate.js +65 -0
  20. package/lib/create-illustrations/index.js +32 -28
  21. package/lib/create-new-component/index.js +1 -1
  22. package/lib/create-new-component/tsFileContentTemplate.js +2 -11
  23. package/lib/css-processors/css-processor-components.mjs +77 -0
  24. package/lib/css-processors/css-processor-themes.mjs +79 -0
  25. package/lib/css-processors/scope-variables.mjs +46 -0
  26. package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
  27. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  28. package/lib/generate-custom-elements-manifest/index.js +51 -107
  29. package/lib/generate-js-imports/illustrations.js +78 -64
  30. package/lib/generate-json-imports/i18n.js +10 -5
  31. package/lib/generate-json-imports/themes.js +10 -5
  32. package/lib/hbs2lit/src/litVisitor2.js +1 -1
  33. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +4 -4
  34. package/lib/jsdoc/preprocess.js +1 -1
  35. package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
  36. package/lib/scoping/get-all-tags.js +1 -1
  37. package/lib/scoping/scope-test-pages.js +2 -1
  38. package/package.json +9 -9
  39. package/lib/esm-abs-to-rel/index.js +0 -58
  40. package/lib/postcss-css-to-json/index.js +0 -47
  41. package/lib/postcss-new-files/index.js +0 -36
  42. package/lib/postcss-p/postcss-p.mjs +0 -14
  43. package/lib/replace-global-core/index.js +0 -25
@@ -0,0 +1,79 @@
1
+ import { globby } from "globby";
2
+ import * as esbuild from 'esbuild'
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import { writeFile, mkdir } from "fs/promises";
6
+ import postcss from "postcss";
7
+ import combineDuplicatedSelectors from "../postcss-combine-duplicated-selectors/index.js"
8
+ import { writeFileIfChanged, stripThemingBaseContent, getFileContent } from "./shared.mjs";
9
+ import scopeVariables from "./scope-variables.mjs";
10
+
11
+ const tsMode = process.env.UI5_TS === "true";
12
+ const extension = tsMode ? ".css.ts" : ".css.js";
13
+
14
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
15
+
16
+ let inputFiles = await globby("src/**/parameters-bundle.css");
17
+ const restArgs = process.argv.slice(2);
18
+
19
+ const removeDuplicateSelectors = async (text) => {
20
+ const result = await postcss(combineDuplicatedSelectors).process(text);
21
+ return result.css;
22
+ }
23
+
24
+ let scopingPlugin = {
25
+ name: 'scoping',
26
+ setup(build) {
27
+ build.initialOptions.write = false;
28
+
29
+ build.onEnd(result => {
30
+ result.outputFiles.forEach(async f => {
31
+ // remove duplicate selectors
32
+ let newText = await removeDuplicateSelectors(f.text);
33
+
34
+ // strip unnecessary theming-base-content
35
+ newText = stripThemingBaseContent(newText);
36
+
37
+ // scoping
38
+ newText = scopeVariables(newText, packageJSON, f.path);
39
+ await mkdir(path.dirname(f.path), {recursive: true});
40
+ writeFile(f.path, newText);
41
+
42
+ // JSON
43
+ const jsonPath = f.path.replace(/dist[\/\\]css/, "dist/generated/assets").replace(".css", ".css.json");
44
+ await mkdir(path.dirname(jsonPath), {recursive: true});
45
+ const data = {
46
+ packageName: packageJSON.name,
47
+ fileName: jsonPath.substr(jsonPath.lastIndexOf("themes")),
48
+ content: newText,
49
+ };
50
+ writeFileIfChanged(jsonPath, JSON.stringify({_: data}));
51
+
52
+ // JS/TS
53
+ const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
54
+ const jsContent = getFileContent(tsMode, jsPath, packageJSON.name, "\`" + newText + "\`");
55
+ writeFileIfChanged(jsPath, jsContent);
56
+ });
57
+ })
58
+ },
59
+ }
60
+
61
+ const config = {
62
+ entryPoints: inputFiles,
63
+ bundle: true,
64
+ minify: true,
65
+ outdir: 'dist/css',
66
+ outbase: 'src',
67
+ plugins: [
68
+ scopingPlugin,
69
+ ],
70
+ external: ["*.ttf", "*.woff", "*.woff2"],
71
+ };
72
+
73
+ if (restArgs.includes("-w")) {
74
+ let ctx = await esbuild.context(config);
75
+ await ctx.watch()
76
+ console.log('watching...')
77
+ } else {
78
+ const result = await esbuild.build(config);
79
+ }
@@ -0,0 +1,46 @@
1
+ import * as path from "path";
2
+
3
+ /**
4
+ * Tries to detect an override for a package
5
+ * @param {*} filePath For example: /my_project/src/themes/overrides/@ui5/webcomponents/my_custom_theme/parameters-bundle.css
6
+ * @returns
7
+ */
8
+ const getOverrideVersion = filePath => {
9
+ if (!filePath) {
10
+ return;
11
+ }
12
+
13
+ if (!filePath.includes(`overrides${path.sep}`)) {
14
+ return; // The "overrides/" directory is the marker
15
+ }
16
+ const override = filePath.split(`overrides${path.sep}`)[1]; // For example, this will be: @ui5/webcomponents/my_custom_theme/parameters-bundle.css
17
+ if (!override) {
18
+ return; // There must be other directories after overrides/, the path can't end with it
19
+ }
20
+ const parts = override.split(path.sep);
21
+ if (parts.length < 3) {
22
+ return; // There must be at least a directory for the theme that is being overridden (my_custom_theme) and the name of the CSS file after the name of the package that is overridden
23
+ }
24
+ const packageName = parts.slice(0, -2).join(path.sep); // After the last 2 parts are removed (my_custom_theme and parameters-bundle.css from the example), the rest is the package
25
+
26
+ let overrideVersion;
27
+ try {
28
+ overrideVersion = require(`${packageName}${path.sep}package.json`).version;
29
+ } catch (e) {
30
+ console.log(`Error requiring package ${packageName}: ${e.message}`);
31
+ }
32
+
33
+ return overrideVersion;
34
+ }
35
+
36
+ const scopeVariables = (cssText, packageJSON, inputFile) => {
37
+ const escapeVersion = version => "v" + version?.replaceAll(/[^0-9A-Za-z\-_]/g, "-");
38
+ const versionStr = escapeVersion(getOverrideVersion(inputFile) || packageJSON.version);
39
+
40
+ const expr = /(--_?ui5)([^\,\:\)\s]+)/g;
41
+
42
+ return cssText.replaceAll(expr, `$1-${versionStr}$2`);
43
+ }
44
+
45
+ export default scopeVariables;
46
+
@@ -1,7 +1,38 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const mkdirp = require('mkdirp');
4
- const assets = require("../../assets-meta.js");
1
+ import { writeFile, readFile, mkdir } from "fs/promises";
2
+ import * as path from "path";
3
+ import assets from "../../assets-meta.js";
4
+
5
+ const readOldContent = async (fileName) => {
6
+ // it seems slower to read the old content, but writing the same content with no real changes
7
+ // (as in initial build and then watch mode) will cause an unnecessary dev server refresh
8
+ let oldContent = "";
9
+ try {
10
+ oldContent = (await readFile(fileName)).toString();
11
+ } catch (e) {
12
+ // file not found
13
+ }
14
+ return oldContent;
15
+ }
16
+
17
+ const writeFileIfChanged = async (fileName, content) => {
18
+ const oldContent = await readOldContent(fileName);
19
+ if (content !== oldContent) {
20
+ if (!oldContent) {
21
+ await mkdir(path.dirname(fileName), {recursive: true});
22
+ }
23
+ return writeFile(fileName, content);
24
+ }
25
+ }
26
+
27
+ // strips the unnecessary theming data coming from @sap-theming/theming-base-content and leaves only the css parameters
28
+ const stripThemingBaseContent = css => {
29
+ css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
30
+ css = css.replace(/\.background-image.*{.*}/, "");
31
+ css = css.replace(/\.sapContrast[ ]*:root[\s\S]*?}/, "");
32
+ css = css.replace(/--sapFontUrl.*\);?/, "");
33
+ return css;
34
+ }
35
+
5
36
 
6
37
  const DEFAULT_THEME = assets.themes.default;
7
38
 
@@ -42,49 +73,4 @@ const getJSContent = (targetFile, packageName, css, includeDefaultTheme) => {
42
73
  return `${defaultTheme}export default {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
43
74
  }
44
75
 
45
-
46
- const proccessCSS = css => {
47
- css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
48
- css = css.replace(/\.background-image.*{.*}/, "");
49
- css = css.replace(/\.sapContrast[ ]*:root[\s\S]*?}/, "");
50
- css = css.replace(/--sapFontUrl.*\);?/, "");
51
- return JSON.stringify(css);
52
- }
53
-
54
- module.exports = function (opts) {
55
- opts = opts || {};
56
-
57
- const packageName = opts.packageName;
58
- const includeDefaultTheme = opts.includeDefaultTheme;
59
- const toReplace = opts.toReplace;
60
-
61
- return {
62
- postcssPlugin: 'postcss-css-to-esm',
63
- Once (root) {
64
- const tsMode = process.env.UI5_TS === "true";
65
-
66
- let css = root.toString();
67
- css = proccessCSS(css);
68
-
69
- const targetFile = root.source.input.from.replace(`/${toReplace}/`, "/src/generated/").replace(`\\${toReplace}\\`, "\\src\\generated\\");
70
- mkdirp.sync(path.dirname(targetFile));
71
-
72
- const filePath = `${targetFile}.${tsMode ? "ts" : "js"}`;
73
-
74
- // it seems slower to read the old content, but writing the same content with no real changes
75
- // (as in initial build and then watch mode) will cause an unnecessary dev server refresh
76
- let oldContent = "";
77
- try {
78
- oldContent = fs.readFileSync(filePath).toString();
79
- } catch (e) {
80
- // file not found
81
- }
82
-
83
- const content = getFileContent(tsMode, targetFile, packageName, css, includeDefaultTheme);
84
- if (content !== oldContent) {
85
- fs.writeFileSync(filePath, content);
86
- }
87
- }
88
- };
89
- };
90
- module.exports.postcss = true;
76
+ export { writeFileIfChanged, stripThemingBaseContent, getFileContent}
@@ -0,0 +1,39 @@
1
+ const fs = require("fs");
2
+
3
+ /**
4
+ * A change is observed on MacOS since 13.5, where the build generates a large amount
5
+ * of JSON file that spotlight search has to index, as they are considered new files.
6
+ *
7
+ * Starting the vitejs dev server reads all of these files and this triggers the indexing.
8
+ * The indexing has a side effect of changing some file metadata (can be checked with `mdls <path_to_file>`).
9
+ * This metadata change is changing the ctime of the file, but not the mtime. This can be checked with `stat -x <path_to_file>
10
+ *
11
+ * Essentially only metadata is changed, not content. This should not cause a page refresh,
12
+ * but chokidar reports this change and vite refreshes the page.
13
+ * The indexing is running with a 10 second interval, so for roughtly 20 minutes vite is refreshing the page every 10 seconds
14
+ *
15
+ * This plugin checks if the file causing the refresh is a generated json file (dist/*.json) and if ctime is changed after mtime
16
+ * In that case, returing an empty array tells vitejs that a custom update will be made by the plugin,
17
+ * which is in effect ignoring the page refresh.
18
+ */
19
+
20
+ const customHotUpdate = async () => {
21
+ return {
22
+ name: 'custom-hot-update',
23
+ handleHotUpdate(ctx) {
24
+ // custom check for generated json files
25
+ if (ctx.file.endsWith(".json")) {
26
+ const stat = fs.statSync(ctx.file);
27
+
28
+ // metadata change only
29
+ if (stat.ctime > stat.mtime) {
30
+ // uncomment for debugging
31
+ // console.log("ignoring hot update for:", ctx.file);
32
+ return [];
33
+ }
34
+ }
35
+ }
36
+ }
37
+ };
38
+
39
+ module.exports = customHotUpdate;
@@ -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 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
- };
8
+ const moduleDeclarations = new Map();
19
9
 
20
10
  const generateJavaScriptExport = entity => {
21
11
  return {
22
- declaration: generateRefenrece(entity.name),
23
- deprecated: !!entity.deprecated,
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: `${entity.module}.js`,
27
+ module: `dist/${entity.resource}`,
34
28
  },
35
- deprecated: !!entity.deprecated,
36
29
  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
- ],
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.type;
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: 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),
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.basename,
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
- module: `${basename}.js`,
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
- if (entity.tagname) {
318
- customElementsManifest.modules.push(generateJavaScriptModule(entity));
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