@ui5/webcomponents-tools 0.0.0-fb61e9889 → 0.0.0-fc993d8cd

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 (64) hide show
  1. package/CHANGELOG.md +357 -0
  2. package/README.md +5 -6
  3. package/assets-meta.js +6 -1
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +34 -0
  6. package/components-package/nps.js +86 -57
  7. package/components-package/postcss.components.js +13 -13
  8. package/components-package/postcss.themes.js +19 -16
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +393 -353
  11. package/components-package/wdio.sync.js +17 -1
  12. package/icons-collection/nps.js +46 -15
  13. package/lib/copy-and-watch/index.js +24 -1
  14. package/lib/copy-list/index.js +17 -17
  15. package/lib/create-icons/index.js +124 -58
  16. package/lib/create-illustrations/index.js +107 -41
  17. package/lib/create-new-component/index.js +105 -108
  18. package/lib/create-new-component/jsFileContentTemplate.js +77 -0
  19. package/lib/create-new-component/tsFileContentTemplate.js +84 -0
  20. package/lib/dev-server/dev-server.js +66 -0
  21. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  22. package/lib/esm-abs-to-rel/index.js +13 -9
  23. package/lib/generate-custom-elements-manifest/index.js +327 -0
  24. package/lib/generate-js-imports/illustrations.js +72 -0
  25. package/lib/generate-json-imports/i18n.js +38 -31
  26. package/lib/generate-json-imports/themes.js +31 -24
  27. package/lib/hbs2lit/src/compiler.js +20 -3
  28. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  29. package/lib/hbs2lit/src/litVisitor2.js +56 -10
  30. package/lib/hbs2ui5/index.js +37 -21
  31. package/lib/i18n/defaults.js +65 -57
  32. package/lib/i18n/toJSON.js +12 -11
  33. package/lib/jsdoc/configTypescript.json +29 -0
  34. package/lib/jsdoc/plugin.js +41 -0
  35. package/lib/jsdoc/preprocess.js +146 -0
  36. package/lib/jsdoc/template/publish.js +21 -2
  37. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  38. package/lib/postcss-css-to-esm/index.js +53 -8
  39. package/lib/postcss-css-to-json/index.js +18 -2
  40. package/lib/postcss-p/postcss-p.mjs +14 -0
  41. package/lib/replace-global-core/index.js +13 -8
  42. package/lib/scoping/get-all-tags.js +1 -8
  43. package/lib/scoping/missing-dependencies.js +65 -0
  44. package/lib/scoping/report-tags-usage.js +28 -0
  45. package/lib/scoping/scope-test-pages.js +1 -1
  46. package/lib/test-runner/test-runner.js +71 -0
  47. package/package.json +28 -28
  48. package/components-package/rollup-plugins/empty-module.js +0 -15
  49. package/components-package/rollup.js +0 -237
  50. package/lib/documentation/index.js +0 -165
  51. package/lib/documentation/templates/api-component-since.js +0 -3
  52. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  53. package/lib/documentation/templates/api-events-section.js +0 -35
  54. package/lib/documentation/templates/api-methods-section.js +0 -26
  55. package/lib/documentation/templates/api-properties-section.js +0 -40
  56. package/lib/documentation/templates/api-slots-section.js +0 -28
  57. package/lib/documentation/templates/template.js +0 -38
  58. package/lib/hash/config.js +0 -10
  59. package/lib/hash/generate.js +0 -19
  60. package/lib/hash/upToDate.js +0 -31
  61. package/lib/polyfill-placeholder/index.js +0 -5
  62. package/lib/serve/index.js +0 -46
  63. package/lib/serve/serve.json +0 -3
  64. package/package-lock.json +0 -48
@@ -1,80 +1,7 @@
1
1
  const fs = require("fs");
