@ui5/create-webcomponents-package 0.0.0-2f7664755 → 0.0.0-354b6d238

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,124 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.13.0-rc.3](https://github.com/SAP/ui5-webcomponents/compare/v1.13.0-rc.2...v1.13.0-rc.3) (2023-04-27)
7
+
8
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
9
+
10
+
11
+
12
+
13
+
14
+ # [1.13.0-rc.2](https://github.com/SAP/ui5-webcomponents/compare/v1.13.0-rc.1...v1.13.0-rc.2) (2023-04-20)
15
+
16
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
17
+
18
+
19
+
20
+
21
+
22
+ # [1.13.0-rc.1](https://github.com/SAP/ui5-webcomponents/compare/v1.13.0-rc.0...v1.13.0-rc.1) (2023-04-13)
23
+
24
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
25
+
26
+
27
+
28
+
29
+
30
+ # [1.13.0-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.12.0...v1.13.0-rc.0) (2023-04-06)
31
+
32
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
33
+
34
+
35
+
36
+
37
+
38
+ # [1.12.0](https://github.com/SAP/ui5-webcomponents/compare/v1.12.0-rc.3...v1.12.0) (2023-04-04)
39
+
40
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
41
+
42
+
43
+
44
+
45
+
46
+ # [1.12.0-rc.3](https://github.com/SAP/ui5-webcomponents/compare/v1.12.0-rc.2...v1.12.0-rc.3) (2023-03-30)
47
+
48
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
49
+
50
+
51
+
52
+
53
+
54
+ # [1.12.0-rc.2](https://github.com/SAP/ui5-webcomponents/compare/v1.12.0-rc.1...v1.12.0-rc.2) (2023-03-23)
55
+
56
+
57
+ ### Bug Fixes
58
+
59
+ * inline sources in the .map file so the src folder is not mandatory ([#6732](https://github.com/SAP/ui5-webcomponents/issues/6732)) ([16771a6](https://github.com/SAP/ui5-webcomponents/commit/16771a64d7b13f418af9afa1a03b224fe3762775))
60
+
61
+
62
+
63
+
64
+
65
+ # [1.12.0-rc.1](https://github.com/SAP/ui5-webcomponents/compare/v1.12.0-rc.0...v1.12.0-rc.1) (2023-03-16)
66
+
67
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
68
+
69
+
70
+
71
+
72
+
73
+ # [1.12.0-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0...v1.12.0-rc.0) (2023-03-09)
74
+
75
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
76
+
77
+
78
+
79
+
80
+
81
+ # [1.11.0](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.4...v1.11.0) (2023-03-06)
82
+
83
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
84
+
85
+
86
+
87
+
88
+
89
+ # [1.11.0-rc.4](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.3...v1.11.0-rc.4) (2023-03-02)
90
+
91
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
92
+
93
+
94
+
95
+
96
+
97
+ # [1.11.0-rc.3](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.2...v1.11.0-rc.3) (2023-02-23)
98
+
99
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
100
+
101
+
102
+
103
+
104
+
105
+ # [1.11.0-rc.2](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.1...v1.11.0-rc.2) (2023-02-16)
106
+
107
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
108
+
109
+
110
+
111
+
112
+
113
+ # [1.11.0-rc.1](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.0...v1.11.0-rc.1) (2023-02-09)
114
+
115
+
116
+ ### Features
117
+
118
+ * **framework:** add option to define package name, tag and typescript support from CLI ([#6379](https://github.com/SAP/ui5-webcomponents/issues/6379)) ([687c0f7](https://github.com/SAP/ui5-webcomponents/commit/687c0f7a420a72f77f294ace2898223c48708ae2)), closes [#6382](https://github.com/SAP/ui5-webcomponents/issues/6382)
119
+
120
+
121
+
122
+
123
+
6
124
  # [1.11.0-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.10.4-rc.0...v1.11.0-rc.0) (2023-02-02)
7
125
 
8
126
  **Note:** Version bump only for package @ui5/create-webcomponents-package
package/README.md CHANGED
@@ -13,13 +13,14 @@ Usage:
13
13
 
14
14
  # npm 6.x
15
15
  npm init @ui5/webcomponents-package [OPTIONS]
16
- # npm 7+, extra double-dash is needed:
16
+ # npm 7+, an extra double-dash is needed:
17
17
  npm init @ui5/webcomponents-package -- [OPTIONS]
18
18
 
19
19
  Options:
20
- --name <string> - defines package name
21
- --tag <string> - defines predefined custom element tag name
22
- --enable-typescript - enables TypeScript support to the package
20
+ --name <string> - defines the package name
21
+ --componentName <string> - defines the component class name that will be created in your new package
22
+ --tag <string> - defines the tag name of the sample web component that will be created in your new package. The tag will be derived from the component name if not provided.
23
+ --enable-typescript - enables TypeScript support for the package
23
24
  --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
24
25
  ```
25
26
 
@@ -32,10 +33,10 @@ components package.
32
33
  Usage:
33
34
  yarn create @ui5/webcomponents-package [OPTIONS]
34
35
  Options:
35
- --name <string> - defines package name
36
- --tag <string> - defines predefined custom element tag name
37
- --enable-typescript - enables TypeScript support to the package
38
- --skip - skips all configurations and generates package with default configurations
36
+ --name <string> - defines the package name
37
+ --tag <string> - defines the tag name of the sample web component that will be created in your new package
38
+ --enable-typescript - enables TypeScript support for the package
39
+ --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
39
40
  ```
40
41
 
41
42
  The script creates a new directory, and fills it with a `package.json` file and all necessary source files, and resources for a new
package/create-package.js CHANGED
@@ -5,8 +5,8 @@ const path = require("path");
5
5
  const mkdirp = require("mkdirp");
6
6
  const prompts = require("prompts");
7
7
  const parser = require("npm-config-user-agent-parser");
8
- const yargs = require('yargs/yargs');
9
- const { hideBin } = require('yargs/helpers');
8
+ const yargs = require("yargs/yargs");
9
+ const { hideBin } = require("yargs/helpers");
10
10
 
11
11
  const argv = yargs(hideBin(process.argv)).argv;
12
12
 
@@ -23,14 +23,36 @@ const toCamelCase = parts => {
23
23
  return index === 0 ? string.toLowerCase() : string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
24
24
  }).join("");
25
25
  };
26
- const isTypescriptRelatedFile = sourcePath => {
27
- return ["Аssets.ts", "MyFirstComponent.ts", "tsconfig.json", "global.d.ts"].some(fileName => sourcePath.includes(fileName));
28
- }
26
+ const isTSRelatedFile = sourcePath => {
27
+ return ["Assets.ts", "MyFirstComponent.ts", "tsconfig.json", "global.d.ts"].some(fileName => sourcePath.includes(fileName));
28
+ };
29
+ const isJSRelatedFile = sourcePath => {
30
+ return ["Assets.js", "MyFirstComponent.js"].some(fileName => sourcePath.includes(fileName));
31
+ };
32
+ const isGitIgnore = sourcePath => {
33
+ return sourcePath.includes("gitignore");
34
+ };
35
+ const isNPMRC = sourcePath => {
36
+ return sourcePath.includes("npmrc");
37
+ };
29
38
 
30
39
  // Validation of user input
31
- const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z0-9\-_]+$/);
40
+ const ComponentNamePattern = /^[A-Z][A-Za-z0-9]+$/;
41
+ const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z][a-zA-Z0-9\-_]+$/);
42
+ const isComponentNameValid = name => typeof name === "string" && ComponentNamePattern.test(name);
32
43
  const isTagValid = tag => typeof tag === "string" && tag.match(/^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/);
