@ui5/create-webcomponents-package 0.0.0-7e7d9ea6f → 0.0.0-81513ce21

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,245 @@
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.5](https://github.com/SAP/ui5-webcomponents/compare/v1.13.0-rc.4...v1.13.0-rc.5) (2023-05-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **create-webcomponents-package:** fix package creation issues with test and lint ([#6976](https://github.com/SAP/ui5-webcomponents/issues/6976)) ([dd70f3a](https://github.com/SAP/ui5-webcomponents/commit/dd70f3aa8ef70b592f1d4e0f3f9894c6280fb1bf))
12
+
13
+
14
+
15
+
16
+
17
+ # [1.13.0-rc.4](https://github.com/SAP/ui5-webcomponents/compare/v1.13.0-rc.3...v1.13.0-rc.4) (2023-05-04)
18
+
19
+
20
+ ### Features
21
+
22
+ * generate TS from HBS templates ([#6558](https://github.com/SAP/ui5-webcomponents/issues/6558)) ([02611b2](https://github.com/SAP/ui5-webcomponents/commit/02611b2e24b2c2a06129b8e60a8bc680d9501e39))
23
+
24
+
25
+
26
+
27
+
28
+ # [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)
29
+
30
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
31
+
32
+
33
+
34
+
35
+
36
+ # [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)
37
+
38
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
39
+
40
+
41
+
42
+
43
+
44
+ # [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)
45
+
46
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
47
+
48
+
49
+
50
+
51
+
52
+ # [1.13.0-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.12.0...v1.13.0-rc.0) (2023-04-06)
53
+
54
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
55
+
56
+
57
+
58
+
59
+
60
+ # [1.12.0](https://github.com/SAP/ui5-webcomponents/compare/v1.12.0-rc.3...v1.12.0) (2023-04-04)
61
+
62
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
63
+
64
+
65
+
66
+
67
+
68
+ # [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)
69
+
70
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
71
+
72
+
73
+
74
+
75
+
76
+ # [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)
77
+
78
+
79
+ ### Bug Fixes
80
+
81
+ * 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))
82
+
83
+
84
+
85
+
86
+
87
+ # [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)
88
+
89
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
90
+
91
+
92
+
93
+
94
+
95
+ # [1.12.0-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0...v1.12.0-rc.0) (2023-03-09)
96
+
97
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
98
+
99
+
100
+
101
+
102
+
103
+ # [1.11.0](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.4...v1.11.0) (2023-03-06)
104
+
105
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
106
+
107
+
108
+
109
+
110
+
111
+ # [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)
112
+
113
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
114
+
115
+
116
+
117
+
118
+
119
+ # [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)
120
+
121
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
122
+
123
+
124
+
125
+
126
+
127
+ # [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)
128
+
129
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
130
+
131
+
132
+
133
+
134
+
135
+ # [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)
136
+
137
+
138
+ ### Features
139
+
140
+ * **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)
141
+
142
+
143
+
144
+
145
+
146
+ # [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)
147
+
148
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
149
+
150
+
151
+
152
+
153
+
154
+ ## [1.10.4-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.10.3...v1.10.4-rc.0) (2023-01-26)
155
+
156
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
157
+
158
+
159
+
160
+
161
+
162
+ ## [1.10.3](https://github.com/SAP/ui5-webcomponents/compare/v1.10.2...v1.10.3) (2023-01-25)
163
+
164
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
165
+
166
+
167
+
168
+
169
+
170
+ ## [1.10.1](https://github.com/SAP/ui5-webcomponents/compare/v0.0.0-7b49a7ff1...v1.10.1) (2023-01-24)
171
+
172
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
173
+
174
+
175
+
176
+
177
+
178
+ # [1.10.0](https://github.com/SAP/ui5-webcomponents/compare/v1.9.3...v1.10.0) (2023-01-20)
179
+
180
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
181
+
182
+
183
+
184
+
185
+
186
+ ## [1.9.3](https://github.com/SAP/ui5-webcomponents/compare/v1.9.2...v1.9.3) (2022-12-16)
187
+
188
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
189
+
190
+
191
+
192
+
193
+
194
+ ## [1.9.1](https://github.com/SAP/ui5-webcomponents/compare/v1.9.0...v1.9.1) (2022-11-10)
195
+
196
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
197
+
198
+
199
+
200
+
201
+
202
+ # [1.9.0](https://github.com/SAP/ui5-webcomponents/compare/v1.8.0...v1.9.0) (2022-10-31)
203
+
204
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
205
+
206
+
207
+
208
+
209
+
210
+ # [1.8.0](https://github.com/SAP/ui5-webcomponents/compare/v1.7.1...v1.8.0) (2022-10-03)
211
+
212
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
213
+
214
+
215
+
216
+
217
+
218
+ ## [1.7.1](https://github.com/SAP/ui5-webcomponents/compare/v1.7.0...v1.7.1) (2022-09-08)
219
+
220
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
221
+
222
+
223
+
224
+
225
+
226
+ # [1.7.0](https://github.com/SAP/ui5-webcomponents/compare/v1.6.0...v1.7.0) (2022-09-02)
227
+
228
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
229
+
230
+
231
+
232
+
233
+
234
+ # [1.6.0](https://github.com/SAP/ui5-webcomponents/compare/v1.5.0...v1.6.0) (2022-07-25)
235
+
236
+
237
+ ### Bug Fixes
238
+
239
+ * create package bugs ([#5517](https://github.com/SAP/ui5-webcomponents/issues/5517)) ([f528f5c](https://github.com/SAP/ui5-webcomponents/commit/f528f5c))
240
+
241
+
242
+
243
+
244
+
6
245
  # [1.5.0](https://github.com/SAP/ui5-webcomponents/compare/v1.4.0...v1.5.0) (2022-07-03)
7
246
 
8
247
  **Note:** Version bump only for package @ui5/create-webcomponents-package
package/README.md CHANGED
@@ -6,17 +6,38 @@
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
+ --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
24
+ --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
25
+ ```
17
26
 
18
- - `yarn create @ui5/webcomponents-package`
19
- - `yarn create @ui5/webcomponents-package <NEW-PACKAGE-NAME>`.
27
+ The script creates a new directory, and fills it with a `package.json` file and all necessary source files, and resources for a new
28
+ components package.
29
+
30
+ ## Usage with yarn
31
+
32
+ ```
33
+ Usage:
34
+ yarn create @ui5/webcomponents-package [OPTIONS]
35
+ Options:
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
40
+ ```
20
41
 
21
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
22
43
  components package.
@@ -0,0 +1,249 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const mkdirp = require("mkdirp");
6
+ const prompts = require("prompts");
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;
12
+
13
+ const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"))).version;
14
+
15
+ // from where all the files will be copied
16
+ const TEMPLATE_DIR = path.join(`${__dirname}`, `template/`);
17
+
18
+ // String utils
19
+ const capitalizeFirst = str => str.substr(0,1).toUpperCase() + str.substr(1);
20
+ const kebabToCamelCase = string => toCamelCase(string.split("-"));
21
+ const toCamelCase = parts => {
22
+ return parts.map((string, index) => {
23
+ return index === 0 ? string.toLowerCase() : string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
24
+ }).join("");
25
+ };
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
+ };
38
+
39
+ // Validation of user input
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);
43
+ const isTagValid = tag => typeof tag === "string" && tag.match(/^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/);
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
+
56
+ // Utils for building the file structure
57
+ const replaceVarsInFileContent = (vars, content) => {
58
+ for (let key in vars) {
59
+ const re = new RegExp(key, "g");
60
+ content = content.replace(re, vars[key]);
61
+ }
62
+ return content;
63
+ };
64
+
65
+ const replaceVarsInFileName = (vars, fileName) => {
66
+ return fileName.replace(/MyFirstComponent/, vars.INIT_PACKAGE_VAR_CLASS_NAME);
67
+ };
68
+
69
+ const copyFile = (vars, sourcePath, destPath) => {
70
+ const ignoreJsRelated = vars.INIT_PACKAGE_VAR_TYPESCRIPT && isJSRelatedFile(sourcePath);
71
+ const ignoreTsRelated = !vars.INIT_PACKAGE_VAR_TYPESCRIPT && isTSRelatedFile(sourcePath);
72
+
73
+ if (ignoreJsRelated || ignoreTsRelated) {
74
+ return;
75
+ }
76
+
77
+ let content = fs.readFileSync(sourcePath, { encoding: "UTF-8" });
78
+ content = replaceVarsInFileContent(vars, content);
79
+ destPath = replaceVarsInFileName(vars, destPath);
80
+
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
+ }
92
+ };
93
+
94
+ const copyFiles = (vars, sourcePath, destPath) => {
95
+ const isDir = fs.lstatSync(sourcePath).isDirectory();
96
+ if (isDir) {
97
+ if (destPath) {
98
+ mkdirp.sync(destPath);
99
+ }
100
+ fs.readdirSync(sourcePath).forEach(file => {
101
+ copyFiles(vars, path.join(sourcePath, file), path.join(destPath, file));
102
+ });
103
+ } else {
104
+ copyFile(vars, sourcePath, destPath);
105
+ }
106
+ };
107
+
108
+ const generateFilesContent = (name, componentName, typescript, skipSubfolder) => {
109
+ const tagName = argv.tag || hyphaneteComponentName(componentName);
110
+
111
+ // All variables that will be replaced in the content of the resources/
112
+ const vars = {
113
+ INIT_PACKAGE_VAR_NAME: name,
114
+ INIT_PACKAGE_VAR_TAG: tagName,
115
+ INIT_PACKAGE_VAR_CLASS_NAME: componentName,
116
+ INIT_PACKAGE_VAR_TYPESCRIPT: typescript,
117
+ };
118
+
119
+ const packageContent = {
120
+ name,
121
+ version: "0.0.1",
122
+ ui5: {
123
+ webComponentsPackage: true,
124
+ },
125
+ scripts: {
126
+ "clean": "wc-dev clean",
127
+ "lint": "wc-dev lint",
128
+ "start": "wc-dev start",
129
+ "watch": "wc-dev watch",
130
+ "build": "wc-dev build",
131
+ "test": "wc-dev test",
132
+ "create-ui5-element": "wc-create-ui5-element",
133
+ "prepublishOnly": "npm run build",
134
+ },
135
+ exports: {
136
+ "./src/*": "./src/*",
137
+ "./dist/*": "./dist/*",
138
+ "./package.json": "./package.json",
139
+ "./bundle.js": "./bundle.js",
140
+ "./*": "./dist/*",
141
+ },
142
+ "dependencies": {
143
+ "@ui5/webcomponents-base": version,
144
+ "@ui5/webcomponents-theming": version,
145
+ },
146
+ "devDependencies": {
147
+ "@ui5/webcomponents-tools": version,
148
+ "chromedriver": "*",
149
+ },
150
+ };
151
+
152
+ if (typescript) {
153
+ packageContent.devDependencies.typescript = "^4.9.4";
154
+ }
155
+
156
+ // Update package.json
157
+ const destDir = skipSubfolder ? path.join("./") : path.join("./", name);
158
+ mkdirp.sync(destDir);
159
+ fs.writeFileSync(path.join(destDir, "package.json"), JSON.stringify(packageContent, null, 2));
160
+ // Copy files
161
+ copyFiles(vars, TEMPLATE_DIR, destDir);
162
+
163
+ console.log("\nPackage successfully created!\nNext steps:\n");
164
+ console.log(`$ cd ${name}`);
165
+
166
+ let userAgentInfo;
167
+ try {
168
+ userAgentInfo = parser(process.env.npm_config_user_agent);
169
+ } catch (e) {}
170
+
171
+ if (userAgentInfo && userAgentInfo.yarn) {
172
+ console.log(`$ yarn`);
173
+ console.log(`$ yarn start`);
174
+ } else {
175
+ console.log(`$ npm i`);
176
+ console.log(`$ npm start`);
177
+ }
178
+
179
+ console.log("\n");
180
+ };
181
+
182
+ // Main function
183
+ const createWebcomponentsPackage = async () => {
184
+ let response;
185
+ if (argv.name && !isNameValid(argv.name)) {
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.");
191
+ }
192
+
193
+ if (argv.tag && !isTagValid(argv.tag) ) {
194
+ throw new Error("The tag should be in kebab-case (f.e my-component) and it can't be a single word.");
195
+ }
196
+
197
+ let name = argv.name || "my-package";
198
+ let componentName = argv.componentName || "MyComponent";
199
+ let typescriptSupport = !!argv.enableTypescript;
200
+ const skipSubfolder = !!argv.skipSubfolder;
201
+
202
+ if (argv.skip) {
203
+ return generateFilesContent(name, componentName, typescriptSupport, skipSubfolder);
204
+ }
205
+
206
+ if (!argv.name) {
207
+ response = await prompts({
208
+ type: "text",
209
+ name: "name",
210
+ message: "Package name:",
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, _, -].",
212
+ });
213
+ name = response.name;
214
+ }
215
+
216
+ if (!typescriptSupport) {
217
+ response = await prompts({
218
+ type: "select",
219
+ name: "language",
220
+ message: "Project type:",
221
+ choices: [
222
+ {
223
+ title: "JavaScript",
224
+ value: false,
225
+ },
226
+ {
227
+ title: "TypeScript",
228
+ value: true,
229
+ },
230
+ ],
231
+ });
232
+ typescriptSupport = response.language;
233
+ }
234
+
235
+ if (!argv.componentName) {
236
+ response = await prompts({
237
+ type: "text",
238
+ name: "componentName",
239
+ message: "Component name:",
240
+ initial: "MyComponent",
241
+ validate: (value) => isComponentNameValid(value) ? true : "Component name should follow PascalCase naming convention (f.e. Button, MyButton, etc.).",
242
+ });
243
+ componentName = response.componentName;
244
+ }
245
+
246
+ return generateFilesContent(name, componentName, typescriptSupport, skipSubfolder);
247
+ };
248
+
249
+ createWebcomponentsPackage();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/create-webcomponents-package",
3
- "version": "0.0.0-7e7d9ea6f",
3
+ "version": "0.0.0-81513ce21",
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,6 +21,7 @@
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
27
  }
@@ -1,3 +1,6 @@
1
1
  # Note: Changes to this file also must be applied to the top level .eslintignore file.
2
2
  dist
3
3
  test
4
+ src/generated
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
@@ -1,7 +1,8 @@
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
+ typescript: INIT_PACKAGE_VAR_TYPESCRIPT,
5
6
  };
6
7
 
7
8
  const scripts = getScripts(options);
@@ -0,0 +1,5 @@
1
+ import "@ui5/webcomponents-theming/dist/Assets.js"; // Theming
2
+
3
+ // own INIT_PACKAGE_VAR_NAME package assets
4
+ import "./generated/json-imports/Themes.js";
5
+ import "./generated/json-imports/i18n.js";
@@ -32,7 +32,7 @@ const metadata = {
32
32
  *
33
33
  * @constructor
34
34
  * @alias demo.components.INIT_PACKAGE_VAR_CLASS_NAME
35
- * @extends UI5Element
35
+ * @extends sap.ui.webc.base.UI5Element
36
36
  * @tagname INIT_PACKAGE_VAR_TAG
37
37
  * @public
38
38
  */
@@ -0,0 +1,48 @@
1
+ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
2
+ import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
3
+ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
4
+ import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
5
+ import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
6
+
7
+ // Template
8
+ import INIT_PACKAGE_VAR_CLASS_NAMETemplate from "./generated/templates/INIT_PACKAGE_VAR_CLASS_NAMETemplate.lit.js";
9
+
10
+ // Styles
11
+ import INIT_PACKAGE_VAR_CLASS_NAMECss from "./generated/themes/INIT_PACKAGE_VAR_CLASS_NAME.css.js";
12
+
13
+ import { PLEASE_WAIT } from "./generated/i18n/i18n-defaults.js";
14
+
15
+ /**
16
+ * @class
17
+ *
18
+ * <h3 class="comment-api-title">Overview</h3>
19
+ *
20
+ * The <code>INIT_PACKAGE_VAR_TAG</code> component is a demo component that displays some text.
21
+ *
22
+ * @constructor
23
+ * @alias demo.components.INIT_PACKAGE_VAR_CLASS_NAME
24
+ * @extends sap.ui.webc.base.UI5Element
25
+ * @tagname INIT_PACKAGE_VAR_TAG
26
+ * @public
27
+ */
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
+ })
34
+ class INIT_PACKAGE_VAR_CLASS_NAME extends UI5Element {
35
+ static i18nBundle: I18nBundle;
36
+
37
+ static async onDefine() {
38
+ INIT_PACKAGE_VAR_CLASS_NAME.i18nBundle = await getI18nBundle("INIT_PACKAGE_VAR_NAME");
39
+ }
40
+
41
+ get pleaseWaitText() {
42
+ return INIT_PACKAGE_VAR_CLASS_NAME.i18nBundle.getText(PLEASE_WAIT);
43
+ }
44
+ }
45
+
46
+ INIT_PACKAGE_VAR_CLASS_NAME.define();
47
+
48
+ export default INIT_PACKAGE_VAR_CLASS_NAME;
@@ -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
+ }
@@ -2,12 +2,10 @@
2
2
  <html>
3
3
 
4
4
  <head>
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
5
  <meta charset="utf-8">
7
6
 
8
7
  <title>INIT_PACKAGE_VAR_TAG</title>
9
8
  <meta name="viewport" content="width=device-width, initial-scale=1">
10
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
11
9
  <meta charset="utf-8">
12
10
 
13
11
  <script data-ui5-config type="application/json">
@@ -30,13 +28,14 @@
30
28
  <li><a href="?sap-ui-theme=sap_fiori_3_dark">Fiori 3 Dark</a></li>
31
29
  <li><a href="?sap-ui-theme=sap_fiori_3_hcb">Fiori 3 High Contrast Black</a></li>
32
30
  <li><a href="?sap-ui-theme=sap_fiori_3_hcw">Fiori 3 High Contrast White</a></li>
33
- <li><a href="?sap-ui-theme=sap_belize">Belize</a></li>
34
- <li><a href="?sap-ui-theme=sap_belize_hcb">Belize High Contrast Black</a></li>
35
- <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>
36
35
  </ul>
37
36
  <br>
38
37
  <span>or in the browser console, for example:</span>
39
- <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>
40
39
 
41
40
  <br><br>
42
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
 
@@ -0,0 +1,15 @@
1
+ {
2
+ "include": ["src/**/*", "global.d.ts"],
3
+ "compilerOptions": {
4
+ "target": "ES2021",
5
+ // Generate d.ts files
6
+ "declaration": true,
7
+ "outDir": "dist",
8
+ "skipLibCheck": true,
9
+ "sourceMap": true,
10
+ "inlineSources": true,
11
+ "strict": true,
12
+ "moduleResolution": "node",
13
+ "experimentalDecorators": true,
14
+ },
15
+ }
package/index.js DELETED
@@ -1,169 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const mkdirp = require("mkdirp");
6
- const prompts = require("prompts");
7
- const parser = require("npm-config-user-agent-parser");
8
-
9
- const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"))).version;
10
-
11
- // from where all the files will be copied
12
- const TEMPLATE_DIR = path.join(`${__dirname}`, `template/`);
13
-
14
- // String utils
15
- const capitalizeFirst = str => str.substr(0,1).toUpperCase() + str.substr(1);
16
- const kebabToCamelCase = string => toCamelCase(string.split("-"));
17
- const toCamelCase = parts => {
18
- return parts.map((string, index) => {
19
- return index === 0 ? string.toLowerCase() : string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
20
- }).join("");
21
- };
22
-
23
- // Validation of user input
24
- const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z0-9\-_]+$/);
25
- const isPortValid = port => typeof port === "string" && port.match(/^[0-9]+$/);
26
- const isTagValid = tag => typeof tag === "string" && tag.match(/^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/);
27
-
28
- // Utils for building the file structure
29
- const replaceVarsInFileContent = (vars, content) => {
30
- for (let key in vars) {
31
- const re = new RegExp(key, "g");
32
- content = content.replace(re, vars[key]);
33
- }
34
- return content;
35
- };
36
-
37
- const replaceVarsInFileName = (vars, fileName) => {
38
- return fileName.replace(/MyFirstComponent/, vars.INIT_PACKAGE_VAR_CLASS_NAME);
39
- };
40
-
41
- const copyFile = (vars, sourcePath, destPath) => {
42
- let content = fs.readFileSync(sourcePath, {encoding: "UTF-8"});
43
- content = replaceVarsInFileContent(vars, content);
44
- destPath = replaceVarsInFileName(vars, destPath);
45
- fs.writeFileSync(destPath, content);
46
- };
47
-
48
- const copyFiles = (vars, sourcePath, destPath) => {
49
- const isDir = fs.lstatSync(sourcePath).isDirectory();
50
- if (isDir) {
51
- if (destPath) {
52
- mkdirp.sync(destPath);
53
- }
54
- fs.readdirSync(sourcePath).forEach(file => {
55
- copyFiles(vars, path.join(sourcePath, file), path.join(destPath, file));
56
- });
57
- } else {
58
- copyFile(vars, sourcePath, destPath);
59
- }
60
- };
61
-
62
- // Main function
63
- const createWebcomponentsPackage = async () => {
64
- let response;
65
-
66
- // Get the name
67
- let name = process.argv[2];
68
-
69
- if (!isNameValid(name)) {
70
- response = await prompts({
71
- type: "text",
72
- name: "name",
73
- message: "Package name:",
74
- validate: isNameValid,
75
- });
76
- name = response.name;
77
- }
78
-
79
- // Get the port
80
- response = await prompts({
81
- type: "text",
82
- name: "port",
83
- message: "Dev server port:",
84
- validate: isPortValid,
85
- initial: "8080",
86
- });
87
- const port = response.port;
88
-
89
- // Get the tag
90
- response = await prompts({
91
- type: "text",
92
- name: "tag",
93
- message: "Demo component name:",
94
- initial: "my-first-component",
95
- validate: isTagValid,
96
- });
97
- const tag = response.tag;
98
-
99
- const className = capitalizeFirst(kebabToCamelCase(tag));
100
-
101
- // All variables that will be replaced in the content of the resources/
102
- const vars = {
103
- INIT_PACKAGE_VAR_NAME: name,
104
- INIT_PACKAGE_VAR_PORT: port,
105
- INIT_PACKAGE_VAR_TAG: tag,
106
- INIT_PACKAGE_VAR_CLASS_NAME: className,
107
- };
108
-
109
- const packageContent = {
110
- name,
111
- version: "0.0.1",
112
- ui5: {
113
- webComponentsPackage: true,
114
- },
115
- scripts: {
116
- "clean": "wc-dev clean",
117
- "lint": "wc-dev lint",
118
- "start": "wc-dev start",
119
- "watch": "wc-dev watch",
120
- "build": "wc-dev build",
121
- "test": "wc-dev test",
122
- "create-ui5-element": "wc-create-ui5-element",
123
- "prepublishOnly": "npm run build",
124
- },
125
- exports: {
126
- "./.port": "./.port",
127
- "./src/*": "./src/*",
128
- "./dist/*": "./dist/*",
129
- "./package.json": "./package.json",
130
- "./bundle.js": "./bundle.js",
131
- "./*": "./dist/*",
132
- },
133
- "dependencies": {
134
- "@ui5/webcomponents-base": version,
135
- "@ui5/webcomponents-theming": version,
136
- },
137
- "devDependencies": {
138
- "@ui5/webcomponents-tools": version,
139
- "chromedriver": "*",
140
- },
141
- };
142
-
143
- // Update package.json
144
- const destDir = path.join(`./`, name);
145
- mkdirp.sync(destDir);
146
- fs.writeFileSync(path.join(destDir, "package.json"), JSON.stringify(packageContent, null, 2));
147
- // Copy files
148
- copyFiles(vars, TEMPLATE_DIR, destDir);
149
-
150
- console.log("\nPackage successfully created!\nNext steps:\n");
151
- console.log(`$ cd ${name}`);
152
-
153
- let userAgentInfo;
154
- try {
155
- userAgentInfo = parser(process.env.npm_config_user_agent);
156
- } catch (e) {}
157
-
158
- if (userAgentInfo && userAgentInfo.yarn) {
159
- console.log(`$ yarn`);
160
- console.log(`$ yarn start`);
161
- } else {
162
- console.log(`$ npm i`);
163
- console.log(`$ npm start`);
164
- }
165
-
166
- console.log("\n");
167
- };
168
-
169
- createWebcomponentsPackage();
@@ -1,3 +0,0 @@
1
- :root {
2
- --my-component-border-color: black;
3
- }