@ui5/webcomponents-tools 0.0.0-a3eca7ade → 0.0.0-a7032d86e

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 (59) hide show
  1. package/CHANGELOG.md +155 -0
  2. package/README.md +5 -6
  3. package/assets-meta.js +4 -0
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +28 -0
  6. package/components-package/nps.js +73 -55
  7. package/components-package/postcss.themes.js +1 -1
  8. package/components-package/vite.config.js +12 -0
  9. package/components-package/wdio.js +28 -4
  10. package/components-package/wdio.sync.js +1 -1
  11. package/icons-collection/nps.js +2 -7
  12. package/lib/copy-and-watch/index.js +24 -1
  13. package/lib/copy-list/index.js +17 -17
  14. package/lib/create-icons/index.js +101 -72
  15. package/lib/create-illustrations/index.js +101 -90
  16. package/lib/create-new-component/index.js +5 -5
  17. package/lib/dev-server/dev-server.js +66 -0
  18. package/lib/dev-server/virtual-index-html-plugin.js +53 -0
  19. package/lib/esm-abs-to-rel/index.js +13 -9
  20. package/lib/generate-custom-elements-manifest/index.js +373 -0
  21. package/lib/generate-js-imports/illustrations.js +72 -0
  22. package/lib/generate-json-imports/i18n.js +38 -31
  23. package/lib/generate-json-imports/themes.js +31 -24
  24. package/lib/hbs2lit/src/compiler.js +20 -3
  25. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  26. package/lib/hbs2lit/src/litVisitor2.js +46 -8
  27. package/lib/hbs2ui5/index.js +37 -21
  28. package/lib/i18n/defaults.js +58 -57
  29. package/lib/i18n/toJSON.js +12 -11
  30. package/lib/jsdoc/configTypescript.json +29 -0
  31. package/lib/jsdoc/plugin.js +32 -0
  32. package/lib/jsdoc/preprocess.js +146 -0
  33. package/lib/jsdoc/template/publish.js +9 -1
  34. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  35. package/lib/postcss-css-to-esm/index.js +13 -1
  36. package/lib/postcss-css-to-json/index.js +12 -1
  37. package/lib/postcss-p/postcss-p.mjs +14 -0
  38. package/lib/replace-global-core/index.js +13 -8
  39. package/lib/scoping/get-all-tags.js +1 -8
  40. package/lib/scoping/scope-test-pages.js +1 -1
  41. package/lib/test-runner/test-runner.js +63 -0
  42. package/package.json +18 -25
  43. package/components-package/rollup-plugins/empty-module.js +0 -15
  44. package/components-package/rollup.js +0 -239
  45. package/lib/documentation/index.js +0 -165
  46. package/lib/documentation/templates/api-component-since.js +0 -3
  47. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  48. package/lib/documentation/templates/api-events-section.js +0 -35
  49. package/lib/documentation/templates/api-methods-section.js +0 -26
  50. package/lib/documentation/templates/api-properties-section.js +0 -42
  51. package/lib/documentation/templates/api-slots-section.js +0 -28
  52. package/lib/documentation/templates/template.js +0 -39
  53. package/lib/hash/config.js +0 -10
  54. package/lib/hash/generate.js +0 -19
  55. package/lib/hash/upToDate.js +0 -31
  56. package/lib/polyfill-placeholder/index.js +0 -5
  57. package/lib/serve/index.js +0 -46
  58. package/lib/serve/serve.json +0 -3
  59. package/package-lock.json +0 -48