33
44
 
45
+ /**
46
+ * Hyphanates the given PascalCase string, f.e.:
47
+ * Foo -> "my-foo" (adds preffix)
48
+ * FooBar -> "foo-bar"
49
+ */
50
+ const hyphaneteComponentName = (componentName) => {
51
+ const result = componentName.replace(/([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
52
+
53
+ return result.includes("-") ? result : `my-${result}`;
54
+ };
55
+
34
56
  // Utils for building the file structure
35
57
  const replaceVarsInFileContent = (vars, content) => {
36
58
  for (let key in vars) {
@@ -45,17 +67,28 @@ const replaceVarsInFileName = (vars, fileName) => {
45
67
  };
46
68
 
47
69
  const copyFile = (vars, sourcePath, destPath) => {
48
- const ignoreJsRelated = vars.INIT_PACKAGE_VAR_TYPESCRIPT && sourcePath.includes("MyFirstComponent.js")
49
- const ignoreTsRelated = !vars.INIT_PACKAGE_VAR_TYPESCRIPT && isTypescriptRelatedFile(sourcePath)
70
+ const ignoreJsRelated = vars.INIT_PACKAGE_VAR_TYPESCRIPT && isJSRelatedFile(sourcePath);
71
+ const ignoreTsRelated = !vars.INIT_PACKAGE_VAR_TYPESCRIPT && isTSRelatedFile(sourcePath);
50
72
 
51
73
  if (ignoreJsRelated || ignoreTsRelated) {
52
74
  return;
53
75
  }
54
76
 
55
- let content = fs.readFileSync(sourcePath, {encoding: "UTF-8"});
77
+ let content = fs.readFileSync(sourcePath, { encoding: "UTF-8" });
56
78
  content = replaceVarsInFileContent(vars, content);
57
79
  destPath = replaceVarsInFileName(vars, destPath);
80
+
58
81
  fs.writeFileSync(destPath, content);
82
+
83
+ // Rename "gitignore" to ".gitignore" (npm init won't include ".gitignore", so we add it as "gitignore" and rename it later)
84
+ if (isGitIgnore(sourcePath)) {
85
+ fs.renameSync(destPath, destPath.replace("gitignore", ".gitignore"))
86
+ }
87
+
88
+ // Rename "npmrc" to ".npmrc" (npm init won't include ".npmrc", so we add it as "npmrc" and rename it later)
89
+ if (isNPMRC(sourcePath)) {
90
+ fs.renameSync(destPath, destPath.replace("npmrc", ".npmrc"));
91
+ }
59
92
  };
60
93
 
61
94
  const copyFiles = (vars, sourcePath, destPath) => {
@@ -72,16 +105,15 @@ const copyFiles = (vars, sourcePath, destPath) => {
72
105
  }
73
106
  };
74
107
 
75
-
76
- const generateFilesContent = (name, tag, typescript) => {
77
- const className = capitalizeFirst(kebabToCamelCase(tag));
108
+ const generateFilesContent = (name, componentName, typescript, skipSubfolder) => {
109
+ const tagName = argv.tag || hyphaneteComponentName(componentName);
78
110
 
79
111
  // All variables that will be replaced in the content of the resources/
80
112
  const vars = {
81
113
  INIT_PACKAGE_VAR_NAME: name,
82
- INIT_PACKAGE_VAR_TAG: tag,
83
- INIT_PACKAGE_VAR_CLASS_NAME: className,
84
- INIT_PACKAGE_VAR_TYPESCRIPT: typescript
114
+ INIT_PACKAGE_VAR_TAG: tagName,
115
+ INIT_PACKAGE_VAR_CLASS_NAME: componentName,
116
+ INIT_PACKAGE_VAR_TYPESCRIPT: typescript,
85
117
  };
86
118
 
87
119
  const packageContent = {
@@ -117,8 +149,12 @@ const generateFilesContent = (name, tag, typescript) => {
117
149
  },
118
150
  };
119
151
 
152
+ if (typescript) {
153
+ packageContent.devDependencies.typescript = "^4.9.4";
154
+ }
155
+
120
156
  // Update package.json
121
- const destDir = path.join(`./`, name);
157
+ const destDir = skipSubfolder ? path.join("./") : path.join("./", name);
122
158
  mkdirp.sync(destDir);
123
159
  fs.writeFileSync(path.join(destDir, "package.json"), JSON.stringify(packageContent, null, 2));
124
160
  // Copy files
@@ -141,25 +177,30 @@ const generateFilesContent = (name, tag, typescript) => {
141
177
  }
142
178
 
143
179
  console.log("\n");
144
- }
180
+ };
145
181
 
146
182
  // Main function
147
183
  const createWebcomponentsPackage = async () => {
148
184
  let response;
149
185
  if (argv.name && !isNameValid(argv.name)) {
150
- throw new Error("The package name should be a string (a-z, A-Z, 0-9).");
186
+ throw new Error("The package name should be a string, starting with letter and containing the following symbols [a-z, A-Z, 0-9].");
187
+ }
188
+
189
+ if (argv.componentName && !isComponentNameValid(argv.componentName)) {
190
+ throw new Error("The component name should be a string, starting with a capital letter [A-Z][a-z], for example: Button, MyButton, etc.");
151
191
  }
152
192
 
153
193
  if (argv.tag && !isTagValid(argv.tag) ) {
154
- throw new Error("The tag should be in kebab-case (my-first-component f.e) and it can't be a single word.");
194
+ throw new Error("The tag should be in kebab-case (f.e my-component) and it can't be a single word.");
155
195
  }
156
196
 
157
197
  let name = argv.name || "my-package";
158
- let tag = argv.tag || "my-first-component";
198
+ let componentName = argv.componentName || "MyComponent";
159
199
  let typescriptSupport = !!argv.enableTypescript;
200
+ const skipSubfolder = !!argv.skipSubfolder;
160
201
 
161
- if (!!argv.skip) {
162
- return generateFilesContent(name, tag, typescriptSupport);
202
+ if (argv.skip) {
203
+ return generateFilesContent(name, componentName, typescriptSupport, skipSubfolder);
163
204
  }
164
205
 
165
206
  if (!argv.name) {
@@ -167,7 +208,7 @@ const createWebcomponentsPackage = async () => {
167
208
  type: "text",
168
209
  name: "name",
169
210
  message: "Package name:",
170
- validate: isNameValid,
211
+ validate: (value) => isNameValid(value) ? true : "Package name should be a string, starting with a letter and containing the following symbols [a-z, A-Z ,0-9, _, -].",
171
212
  });
172
213
  name = response.name;
173
214
  }
@@ -186,23 +227,23 @@ const createWebcomponentsPackage = async () => {
186
227
  title: "TypeScript",
187
228
  value: true,
188
229
  },
189
- ]
230
+ ],
190
231
  });
191
- typescript = response.language;
232
+ typescriptSupport = response.language;
192
233
  }
193
234
 
194
- if (!argv.tag) {
235
+ if (!argv.componentName) {
195
236
  response = await prompts({
196
237
  type: "text",
197
- name: "tag",
238
+ name: "componentName",
198
239
  message: "Component name:",
199
- initial: "my-first-component",
200
- validate: isTagValid,
240
+ initial: "MyComponent",
241
+ validate: (value) => isComponentNameValid(value) ? true : "Component name should follow PascalCase naming convention (f.e. Button, MyButton, etc.).",
201
242
  });
202
- tag = response.tag;
243
+ componentName = response.componentName;
203
244
  }
204
245
 
205
- return generateFilesContent(name, tag, typescript);
246
+ return generateFilesContent(name, componentName, typescriptSupport, skipSubfolder);
206
247
  };
207
248
 
208
249
  createWebcomponentsPackage();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/create-webcomponents-package",
3
- "version": "0.0.0-2f7664755",
3
+ "version": "0.0.0-354b6d238",
4
4
  "description": "UI5 Web Components: create package",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -2,4 +2,5 @@
2
2
  dist
3
3
  test
4
4
  src/generated
5
- jsdoc-dist
5
+ jsdoc-dist
6
+ .eslintrc.js
@@ -0,0 +1,5 @@
1
+ const config = require("@ui5/webcomponents-tools/components-package/eslint.js");
2
+
3
+ // This eslint config is defined @ui5/webcomponents-tools,
4
+ // Feel free to override part of the configuration or provide entirely new config to fit your dev requirements.
5
+ module.exports = config;
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ dist
3
+ jsdoc-dist
4
+ src/generated
package/template/npmrc ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect the chromedriver version
2
+ detect_chromedriver_version=true
@@ -25,22 +25,15 @@ import { PLEASE_WAIT } from "./generated/i18n/i18n-defaults.js";
25
25
  * @tagname INIT_PACKAGE_VAR_TAG
26
26
  * @public
27
27
  */
28
- @customElement("INIT_PACKAGE_VAR_TAG")
28
+ @customElement({
29
+ tag: "INIT_PACKAGE_VAR_TAG",
30
+ renderer: litRender,
31
+ styles: INIT_PACKAGE_VAR_CLASS_NAMECss,
32
+ template: INIT_PACKAGE_VAR_CLASS_NAMETemplate,
33
+ })
29
34
  class INIT_PACKAGE_VAR_CLASS_NAME extends UI5Element {
30
35
  static i18nBundle: I18nBundle;
31
36
 
32
- static get render() {
33
- return litRender;
34
- }
35
-
36
- static get template() {
37
- return INIT_PACKAGE_VAR_CLASS_NAMETemplate;
38
- }
39
-
40
- static get styles() {
41
- return INIT_PACKAGE_VAR_CLASS_NAMECss;
42
- }
43
-
44
37
  static async onDefine() {
45
38
  INIT_PACKAGE_VAR_CLASS_NAME.i18nBundle = await getI18nBundle("INIT_PACKAGE_VAR_NAME");
46
39
  }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: blue;
3
+ }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: white;
3
+ }
@@ -28,13 +28,14 @@
28
28
  <li><a href="?sap-ui-theme=sap_fiori_3_dark">Fiori 3 Dark</a></li>
