@ui5/create-webcomponents-package 0.0.0-51202adee → 0.0.0-7d5f73b20
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 +32 -0
- package/README.md +27 -7
- package/{index.js → create-package.js} +78 -39
- package/package.json +5 -2
- package/template/.eslintignore +2 -0
- package/template/global.d.ts +12 -0
- package/template/package-scripts.js +2 -1
- package/template/src/Assets.ts +5 -0
- package/template/src/MyFirstComponent.ts +55 -0
- package/template/tsconfig.json +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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.0](https://github.com/SAP/ui5-webcomponents/compare/v1.10.4-rc.0...v1.11.0-rc.0) (2023-02-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @ui5/create-webcomponents-package
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.10.4-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.10.3...v1.10.4-rc.0) (2023-01-26)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @ui5/create-webcomponents-package
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [1.10.3](https://github.com/SAP/ui5-webcomponents/compare/v1.10.2...v1.10.3) (2023-01-25)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @ui5/create-webcomponents-package
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [1.10.1](https://github.com/SAP/ui5-webcomponents/compare/v0.0.0-7b49a7ff1...v1.10.1) (2023-01-24)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @ui5/create-webcomponents-package
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
# [1.10.0](https://github.com/SAP/ui5-webcomponents/compare/v1.9.3...v1.10.0) (2023-01-20)
|
|
7
39
|
|
|
8
40
|
**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
|
-
|
|
11
|
+
```
|
|
12
|
+
Usage:
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
# npm 6.x
|
|
15
|
+
npm init @ui5/webcomponents-package [OPTIONS]
|
|
16
|
+
# npm 7+, extra double-dash is needed:
|
|
17
|
+
npm init @ui5/webcomponents-package -- [OPTIONS]
|
|
15
18
|
|
|
16
|
-
|
|
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
|
|
23
|
+
--skip - skips configuration and generates package with a default value for each parameter that wasn't passed
|
|
24
|
+
```
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
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 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
|
|
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
|
|
|
@@ -19,10 +23,12 @@ const toCamelCase = parts => {
|
|
|
19
23
|
return index === 0 ? string.toLowerCase() : string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
|
|
20
24
|
}).join("");
|
|
21
25
|
};
|
|
26
|
+
const isTypescriptRelatedFile = sourcePath => {
|
|
27
|
+
return ["Аssets.ts", "MyFirstComponent.ts", "tsconfig.json", "global.d.ts"].some(fileName => sourcePath.includes(fileName));
|
|
28
|
+
}
|
|
22
29
|
|
|
23
30
|
// Validation of user input
|
|
24
31
|
const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z0-9\-_]+$/);
|
|
25
|
-
const isPortValid = port => typeof port === "string" && port.match(/^[0-9]+$/);
|
|
26
32
|
const isTagValid = tag => typeof tag === "string" && tag.match(/^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/);
|
|
27
33
|
|
|
28
34
|
// Utils for building the file structure
|
|
@@ -39,6 +45,13 @@ const replaceVarsInFileName = (vars, fileName) => {
|
|
|
39
45
|
};
|
|
40
46
|
|
|
41
47
|
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)
|
|
50
|
+
|
|
51
|
+
if (ignoreJsRelated || ignoreTsRelated) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
let content = fs.readFileSync(sourcePath, {encoding: "UTF-8"});
|
|
43
56
|
content = replaceVarsInFileContent(vars, content);
|
|
44
57
|
destPath = replaceVarsInFileName(vars, destPath);
|
|
@@ -59,51 +72,16 @@ const copyFiles = (vars, sourcePath, destPath) => {
|
|
|
59
72
|
}
|
|
60
73
|
};
|
|
61
74
|
|
|
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
75
|
|
|
76
|
+
const generateFilesContent = (name, tag, typescript) => {
|
|
99
77
|
const className = capitalizeFirst(kebabToCamelCase(tag));
|
|
100
78
|
|
|
101
79
|
// All variables that will be replaced in the content of the resources/
|
|
102
80
|
const vars = {
|
|
103
81
|
INIT_PACKAGE_VAR_NAME: name,
|
|
104
|
-
INIT_PACKAGE_VAR_PORT: port,
|
|
105
82
|
INIT_PACKAGE_VAR_TAG: tag,
|
|
106
83
|
INIT_PACKAGE_VAR_CLASS_NAME: className,
|
|
84
|
+
INIT_PACKAGE_VAR_TYPESCRIPT: typescript
|
|
107
85
|
};
|
|
108
86
|
|
|
109
87
|
const packageContent = {
|
|
@@ -123,7 +101,6 @@ const createWebcomponentsPackage = async () => {
|
|
|
123
101
|
"prepublishOnly": "npm run build",
|
|
124
102
|
},
|
|
125
103
|
exports: {
|
|
126
|
-
"./.port": "./.port",
|
|
127
104
|
"./src/*": "./src/*",
|
|
128
105
|
"./dist/*": "./dist/*",
|
|
129
106
|
"./package.json": "./package.json",
|
|
@@ -164,6 +141,68 @@ const createWebcomponentsPackage = async () => {
|
|
|
164
141
|
}
|
|
165
142
|
|
|
166
143
|
console.log("\n");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Main function
|
|
147
|
+
const createWebcomponentsPackage = async () => {
|
|
148
|
+
let response;
|
|
149
|
+
if (argv.name && !isNameValid(argv.name)) {
|
|
150
|
+
throw new Error("The package name should be a string (a-z, A-Z, 0-9).");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
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.");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let name = argv.name || "my-package";
|
|
158
|
+
let tag = argv.tag || "my-first-component";
|
|
159
|
+
let typescriptSupport = !!argv.enableTypescript;
|
|
160
|
+
|
|
161
|
+
if (!!argv.skip) {
|
|
162
|
+
return generateFilesContent(name, tag, typescriptSupport);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (!argv.name) {
|
|
166
|
+
response = await prompts({
|
|
167
|
+
type: "text",
|
|
168
|
+
name: "name",
|
|
169
|
+
message: "Package name:",
|
|
170
|
+
validate: isNameValid,
|
|
171
|
+
});
|
|
172
|
+
name = response.name;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!typescriptSupport) {
|
|
176
|
+
response = await prompts({
|
|
177
|
+
type: "select",
|
|
178
|
+
name: "language",
|
|
179
|
+
message: "Project type:",
|
|
180
|
+
choices: [
|
|
181
|
+
{
|
|
182
|
+
title: "JavaScript",
|
|
183
|
+
value: false,
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
title: "TypeScript",
|
|
187
|
+
value: true,
|
|
188
|
+
},
|
|
189
|
+
]
|
|
190
|
+
});
|
|
191
|
+
typescript = response.language;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!argv.tag) {
|
|
195
|
+
response = await prompts({
|
|
196
|
+
type: "text",
|
|
197
|
+
name: "tag",
|
|
198
|
+
message: "Component name:",
|
|
199
|
+
initial: "my-first-component",
|
|
200
|
+
validate: isTagValid,
|
|
201
|
+
});
|
|
202
|
+
tag = response.tag;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return generateFilesContent(name, tag, typescript);
|
|
167
206
|
};
|
|
168
207
|
|
|
169
208
|
createWebcomponentsPackage();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui5/create-webcomponents-package",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-7d5f73b20",
|
|
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": "
|
|
14
|
+
"create-webcomponents-package": "create-package.js"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -22,5 +22,8 @@
|
|
|
22
22
|
"mkdirp": "^1.0.4",
|
|
23
23
|
"npm-config-user-agent-parser": "^1.0.0",
|
|
24
24
|
"prompts": "^2.4.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"yargs": "^17.5.1"
|
|
25
28
|
}
|
|
26
29
|
}
|
package/template/.eslintignore
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// eslint-disable-next-line
|
|
2
|
+
import "@ui5/webcomponents-base/dist/global";
|
|
3
|
+
import { TemplateFunction } from "@ui5/webcomponents-base/dist/renderer/executeTemplate.js";
|
|
4
|
+
|
|
5
|
+
export {};
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
module "*.lit.js" {
|
|
9
|
+
const content: TemplateFunction;
|
|
10
|
+
export default content;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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("INIT_PACKAGE_VAR_TAG")
|
|
29
|
+
class INIT_PACKAGE_VAR_CLASS_NAME extends UI5Element {
|
|
30
|
+
static i18nBundle: I18nBundle;
|
|
31
|
+
|
|
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
|
+
static async onDefine() {
|
|
45
|
+
INIT_PACKAGE_VAR_CLASS_NAME.i18nBundle = await getI18nBundle("INIT_PACKAGE_VAR_NAME");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get pleaseWaitText() {
|
|
49
|
+
return INIT_PACKAGE_VAR_CLASS_NAME.i18nBundle.getText(PLEASE_WAIT);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
INIT_PACKAGE_VAR_CLASS_NAME.define();
|
|
54
|
+
|
|
55
|
+
export default INIT_PACKAGE_VAR_CLASS_NAME;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
"strict": true,
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"experimentalDecorators": true,
|
|
13
|
+
},
|
|
14
|
+
}
|