2
-
3
- const jsFileContentTemplate = componentName => {
4
- return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
5
- import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
6
- import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
7
-
8
- // Styles
9
- import ${componentName}Css from "./generated/themes/${componentName}.css.js";
10
-
11
- /**
12
- * @public
13
- */
14
- const metadata = {
15
- tag: "${tagName}",
16
- properties: /** @lends sap.ui.webcomponents.${library}.${componentName}.prototype */ {
17
- //
18
- },
19
- slots: /** @lends sap.ui.webcomponents.${library}.${componentName}.prototype */ {
20
- //
21
- },
22
- events: /** @lends sap.ui.webcomponents.${library}.${componentName}.prototype */ {
23
- //
24
- },
25
- };
26
-
27
- /**
28
- * @class
29
- *
30
- * <h3 class="comment-api-title">Overview</h3>
31
- *
32
- *
33
- * <h3>Usage</h3>
34
- *
35
- * For the <code>${tagName}</code>
36
- * <h3>ES6 Module Import</h3>
37
- *
38
- * <code>import ${packageName}/dist/${componentName}.js";</code>
39
- *
40
- * @constructor
41
- * @author SAP SE
42
- * @alias sap.ui.webcomponents.${library}.${componentName}
43
- * @extends UI5Element
44
- * @tagname ${tagName}
45
- * @public
46
- */
47
- class ${componentName} extends UI5Element {
48
- static get metadata() {
49
- return metadata;
50
- }
51
-
52
- static get render() {
53
- return litRender;
54
- }
55
-
56
- static get styles() {
57
- return ${componentName}Css;
58
- }
59
-
60
- static get template() {
61
- return ${componentName}Template;
62
- }
63
-
64
- static get dependencies() {
65
- return [];
66
- }
67
-
68
- static async onDefine() {
69
-
70
- }
71
- }
72
-
73
- ${componentName}.define();
74
-
75
- export default ${componentName};
76
- `;
77
- };
2
+ const prompts = require("prompts");
3
+ const jsFileContentTemplate = require("./jsFileContentTemplate.js");
4
+ const tsFileContentTemplate = require("./tsFileContentTemplate.js");
78
5
 
79
6
  const getPackageName = () => {
80
7
  if (!fs.existsSync("./package.json")) {
@@ -108,47 +35,117 @@ const getLibraryName = packageName => {
108
35
  return packageName.substr("webcomponents-".length);
109
36
  };
110
37
 
111
- const camelToKebabCase = string => string.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
38
+ // String manipulation
39
+ const capitalizeFirstLetter = string => string.charAt(0).toUpperCase() + string.slice(1);
40
+
41
+ // Validation of user input
42
+ const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/);
43
+ const isTagNameValid = tagName => tagName.match(/^([a-z][a-z0-9]*-)([a-z0-9]+(-[a-z0-9]+)*)$/);
44
+
45
+ const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
46
+ componentName = capitalizeFirstLetter(componentName);
47
+ const filePaths = {
48
+ "main": isTypeScript
49
+ ? `./src/${componentName}.ts`
50
+ : `./src/${componentName}.js`,
51
+ "css": `./src/themes/${componentName}.css`,
52
+ "template": `./src/${componentName}.hbs`,
53
+ };
112
54
 
113
- const packageName = getPackageName();
114
- const library = getLibraryName(packageName);
55
+ const FileContentTemplate = isTypeScript
56
+ ? tsFileContentTemplate(componentName, tagName, library, packageName)
57
+ : jsFileContentTemplate(componentName, tagName, library, packageName);
115
58
 
116
- const consoleArguments = process.argv.slice(2);
117
- const componentName = consoleArguments[0];
59
+ fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
60
+ fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
61
+ fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
118
62
 
119
- if (!componentName){
120
- console.error("Please enter component name.");
121
- return;
63
+ console.log(`Successfully generated ${filePaths.main}`);
64
+ console.log(`Successfully generated ${filePaths.css}`);
65
+ console.log(`Successfully generated ${filePaths.template}`);
66
+
67
+ // Change the color of the output
68
+ console.warn('\x1b[33m%s\x1b[0m', `
69
+ Make sure to import the component in your bundle by using:
70
+ import ${componentName} from "./dist/${componentName}.js";`);
122
71
  }
123
72
 
124
- const tagName = `ui5-${camelToKebabCase(componentName)}`;
73
+ // Main function
74
+ const createWebComponent = async () => {
75
+ const packageName = getPackageName();
76
+ const library = getLibraryName(packageName);
125
77
 
126
- const filePaths = {
127
- "js": `./src/${componentName}.js`,
128
- "css": `./src/themes/${componentName}.css`,
129
- "hbs": `./src/${componentName}.hbs`,
130
- };
131
- const sJsFileContentTemplate = jsFileContentTemplate(componentName);
78
+ const consoleArguments = process.argv.slice(2);
79
+ let componentName = consoleArguments[0];
80
+ let tagName = consoleArguments[1];
81
+ let language = consoleArguments[2];
82
+ let isTypeScript;
132
83
 
133
- fs.writeFileSync(filePaths.js, sJsFileContentTemplate, { flag: "wx+" });
134
- fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
135
- fs.writeFileSync(filePaths.hbs, "<div>Hello World</div>", { flag: "wx+" });
136
84
 
85
+ if (componentName && !isNameValid(componentName)) {
86
+ throw new Error("Invalid component name. Please use only letters, numbers, dashes and underscores. The first character must be a letter.");
87
+ }
137
88
 
138
- console.log(`Successfully generated ${componentName}.js`);
139
- console.log(`Successfully generated ${componentName}.css`);
140
- console.log(`Successfully generated ${componentName}.hbs`);
89
+ if (tagName && !isTagNameValid(tagName)) {
90
+ throw new Error("Invalid tag name. The tag name should only contain lowercase letters, numbers, dashes, and underscores. The first character must be a letter, and it should follow the pattern 'tag-name'.");
91
+ }
141
92
 
142
- const bundleLogger = fs.createWriteStream("./bundle.common.js", {
143
- flags: "a" // appending
144
- });
93
+ if (language && language !== "typescript" && language !== "ts" && language !== "javascript" && language !== "js") {
94
+ throw new Error("Invalid language. Please use 'typescript','javascript' or their respective 'ts','js'.");
95
+ }
145
96
 
146
- bundleLogger.write(`
147
- // TODO: Move this line in order to keep the file sorted alphabetically
148
- import ${componentName} from "./dist/${componentName}.js";`);
97
+ if (!componentName) {
98
+ const response = await prompts({
99
+ type: "text",
100
+ name: "componentName",
101
+ message: "Please enter a component name:",
102
+ validate: (value) => isNameValid(value),
103
+ });
104
+ componentName = response.componentName;
105
+
106
+ if (!componentName) {
107
+ process.exit();
108
+ }
109
+ }
149
110
 
150
- // Change the color of the output
151
- console.warn('\x1b[33m%s\x1b[0m', `
152
- Component is imported in bundle.common.js.
153
- Do NOT forget to sort the file in alphabeticall order.
154
- `);
111
+ if (!tagName) {
112
+ const response = await prompts({
113
+ type: "text",
114
+ name: "tagName",
115
+ message: "Please enter a tag name:",
116
+ validate: (value) => isTagNameValid(value),
117
+ });
118
+ tagName = response.tagName;
119
+
120
+ if (!tagName) {
121
+ process.exit();
122
+ }
123
+ }
124
+
125
+ if (!language) {
126
+ const response = await prompts({
127
+ type: "select",
128
+ name: "isTypeScript",
129
+ message: "Please select a language:",
130
+ choices: [
131
+ {
132
+ title: "TypeScript (recommended)",
133
+ value: true,
134
+ },
135
+ {
136
+ title: "JavaScript",
137
+ value: false,
138
+ },
139
+ ],
140
+ });
141
+ isTypeScript = response.isTypeScript;
142
+ } else if (language === "typescript" || language === "ts") {
143
+ isTypeScript = true;
144
+ } else {
145
+ isTypeScript = false;
146
+ }
147
+
148
+ generateFiles(componentName, tagName, library, packageName, isTypeScript);
149
+ };
150
+
151
+ createWebComponent();
@@ -0,0 +1,77 @@
1
+ const jsFileContentTemplate = (componentName, tagName, library, packageName) => {
2
+ return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
3
+ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
4
+ import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
5
+
6
+ // Styles
7
+ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
8
+
9
+ /**
10
+ * @public
11
+ */
12
+ const metadata = {
13
+ tag: "${tagName}",
14
+ properties: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
15
+ //
16
+ },
17
+ slots: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
18
+ //
19
+ },
20
+ events: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
21
+ //
22
+ },
23
+ };
24
+
25
+ /**
26
+ * @class
27
+ *
28
+ * <h3 class="comment-api-title">Overview</h3>
29
+ *
30
+ *
31
+ * <h3>Usage</h3>
32
+ *
33
+ * For the <code>${tagName}</code>
34
+ * <h3>ES6 Module Import</h3>
35
+ *
36
+ * <code>import ${packageName}/dist/${componentName}.js";</code>
37
+ *
38
+ * @constructor
39
+ * @author SAP SE
40
+ * @alias sap.ui.webc.${library}.${componentName}
41
+ * @extends sap.ui.webc.base.UI5Element
42
+ * @tagname ${tagName}
43
+ * @public
44
+ */
45
+ class ${componentName} extends UI5Element {
46
+ static get metadata() {
47
+ return metadata;
48
+ }
49
+
50
+ static get render() {
51
+ return litRender;
52
+ }
53
+
54
+ static get styles() {
55
+ return ${componentName}Css;
56
+ }
57
+
58
+ static get template() {
59
+ return ${componentName}Template;
60
+ }
61
+
62
+ static get dependencies() {
63
+ return [];
64
+ }
65
+
66
+ static async onDefine() {
67
+
68
+ }
69
+ }
70
+
71
+ ${componentName}.define();
72
+
73
+ export default ${componentName};
74
+ `;
75
+ };
76
+
77
+ module.exports = jsFileContentTemplate;
@@ -0,0 +1,84 @@
1
+ const tsFileContentTemplate = (componentName, tagName, library, packageName) => {
2
+ return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
3
+ import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
4
+ import property from "@ui5/webcomponents-base/dist/decorators/property.js";
5
+ import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
6
+ import event from "@ui5/webcomponents-base/dist/decorators/event.js";
7
+ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
8
+
9
+ import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
10
+
11
+ // Styles
12
+ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
13
+
14
+ /**
15
+ * @class
16
+ *
17
+ * <h3 class="comment-api-title">Overview</h3>
18
+ *
19
+ *
20
+ * <h3>Usage</h3>
21
+ *
22
+ * For the <code>${tagName}</code>
23
+ * <h3>ES6 Module Import</h3>
24
+ *
25
+ * <code>import ${packageName}/dist/${componentName}.js";</code>
26
+ *
27
+ * @constructor
28
+ * @author SAP SE
29
+ * @alias sap.ui.webc.${library}.${componentName}
30
+ * @extends sap.ui.webc.base.UI5Element
31
+ * @tagname ${tagName}
32
+ * @public
33
+ */
34
+ @customElement({
35
+ tag: "${tagName}",
36
+ renderer: litRender,
37
+ styles: ${componentName}Css,
38
+ template: ${componentName}Template,
39
+ dependencies: [],
40
+ })
41
+
42
+ /**
43
+ * Example custom event.
44
+ * Please keep in mind that all public events should be documented in the API Reference as shown below.
45
+ *
46
+ * @event sap.ui.webc.${library}.${componentName}#interact
47
+ * @public
48
+ */
49
+ @event("interact", { detail: { /* event payload ( optional ) */ } })
50
+ class ${componentName} extends UI5Element {
51
+ /**
52
+ * Defines the value of the component.
53
+ *
54
+ * @type {string}
55
+ * @name sap.ui.webc.${library}.${componentName}.prototype.value
56
+ * @defaultvalue ""
57
+ * @public
58
+ */
59
+ @property()
60
+ value!: string;
61
+
62
+ /**
63
+ * Defines the text of the component.
64
+ *
65
+ * @type {Node[]}
66
+ * @name sap.ui.webc.${library}.${componentName}.prototype.default
67
+ * @slot
68
+ * @public
69
+ */
70
+ @slot({ type: Node, "default": true })
71
+ text!: Array<Node>;
72
+
73
+ static async onDefine() {
74
+
75
+ }
76
+ }
77
+
78
+ ${componentName}.define();
79
+
80
+ export default ${componentName};
81
+ `;
82
+ };
83
+
84
+ module.exports = tsFileContentTemplate;
@@ -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,14 @@
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
10
  // console.log("scanning imports of", srcPath);
12
- let code = fs.readFileSync(srcPath).toString();
11
+ let code = (await fs.readFile(srcPath)).toString();
13
12
  const tree = esprima.parseModule(code);
14
13
  const importer = srcPath.replace(basePath, "");
15
14
  const importerDir = path.dirname(importer);
@@ -44,11 +43,16 @@ const convertImports = (srcPath) => {
44
43
  });
45
44
 
46
45
  if (changed) {
47
- fs.writeFileSync(srcPath, escodegen.generate(tree));
46
+ return fs.writeFile(srcPath, escodegen.generate(tree));
48
47
  }
49
48
  }
50
49
 
51
- const fileNames = glob.sync(basePath + "**/*.js");
52
- // console.log(fileNames);
53
- fileNames.forEach(convertImports);
54
- console.log("Success: Converted absolute imports to relative for files in:", basePath)
50
+ const generate = async () => {
51
+ const { globby } = await import("globby");
52
+ const fileNames = await globby(basePath + "**/*.js");
53
+ return Promise.all(fileNames.map(convertImports).filter(x => !!x));
54
+ };
55
+
56
+ generate().then(() => {
57
+ console.log("Success: Converted absolute imports to relative for files in:", basePath);
58
+ });