@@ -0,0 +1,178 @@
1
+ /*
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2016 Christian Murphy
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
25
+ const parser = require('postcss-selector-parser');
26
+ const name = "postcss-combine-duplicated-selectors";
27
+
28
+ /**
29
+ * Ensure that attributes with different quotes match.
30
+ * @param {Object} selector - postcss selector node
31
+ */
32
+ function normalizeAttributes(selector) {
33
+ selector.walkAttributes((node) => {
34
+ if (node.value) {
35
+ // remove quotes
36
+ node.value = node.value.replace(/'|\\'|"|\\"/g, '');
37
+ }
38
+ });
39
+ }
40
+
41
+ /**
42
+ * Sort class and id groups alphabetically
43
+ * @param {Object} selector - postcss selector node
44
+ */
45
+ function sortGroups(selector) {
46
+ selector.each((subSelector) => {
47
+ subSelector.nodes.sort((a, b) => {
48
+ // different types cannot be sorted
49
+ if (a.type !== b.type) {
50
+ return 0;
51
+ }
52
+
53
+ // sort alphabetically
54
+ return a.value < b.value ? -1 : 1;
55
+ });
56
+ });
57
+
58
+ selector.sort((a, b) => (a.nodes.join('') < b.nodes.join('') ? -1 : 1));
59
+ }
60
+
61
+ /**
62
+ * Remove duplicated properties
63
+ * @param {Object} selector - postcss selector node
64
+ * @param {Boolean} exact
65
+ */
66
+ function removeDupProperties(selector, exact) {
67
+ if (!exact) { // Remove duplicated properties, regardless of value
68
+ const retainedProps = new Set();
69
+
70
+ for (let actIndex = selector.nodes.length - 1; actIndex >= 1; actIndex--) {
71
+ const prop = selector.nodes[actIndex].prop;
72
+ if (prop !== undefined) {
73
+ if (!retainedProps.has(prop)) {
74
+ retainedProps.add(prop); // Mark the prop as retained, all other occurrences must be removed
75
+ } else {
76
+ selector.nodes[actIndex].remove(); // This occurrence of the prop must be removed
77
+ }
78
+ }
79
+ }
80
+ } else {
81
+ // Remove duplicated properties from bottom to top ()
82
+ for (let actIndex = selector.nodes.length - 1; actIndex >= 1; actIndex--) {
83
+ for (let befIndex = actIndex - 1; befIndex >= 0; befIndex--) {
84
+ if (
85
+ selector.nodes[actIndex].prop === selector.nodes[befIndex].prop &&
86
+ selector.nodes[actIndex].value === selector.nodes[befIndex].value
87
+ ) {
88
+ selector.nodes[befIndex].remove();
89
+ actIndex--;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ const uniformStyle = parser((selector) => {
97
+ normalizeAttributes(selector);
98
+ sortGroups(selector);
99
+ });
100
+
101
+ const defaultOptions = {
102
+ removeDuplicatedProperties: false,
103
+ };
104
+
105
+ module.exports = (options) => {
106
+ options = Object.assign({}, defaultOptions, options);
107
+ return {
108
+ postcssPlugin: name,
109
+ prepare() {
110
+ // Create a map to store maps
111
+ const mapTable = new Map();
112
+ // root map to store root selectors
113
+ mapTable.set('root', new Map());
114
+
115
+ return {
116
+ Rule: (rule) => {
117
+ let map;
118
+ // Check selector parent for any at rule
119
+ if (rule.parent.type === 'atrule') {
120
+ // Use name and query params as the key
121
+ const query =
122
+ rule.parent.name.toLowerCase() +
123
+ rule.parent.params.replace(/\s+/g, '');
124
+
125
+ // See if this query key is already in the map table
126
+ map = mapTable.has(query) ? // If it is use it
127
+ mapTable.get(query) : // if not set it and get it
128
+ mapTable.set(query, new Map()).get(query);
129
+ } else {
130
+ // Otherwise we are dealing with a selector in the root
131
+ map = mapTable.get('root');
132
+ }
133
+
134
+ // create a uniform selector
135
+ const selector = uniformStyle.processSync(rule.selector, {
136
+ lossless: false,
137
+ });
138
+
139
+ if (map.has(selector)) {
140
+ // store original rule as destination
141
+ const destination = map.get(selector);
142
+
143
+ // check if node has already been processed
144
+ if (destination === rule) return;
145
+
146
+ // move declarations to original rule
147
+ while (rule.nodes.length > 0) {
148
+ destination.append(rule.nodes[0]);
149
+ }
150
+ // remove duplicated rule
151
+ rule.remove();
152
+
153
+ if (
154
+ options.removeDuplicatedProperties ||
155
+ options.removeDuplicatedValues
156
+ ) {
157
+ removeDupProperties(
158
+ destination,
159
+ options.removeDuplicatedValues,
160
+ );
161
+ }
162
+ } else {
163
+ if (
164
+ options.removeDuplicatedProperties ||
165
+ options.removeDuplicatedValues
166
+ ) {
167
+ removeDupProperties(rule, options.removeDuplicatedValues);
168
+ }
169
+ // add new selector to symbol table
170
+ map.set(selector, rule);
171
+ }
172
+ },
173
+ };
174
+ },
175
+ };
176
+ };
177
+
178
+ module.exports.postcss = true;
@@ -38,7 +38,19 @@ module.exports = function (opts) {
38
38
 
39
39
  const filePath = `${targetFile}.js`;
40
40
  const defaultTheme = opts.includeDefaultTheme ? getDefaultThemeCode(opts.packageName) : ``;
41
- fs.writeFileSync(filePath, `${defaultTheme}export default {packageName:"${opts.packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`);
41
+
42
+ // it seems slower to read the old content, but writing the same content with no real changes
43
+ // (as in initial build and then watch mode) will cause an unnecessary dev server refresh
44
+ let oldContent = "";
45
+ try {
46
+ oldContent = fs.readFileSync(filePath).toString();
47
+ } catch (e) {
48
+ // file not found
49
+ }
50
+ const content = `${defaultTheme}export default {packageName:"${opts.packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
51
+ if (content !== oldContent) {
52
+ fs.writeFileSync(filePath, content);
53
+ }
42
54
  }
43
55
  };
44
56
  };
@@ -28,7 +28,18 @@ module.exports = function (opts) {
28
28
  fileName: targetFile.substr(targetFile.lastIndexOf("themes")),
29
29
  content: css
30
30
  };
31
- fs.writeFileSync(filePath, JSON.stringify({_: data}));
31
+ // it seems slower to read the old content, but writing the same content with no real changes
32
+ // (as in initial build and then watch mode) will cause an unnecessary dev server refresh
33
+ let oldContent = "";
34
+ try {
35
+ oldContent = fs.readFileSync(filePath).toString();
36
+ } catch (e) {
37
+ // file not found
38
+ }
39
+ const content = JSON.stringify({_: data});
40
+ if (content !== oldContent) {
41
+ fs.writeFileSync(filePath, content);
42
+ }
32
43
  }
33
44
  };
34
45
  };
@@ -0,0 +1,14 @@
1
+ import 'zx/globals';
2
+
3
+ // don't print executed commands and their output
4
+ $.verbose = false;
5
+
6
+ const inputFiles = await globby("src/**/parameters-bundle.css");
7
+
8
+ const restArgs = process.argv.slice(2);
9
+
10
+ // run all postcss processes in parallel as passing the glob directly to postcss makes them processed sequentially.
11
+ // and the amount of imports give a big speed up when run in parallel
12
+ await Promise.all(inputFiles.map(file => {
13
+ return $`postcss ${file} --config config/postcss.themes --base src --dir dist/css/ ${restArgs}`;
14
+ }));
@@ -1,20 +1,25 @@
1
- const fs = require("fs");
2
- const glob = require("glob");
1
+ const fs = require("fs").promises;
3
2
 
4
3
  const basePath = process.argv[2];
5
4
 
6
- const replaceGlobalCoreUsage = (srcPath) => {
5
+ const replaceGlobalCoreUsage = async (srcPath) => {
7
6
 
8
- const original = fs.readFileSync(srcPath).toString();
7
+ const original = (await fs.readFile(srcPath)).toString();
9
8
  let replaced = original.replace(/sap\.ui\.getCore\(\)/g, `Core`);
10
9
 
11
10
  if (original !== replaced) {
12
11
  replaced = `import Core from 'sap/ui/core/Core';
13
12
  ${replaced}`;
14
- fs.writeFileSync(srcPath, replaced);
13
+ return fs.writeFile(srcPath, replaced);
15
14
  }
16
15
  };
17
16
 
18
- const fileNames = glob.sync(basePath + "**/*.js");
19
- fileNames.forEach(replaceGlobalCoreUsage);
20
- console.log("Success: Replaced global core usage in:", basePath);
17
+ const generate = async () => {
18
+ const { globby } = await import("globby");
19
+ const fileNames = await globby(basePath + "**/*.js");
20
+ return Promise.all(fileNames.map(replaceGlobalCoreUsage).filter(x => !!x));
21
+ };
22
+
23
+ generate().then(() => {
24
+ console.log("Success: Replaced global core usage in:", basePath);
25
+ });
@@ -8,18 +8,11 @@ const getTag = file => {
8
8
  return matches ? matches[1] : undefined;
9
9
  };
10
10
 
11
- const getAltTag = file => {
12
- const fileContent = String(fs.readFileSync(file)).replace(/\n/g, "");
13
- const matches = fileContent.match(/\baltTag\b:\s*\"(.*?)\"/);
14
- return matches ? matches[1] : undefined;
15
- };
16
-
17
11
  const getPackageTags = (packageDir) => {
18
12
  const srcDir = path.join(packageDir, "src/");
19
13
  return glob.sync(path.join(srcDir, "/**/*.js")).flatMap(file => {
20
14
  const tag = getTag(file);
21
- const altTag = getAltTag(file);
22
- return [tag, altTag];
15
+ return [tag];
23
16
  }).filter(item => !!item);
24
17
  };
25
18
 
@@ -27,7 +27,7 @@ const replaceTagsAny = content => {
27
27
  // Replace bundle names and HTML tag names in test pages
28
28
  glob.sync(path.join(root, "/**/*.html")).forEach(file => {
29
29
  let content = String(fs.readFileSync(file));
30
- content = content.replace(/bundle\.(.*?)\.js/g, `bundle.scoped.$1.js`);
30
+ content = content.replace(/bundle\.(.*?)\.js/g, `../bundle.scoped.$1.js`);
31
31
  content = replaceTagsHTML(content);
32
32
  fs.writeFileSync(file, content);
33
33
  });
@@ -0,0 +1,63 @@
1
+ const child_process = require("child_process");
2
+ const { readFileSync } = require("fs");
3
+ const path = require("path");
4
+
5
+ // search for dev-server port
6
+ // start in current folder
7
+ // traversing upwards in case of mono repo tests and dev-server running in root folder of repository
8
+ let devServerFolder = process.cwd();
9
+ let devServerPort;
10
+ while (true) {
11
+ try {
12
+ devServerPort = readFileSync(path.join(devServerFolder, ".dev-server-port")).toString();
13
+ break; // found
14
+ } catch (e) {
15
+ // file not found
16
+ if (devServerFolder === path.dirname(devServerFolder)) {
17
+ break; // reached root folder "/"
18
+ }
19
+ devServerFolder = path.dirname(devServerFolder);
20
+ }
21
+ }
22
+
23
+ // check if we are in a monorepo and extract path from package.json
24
+ let packageRepositoryPath = "";
25
+ const pkg = require(path.join(process.cwd(), "package.json"));
26
+ packageRepositoryPath = pkg.repository.directory;
27
+
28
+ // construct base url
29
+ // use devServerPort if a dev server is running, otherwise let the baseUrl in the wdio config be used
30
+ // if a dev server is running in the root of a mono repo, append tha package path like this
31
+ // http://localhost:${devServerPort}/packages/main/
32
+ let baseUrl = "";
33
+ if (devServerPort) {
34
+ console.log(`Found port ${devServerPort} from '${path.join(devServerFolder, ".dev-server-port")}'`);
35
+ const devServerInRoot = !devServerFolder.includes(packageRepositoryPath);
36
+ if (devServerInRoot) {
37
+ baseUrl = `--base-url http://localhost:${devServerPort}/${packageRepositoryPath}/`;
38
+ } else {
39
+ baseUrl = `--base-url http://localhost:${devServerPort}/`;
40
+ }
41
+ }
42
+
43
+ if (!baseUrl) {
44
+ console.log("No dev server running, running tests served from `dist`, make sure it is up to date");
45
+ }
46
+
47
+ // add single spec parameter if passed
48
+ let spec = "";
49
+ if (process.argv.length === 3) {
50
+ const specFile = process.argv[2];
51
+ spec = `--spec ${specFile}`;
52
+ }
53
+
54
+ // more parameters - pass them to wdio
55
+ let restParams = "";
56
+ if (process.argv.length > 3) {
57
+ restParams = process.argv.slice(2).join(" ");
58
+ }
59
+
60
+ // run wdio with calculated parameters
61
+ const cmd = `yarn cross-env WDIO_LOG_LEVEL=error wdio config/wdio.conf.js ${spec} ${baseUrl} ${restParams}`;
62
+ console.log(`executing: ${cmd}`);
63
+ child_process.execSync(cmd, {stdio: 'inherit'});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-tools",
3
- "version": "0.0.0-a3eca7ade",
3
+ "version": "0.0.0-a7032d86e",
4
4
  "description": "UI5 Web Components: webcomponents.tools",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -21,26 +21,19 @@
21
21
  "directory": "packages/tools"
22
22
  },
23
23
  "dependencies": {
24
- "@babel/core": "^7.13.10",
25
- "@babel/preset-env": "^7.13.10",
26
- "@openui5/sap.ui.core": "1.95.0",
27
- "@rollup/plugin-babel": "^5.3.0",
28
- "@rollup/plugin-commonjs": "^21.0.1",
29
- "@rollup/plugin-json": "^4.1.0",
30
- "@rollup/plugin-node-resolve": "^13.0.5",
31
- "@rollup/plugin-replace": "^3.0.0",
32
- "@rollup/plugin-url": "^6.0.0",
33
- "@wdio/cli": "^7.12.2",
34
- "@wdio/dot-reporter": "^7.10.1",
35
- "@wdio/local-runner": "^7.12.2",
36
- "@wdio/mocha-framework": "^7.12.2",
37
- "@wdio/spec-reporter": "^7.10.1",
38
- "@webcomponents/webcomponentsjs": "^2.5.0",
24
+ "@typescript-eslint/eslint-plugin": "^5.42.1",
25
+ "@typescript-eslint/parser": "^5.42.1",
26
+ "@wdio/cli": "^7.19.7",
27
+ "@wdio/devtools-service": "^7.19.7",
28
+ "@wdio/dot-reporter": "^7.19.7",
29
+ "@wdio/local-runner": "^7.19.7",
30
+ "@wdio/mocha-framework": "^7.19.7",
31
+ "@wdio/spec-reporter": "^7.19.7",
32
+ "@wdio/static-server-service": "^7.19.5",
39
33
  "chai": "^4.3.4",
40
34
  "child_process": "^1.0.2",
41
35
  "chokidar": "^3.5.1",
42
36
  "chokidar-cli": "^3.0.0",
43
- "cli-color": "^2.0.1",
44
37
  "command-line-args": "^5.1.1",
45
38
  "concurrently": "^6.0.0",
46
39
  "cross-env": "^7.0.3",
@@ -50,10 +43,10 @@
50
43
  "eslint-config-airbnb-base": "^14.2.1",
51
44
  "eslint-plugin-import": "^2.22.1",
52
45
  "esprima": "^4.0.1",
53
- "folder-hash": "^4.0.1",
54
46
  "getopts": "^2.3.0",
55
47
  "glob": "^7.1.6",
56
48
  "glob-parent": "^6.0.2",
49
+ "globby": "^13.1.1",
57
50
  "handlebars": "^4.7.7",
58
51
  "is-port-reachable": "^3.1.0",
59
52
  "jsdoc": "^3.6.6",
@@ -62,21 +55,21 @@
62
55
  "nps": "^5.10.0",
63
56
  "postcss": "^8.4.5",
64
57
  "postcss-cli": "^9.1.0",
65
- "postcss-combine-duplicated-selectors": "^10.0.3",
66
58
  "postcss-import": "^14.0.2",
59
+ "postcss-selector-parser": "^6.0.10",
67
60
  "properties-reader": "^2.2.0",
68
61
  "recursive-readdir": "^2.2.2",
69
62
  "resolve": "^1.20.0",
70
63
  "rimraf": "^3.0.2",
71
- "rollup": "^2.41.4",
72
- "rollup-plugin-filesize": "^9.1.1",
73
- "rollup-plugin-livereload": "^2.0.0",
74
- "rollup-plugin-terser": "^7.0.2",
75
- "serve": "^12.0.0",
76
64
  "slash": "3.0.0",
77
- "wdio-chromedriver-service": "^7.0.0"
65
+ "vite": "^2.9.12",
66
+ "wdio-chromedriver-service": "^7.3.2",
67
+ "zx": "^4.3.0"
78
68
  },
79
69
  "peerDependencies": {
80
70
  "chromedriver": "*"
71
+ },
72
+ "devDependencies": {
73
+ "yargs": "^17.5.1"
81
74
  }
82
75
  }
@@ -1,15 +0,0 @@
1
- const slash = require("slash");
2
-
3
- function emptyModulePlugin({ emptyModules }) {
4
- return {
5
- name: "ui5-dev-empty-module-plugin",
6
- load(id) {
7
- if (emptyModules.some(mod => slash(id).includes(mod))) {
8
- return `export default ""`;
9
- }
10
- return null;
11
- },
12
- };
13
- }
14
-
15
- module.exports = emptyModulePlugin;