@ui5/webcomponents-tools 0.0.0-fd6264051 → 0.0.0-ff1549e7b

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 +375 -0
  2. package/README.md +5 -6
  3. package/assets-meta.js +1 -0
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +34 -0
  6. package/components-package/nps.js +87 -58
  7. package/components-package/postcss.components.js +13 -13
  8. package/components-package/postcss.themes.js +26 -16
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +401 -369
  11. package/components-package/wdio.sync.js +10 -2
  12. package/icons-collection/nps.js +8 -11
  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 -72
  16. package/lib/create-illustrations/index.js +101 -90
  17. package/lib/create-new-component/index.js +71 -104
  18. package/lib/create-new-component/jsFileContentTemplate.js +73 -0
  19. package/lib/create-new-component/tsFileContentTemplate.js +80 -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 +24 -4
  28. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  29. package/lib/hbs2lit/src/litVisitor2.js +85 -22
  30. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  31. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
  32. package/lib/hbs2ui5/index.js +56 -23
  33. package/lib/i18n/defaults.js +65 -57
  34. package/lib/i18n/toJSON.js +12 -11
  35. package/lib/jsdoc/configTypescript.json +29 -0
  36. package/lib/jsdoc/plugin.js +32 -0
  37. package/lib/jsdoc/preprocess.js +146 -0
  38. package/lib/jsdoc/template/publish.js +9 -1
  39. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  40. package/lib/postcss-css-to-esm/index.js +51 -6
  41. package/lib/postcss-css-to-json/index.js +12 -1
  42. package/lib/postcss-p/postcss-p.mjs +14 -0
  43. package/lib/replace-global-core/index.js +13 -8
  44. package/lib/scoping/get-all-tags.js +1 -8
  45. package/lib/scoping/scope-test-pages.js +1 -1
  46. package/lib/test-runner/test-runner.js +71 -0
  47. package/package.json +27 -26
  48. package/components-package/rollup-plugins/empty-module.js +0 -15
  49. package/components-package/rollup.js +0 -239
  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 -42
  56. package/lib/documentation/templates/api-slots-section.js +0 -28
  57. package/lib/documentation/templates/template.js +0 -39
  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,30 @@
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";
2
+ const path = require("path");
3
+ const prompts = require("prompts");
4
+ const jsFileContentTemplate = require("./jsFileContentTemplate.js");
5
+ const tsFileContentTemplate = require("./tsFileContentTemplate.js");
10
6
 
11
7
  /**
12
- * @public
8
+ * Hyphanates the given PascalCase string, f.e.:
9
+ * Foo -> "my-foo" (adds preffix)
10
+ * FooBar -> "foo-bar"
13
11
  */
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
- },
12
+ const hyphaneteComponentName = (componentName) => {
13
+ const result = componentName.replace(/([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
14
+
15
+ return result.includes("-") ? result : `my-${result}`;
25
16
  };
26
17
 
27
18
  /**
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
19
+ * Capitalizes first letter of string.
46
20
  */
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();
21
+ const capitalizeFirstLetter = string => string.charAt(0).toUpperCase() + string.slice(1);
74
22
 
75
- export default ${componentName};
76
- `;
77
- };
23
+ /**
24
+ * Validates component name, enforcing PascalCase pattern - Button, MyButton.
25
+ */
26
+ const PascalCasePattern = /^[A-Z][A-Za-z0-9]+$/;
27
+ const isNameValid = name => typeof name === "string" && PascalCasePattern.test(name);
78
28
 
79
29
  const getPackageName = () => {
80
30
  if (!fs.existsSync("./package.json")) {
@@ -108,47 +58,64 @@ const getLibraryName = packageName => {
108
58
  return packageName.substr("webcomponents-".length);
109
59
  };
110
60
 
111
- const camelToKebabCase = string => string.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
112
-
113
- const packageName = getPackageName();
114
- const library = getLibraryName(packageName);
115
-
116
- const consoleArguments = process.argv.slice(2);
117
- const componentName = consoleArguments[0];
118
-
119
- if (!componentName){
120
- console.error("Please enter component name.");
121
- return;
61
+ const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
62
+ componentName = capitalizeFirstLetter(componentName);
63
+ const filePaths = {
64
+ "main": isTypeScript
65
+ ? `./src/${componentName}.ts`
66
+ : `./src/${componentName}.js`,
67
+ "css": `./src/themes/${componentName}.css`,
68
+ "template": `./src/${componentName}.hbs`,
69
+ };
70
+
71
+ const FileContentTemplate = isTypeScript
72
+ ? tsFileContentTemplate(componentName, tagName, library, packageName)
73
+ : jsFileContentTemplate(componentName, tagName, library, packageName);
74
+
75
+ fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
76
+ fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
77
+ fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
78
+
79
+ console.log(`Successfully generated ${filePaths.main}`);
80
+ console.log(`Successfully generated ${filePaths.css}`);
81
+ console.log(`Successfully generated ${filePaths.template}`);
82
+
83
+ // Change the color of the output
84
+ console.warn('\x1b[33m%s\x1b[0m', `
85
+ Make sure to import the component in your bundle by using:
86
+ import ${componentName} from "./dist/${componentName}.js";`);
122
87
  }
123
88
 
124
- const tagName = `ui5-${camelToKebabCase(componentName)}`;
125
-
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);
89
+ // Main function
90
+ const createWebComponent = async () => {
91
+ const packageName = getPackageName();
92
+ const library = getLibraryName(packageName);
132
93
 
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+" });
94
+ const consoleArguments = process.argv.slice(2);
95
+ let componentName = consoleArguments[0];
136
96
 
97
+ if (componentName && !isNameValid(componentName)) {
98
+ throw new Error(`${componentName} is invalid component name. Use only letters (at least two) and start with capital one: Button, MyButton, etc.`);
99
+ }
137
100
 
138
- console.log(`Successfully generated ${componentName}.js`);
139
- console.log(`Successfully generated ${componentName}.css`);
140
- console.log(`Successfully generated ${componentName}.hbs`);
101
+ if (!componentName) {
102
+ const response = await prompts({
103
+ type: "text",
104
+ name: "componentName",
105
+ message: "Please enter a component name:",
106
+ validate: (value) => isNameValid(value) ? true : "Component name should follow PascalCase naming convention (f.e. Button, MyButton, etc.).",
107
+ });
108
+ componentName = response.componentName;
109
+
110
+ if (!componentName) {
111
+ process.exit();
112
+ }
113
+ }
141
114
 
142
- const bundleLogger = fs.createWriteStream("./bundle.common.js", {
143
- flags: "a" // appending
144
- });
115
+ const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
116
+ const tagName = hyphaneteComponentName(componentName);
145
117
 
146
- bundleLogger.write(`
147
- // TODO: Move this line in order to keep the file sorted alphabetically
148
- import ${componentName} from "./dist/${componentName}.js";`);
118
+ generateFiles(componentName, tagName, library, packageName, isTypeScript);
119
+ };
149
120
 
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
- `);
121
+ createWebComponent();
@@ -0,0 +1,73 @@
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
+
67
+ ${componentName}.define();
68
+
69
+ export default ${componentName};
70
+ `;
71
+ };
72
+
73
+ module.exports = jsFileContentTemplate;
@@ -0,0 +1,80 @@
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
+
74
+ ${componentName}.define();
75
+
76
+ export default ${componentName};
77
+ `;
78
+ };
79
+
80
+ 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.replace(/\\/g, "/") + "**/*.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
+ });