29
29
  <li><a href="?sap-ui-theme=sap_fiori_3_hcb">Fiori 3 High Contrast Black</a></li>
30
30
  <li><a href="?sap-ui-theme=sap_fiori_3_hcw">Fiori 3 High Contrast White</a></li>
31
- <li><a href="?sap-ui-theme=sap_belize">Belize</a></li>
32
- <li><a href="?sap-ui-theme=sap_belize_hcb">Belize High Contrast Black</a></li>
33
- <li><a href="?sap-ui-theme=sap_belize_hcw">Belize High Contrast White</a></li>
31
+ <li><a href="?sap-ui-theme=sap_horizon">Horizon</a></li>
32
+ <li><a href="?sap-ui-theme=sap_horizon_dark">Horizon Dark</a></li>
33
+ <li><a href="?sap-ui-theme=sap_horizon_hcb">Horizon High Contrast Black</a></li>
34
+ <li><a href="?sap-ui-theme=sap_horizon_hcw">Horizon High Contrast White</a></li>
34
35
  </ul>
35
36
  <br>
36
37
  <span>or in the browser console, for example:</span>
37
- <code>window['sap-ui-webcomponents-bundle'].configuration.setTheme("sap_belize_hcb")</code>
38
+ <code>window['sap-ui-webcomponents-bundle'].configuration.setTheme("sap_horizon_hcb")</code>
38
39
 
39
40
  <br><br>
40
41
 
@@ -1,7 +1,9 @@
1
1
  const assert = require("assert");
2
2
 
3
3
  describe("INIT_PACKAGE_VAR_TAG rendering", async () => {
4
- await browser.url("test/pages/index.html");
4
+ before(async () => {
5
+ await browser.url("test/pages/index.html");
6
+ });
5
7
 
6
8
  it("tests if web component is correctly rendered", async () => {
7
9
 
@@ -7,6 +7,7 @@
7
7
  "outDir": "dist",
8
8
  "skipLibCheck": true,
9
9
  "sourceMap": true,
10
+ "inlineSources": true,
10
11
  "strict": true,
11
12
  "moduleResolution": "node",
12
13
  "experimentalDecorators": true,
@@ -1,3 +0,0 @@
1
- :root {
2
- --my-component-border-color: black;
3
- }