@ui5/create-webcomponents-package 1.11.0-rc.0 → 1.11.0-rc.2

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,25 @@
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.11.0-rc.2](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.1...v1.11.0-rc.2) (2023-02-16)
7
+
8
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
9
+
10
+
11
+
12
+
13
+
14
+ # [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)
15
+
16
+
17
+ ### Features
18
+
19
+ * **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)
20
+
21
+
22
+
23
+
24
+
6
25
  # [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
26
 
8
27
  **Note:** Version bump only for package @ui5/create-webcomponents-package
package/README.md CHANGED
@@ -6,17 +6,37 @@
6
6
 
7
7
  Provides an `npm init` script for creating new "UI5 Web Components" packages.
8
8
 
9
- ## Usage
9
+ ## Usage with npm
10
10
 
11
- with `npm`
11
+ ```
12
+ Usage:
12
13
 
13
- - `npm init @ui5/webcomponents-package` (the user will be asked for **name**, **port**, **tag**);
14
- - `npm init @ui5/webcomponents-package <NEW-PACKAGE-NAME>` (the user will be asked for **port** and **tag** only).
14
+ # npm 6.x
15
+ npm init @ui5/webcomponents-package [OPTIONS]
16
+ # npm 7+, an extra double-dash is needed:
17
+ npm init @ui5/webcomponents-package -- [OPTIONS]
15
18
 
16
- And with `yarn`
19
+ Options:
20
+ --name <string> - defines the package name
21
+ --tag <string> - defines the tag name of the sample web component that will be created in your new package
22
+ --enable-typescript - enables TypeScript support for the package
23
+ --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
24
+ ```
17
25
 
18
- - `yarn create @ui5/webcomponents-package`
19
- - `yarn create @ui5/webcomponents-package <NEW-PACKAGE-NAME>`.
26
+ The script creates a new directory, and fills it with a `package.json` file and all necessary source files, and resources for a new
27
+ components package.
28
+
29
+ ## Usage with yarn
30
+
31
+ ```
32
+ Usage:
33
+ yarn create @ui5/webcomponents-package [OPTIONS]
34
+ Options:
35
+ --name <string> - defines the package name
36
+ --tag <string> - defines the tag name of the sample web component that will be created in your new package
37
+ --enable-typescript - enables TypeScript support for the package
38
+ --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
39
+ ```
20
40
 
21
41
  The script creates a new directory, and fills it with a `package.json` file and all necessary source files, and resources for a new
22
42
  components package.
@@ -5,6 +5,10 @@ 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");
10
+
11
+ const argv = yargs(hideBin(process.argv)).argv;
8
12
 
9
13
  const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"))).version;
10
14
 
@@ -20,12 +24,11 @@ const toCamelCase = parts => {
20
24
  }).join("");
21
25
  };
22
26
  const isTypescriptRelatedFile = sourcePath => {
23
- return ["Аssets.ts", "MyFirstComponent.ts", "tsconfig.json", "global.d.ts"].some(fileName => sourcePath.includes(fileName));
24
- }
27
+ return ["Assets.ts", "MyFirstComponent.ts", "tsconfig.json", "global.d.ts"].some(fileName => sourcePath.includes(fileName));
28
+ };
25
29
 
26
30
  // Validation of user input
27
31
  const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z0-9\-_]+$/);
28
- const isPortValid = port => typeof port === "string" && port.match(/^[0-9]+$/);
29
32
  const isTagValid = tag => typeof tag === "string" && tag.match(/^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/);
30
33
 
31
34
  // Utils for building the file structure
@@ -42,14 +45,14 @@ const replaceVarsInFileName = (vars, fileName) => {
42
45
  };
43
46
 
44
47
  const copyFile = (vars, sourcePath, destPath) => {
45
- const ignoreJsRelated = vars.INIT_PACKAGE_VAR_TYPESCRIPT && sourcePath.includes("MyFirstComponent.js")
46
- const ignoreTsRelated = !vars.INIT_PACKAGE_VAR_TYPESCRIPT && isTypescriptRelatedFile(sourcePath)
48
+ const ignoreJsRelated = vars.INIT_PACKAGE_VAR_TYPESCRIPT && sourcePath.includes("MyFirstComponent.js");
49
+ const ignoreTsRelated = !vars.INIT_PACKAGE_VAR_TYPESCRIPT && isTypescriptRelatedFile(sourcePath);
47
50
 
48
51
  if (ignoreJsRelated || ignoreTsRelated) {
49
52
  return;
50
53
  }
51
54
 
52
- let content = fs.readFileSync(sourcePath, {encoding: "UTF-8"});
55
+ let content = fs.readFileSync(sourcePath, { encoding: "UTF-8" });
53
56
  content = replaceVarsInFileContent(vars, content);
54
57
  destPath = replaceVarsInFileName(vars, destPath);
55
58
  fs.writeFileSync(destPath, content);
@@ -69,70 +72,15 @@ const copyFiles = (vars, sourcePath, destPath) => {
69
72
  }
70
73
  };
71
74
 
72
- // Main function
73
- const createWebcomponentsPackage = async () => {
74
- let response;
75
-
76
- // Get the name
77
- let name = process.argv[2];
78
-
79
- if (!isNameValid(name)) {
80
- response = await prompts({
81
- type: "text",
82
- name: "name",
83
- message: "Package name:",
84
- validate: isNameValid,
85
- });
86
- name = response.name;
87
- }
88
-
89
- // Add TypeScript support
90
- response = await prompts({
91
- type: "select",
92
- name: "language",
93
- message: "Support TypeScript:",
94
- choices: [
95
- {
96
- title: "JavaScript",
97
- value: "js",
98
- },
99
- {
100
- title: "TypeScript",
101
- value: "ts",
102
- },
103
- ]
104
- });
105
- const typescript = response.language === "ts";
106
-
107
- // Get the port
108
- response = await prompts({
109
- type: "text",
110
- name: "port",
111
- message: "Dev server port:",
112
- validate: isPortValid,
113
- initial: "8080",
114
- });
115
- const port = response.port;
116
-
117
- // Get the tag
118
- response = await prompts({
119
- type: "text",
120
- name: "tag",
121
- message: "Demo component name:",
122
- initial: "my-first-component",
123
- validate: isTagValid,
124
- });
125
- const tag = response.tag;
126
-
75
+ const generateFilesContent = (name, tag, typescript) => {
127
76
  const className = capitalizeFirst(kebabToCamelCase(tag));
128
77
 
129
78
  // All variables that will be replaced in the content of the resources/
130
79
  const vars = {
131
80
  INIT_PACKAGE_VAR_NAME: name,
132
- INIT_PACKAGE_VAR_PORT: port,
133
81
  INIT_PACKAGE_VAR_TAG: tag,
134
82
  INIT_PACKAGE_VAR_CLASS_NAME: className,
135
- INIT_PACKAGE_VAR_TYPESCRIPT: typescript
83
+ INIT_PACKAGE_VAR_TYPESCRIPT: typescript,
136
84
  };
137
85
 
138
86
  const packageContent = {
@@ -152,7 +100,6 @@ const createWebcomponentsPackage = async () => {
152
100
  "prepublishOnly": "npm run build",
153
101
  },
154
102
  exports: {
155
- "./.port": "./.port",
156
103
  "./src/*": "./src/*",
157
104
  "./dist/*": "./dist/*",
158
105
  "./package.json": "./package.json",
@@ -195,4 +142,66 @@ const createWebcomponentsPackage = async () => {
195
142
  console.log("\n");
196
143
  };
197
144
 
145
+ // Main function
146
+ const createWebcomponentsPackage = async () => {
147
+ let response;
148
+ if (argv.name && !isNameValid(argv.name)) {
149
+ throw new Error("The package name should be a string (a-z, A-Z, 0-9).");
150
+ }
151
+
152
+ if (argv.tag && !isTagValid(argv.tag) ) {
153
+ throw new Error("The tag should be in kebab-case (my-first-component f.e) and it can't be a single word.");
154
+ }
155
+
156
+ let name = argv.name || "my-package";
157
+ let tag = argv.tag || "my-first-component";
158
+ let typescriptSupport = !!argv.enableTypescript;
159
+
160
+ if (argv.skip) {
161
+ return generateFilesContent(name, tag, typescriptSupport);
162
+ }
163
+
164
+ if (!argv.name) {
165
+ response = await prompts({
166
+ type: "text",
167
+ name: "name",
168
+ message: "Package name:",
169
+ validate: isNameValid,
170
+ });
171
+ name = response.name;
172
+ }
173
+
174
+ if (!typescriptSupport) {
175
+ response = await prompts({
176
+ type: "select",
177
+ name: "language",
178
+ message: "Project type:",
179
+ choices: [
180
+ {
181
+ title: "JavaScript",
182
+ value: false,
183
+ },
184
+ {
185
+ title: "TypeScript",
186
+ value: true,
187
+ },
188
+ ],
189
+ });
190
+ typescriptSupport = response.language;
191
+ }
192
+
193
+ if (!argv.tag) {
194
+ response = await prompts({
195
+ type: "text",
196
+ name: "tag",
197
+ message: "Component name:",
198
+ initial: "my-first-component",
199
+ validate: isTagValid,
200
+ });
201
+ tag = response.tag;
202
+ }
203
+
204
+ return generateFilesContent(name, tag, typescriptSupport);
205
+ };
206
+
198
207
  createWebcomponentsPackage();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/create-webcomponents-package",
3
- "version": "1.11.0-rc.0",
3
+ "version": "1.11.0-rc.2",
4
4
  "description": "UI5 Web Components: create package",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -11,7 +11,7 @@
11
11
  "ui5"
12
12
  ],
13
13
  "bin": {
14
- "create-webcomponents-package": "index.js"
14
+ "create-webcomponents-package": "create-package.js"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -21,7 +21,8 @@
21
21
  "dependencies": {
22
22
  "mkdirp": "^1.0.4",
23
23
  "npm-config-user-agent-parser": "^1.0.0",
24
- "prompts": "^2.4.1"
24
+ "prompts": "^2.4.1",
25
+ "yargs": "^17.5.1"
25
26
  },
26
- "gitHead": "6464abd79265425ce65232ebeee53cf6585e6ec6"
27
+ "gitHead": "a6334749f4f61a49b1ef754b75fe319991c54c17"
27
28
  }
@@ -1,7 +1,7 @@
1
1
  const getScripts = require("@ui5/webcomponents-tools/components-package/nps.js"); //eslint-disable-line
2
2
 
3
3
  const options = {
4
- port: INIT_PACKAGE_VAR_PORT,
4
+ port: 8080,
5
5
  typescript: INIT_PACKAGE_VAR_TYPESCRIPT,
6
6
  };
7
7