@ui5/webcomponents-tools 1.11.0 → 1.12.0-rc.0
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,17 @@
|
|
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.12.0-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0...v1.12.0-rc.0) (2023-03-09)
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* enhance create-ui5-element command to create component in TS ([#6609](https://github.com/SAP/ui5-webcomponents/issues/6609)) ([d870065](https://github.com/SAP/ui5-webcomponents/commit/d8700650a4e5991862e2076cc2c93482011c4c90))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
6
17
|
# [1.11.0](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.4...v1.11.0) (2023-03-06)
|
7
18
|
|
8
19
|
**Note:** Version bump only for package @ui5/webcomponents-tools
|
@@ -47,7 +47,7 @@ const getScripts = (options) => {
|
|
47
47
|
const scripts = {
|
48
48
|
clean: 'rimraf jsdoc-dist && rimraf src/generated && rimraf dist && rimraf .port && nps "scope.testPages.clean"',
|
49
49
|
lint: `eslint . ${eslintConfig}`,
|
50
|
-
lintfix: `eslint . ${eslintConfig}`,
|
50
|
+
lintfix: `eslint . ${eslintConfig} --fix`,
|
51
51
|
prepare: {
|
52
52
|
default: `${tsCrossEnv} nps clean prepare.all typescript generateAPI`,
|
53
53
|
all: 'concurrently "nps build.templates" "nps build.i18n" "nps prepare.styleRelated" "nps copy" "nps build.illustrations"',
|
@@ -1,80 +1,7 @@
|
|
1
1
|
const fs = require("fs");
|
2
|
-
|
3
|
-
const jsFileContentTemplate =
|
4
|
-
|
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";
|
10
|
-
|
11
|
-
/**
|
12
|
-
* @public
|
13
|
-
*/
|
14
|
-
const metadata = {
|
15
|
-
tag: "${tagName}",
|
16
|
-
properties: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
|
17
|
-
//
|
18
|
-
},
|
19
|
-
slots: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
|
20
|
-
//
|
21
|
-
},
|
22
|
-
events: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
|
23
|
-
//
|
24
|
-
},
|
25
|
-
};
|
26
|
-
|
27
|
-
/**
|
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.webc.${library}.${componentName}
|
43
|
-
* @extends sap.ui.webc.base.UI5Element
|
44
|
-
* @tagname ${tagName}
|
45
|
-
* @public
|
46
|
-
*/
|
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();
|
74
|
-
|
75
|
-
export default ${componentName};
|
76
|
-
`;
|
77
|
-
};
|
2
|
+
const prompts = require("prompts");
|
3
|
+
const jsFileContentTemplate = require("./jsFileContentTemplate.js");
|
4
|
+
const tsFileContentTemplate = require("./tsFileContentTemplate.js");
|
78
5
|
|
79
6
|
const getPackageName = () => {
|
80
7
|
if (!fs.existsSync("./package.json")) {
|
@@ -108,47 +35,117 @@ const getLibraryName = packageName => {
|
|
108
35
|
return packageName.substr("webcomponents-".length);
|
109
36
|
};
|
110
37
|
|
111
|
-
|
38
|
+
// String manipulation
|
39
|
+
const capitalizeFirstLetter = string => string.charAt(0).toUpperCase() + string.slice(1);
|
40
|
+
|
41
|
+
// Validation of user input
|
42
|
+
const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/);
|
43
|
+
const isTagNameValid = tagName => tagName.match(/^([a-z][a-z0-9]*-)([a-z0-9]+(-[a-z0-9]+)*)$/);
|
44
|
+
|
45
|
+
const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
|
46
|
+
componentName = capitalizeFirstLetter(componentName);
|
47
|
+
const filePaths = {
|
48
|
+
"main": isTypeScript
|
49
|
+
? `./src/${componentName}.ts`
|
50
|
+
: `./src/${componentName}.js`,
|
51
|
+
"css": `./src/themes/${componentName}.css`,
|
52
|
+
"template": `./src/${componentName}.hbs`,
|
53
|
+
};
|
112
54
|
|
113
|
-
const
|
114
|
-
|
55
|
+
const FileContentTemplate = isTypeScript
|
56
|
+
? tsFileContentTemplate(componentName, tagName, library, packageName)
|
57
|
+
: jsFileContentTemplate(componentName, tagName, library, packageName);
|
115
58
|
|
116
|
-
|
117
|
-
|
59
|
+
fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
|
60
|
+
fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
|
61
|
+
fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
|
118
62
|
|
119
|
-
|
120
|
-
console.
|
121
|
-
|
63
|
+
console.log(`Successfully generated ${filePaths.main}`);
|
64
|
+
console.log(`Successfully generated ${filePaths.css}`);
|
65
|
+
console.log(`Successfully generated ${filePaths.template}`);
|
66
|
+
|
67
|
+
// Change the color of the output
|
68
|
+
console.warn('\x1b[33m%s\x1b[0m', `
|
69
|
+
Make sure to import the component in your bundle by using:
|
70
|
+
import ${componentName} from "./dist/${componentName}.js";`);
|
122
71
|
}
|
123
72
|
|
124
|
-
|
73
|
+
// Main function
|
74
|
+
const createWebComponent = async () => {
|
75
|
+
const packageName = getPackageName();
|
76
|
+
const library = getLibraryName(packageName);
|
125
77
|
|
126
|
-
const
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
const sJsFileContentTemplate = jsFileContentTemplate(componentName);
|
78
|
+
const consoleArguments = process.argv.slice(2);
|
79
|
+
let componentName = consoleArguments[0];
|
80
|
+
let tagName = consoleArguments[1];
|
81
|
+
let language = consoleArguments[2];
|
82
|
+
let isTypeScript;
|
132
83
|
|
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+" });
|
136
84
|
|
85
|
+
if (componentName && !isNameValid(componentName)) {
|
86
|
+
throw new Error("Invalid component name. Please use only letters, numbers, dashes and underscores. The first character must be a letter.");
|
87
|
+
}
|
137
88
|
|
138
|
-
|
139
|
-
|
140
|
-
|
89
|
+
if (tagName && !isTagNameValid(tagName)) {
|
90
|
+
throw new Error("Invalid tag name. The tag name should only contain lowercase letters, numbers, dashes, and underscores. The first character must be a letter, and it should follow the pattern 'tag-name'.");
|
91
|
+
}
|
141
92
|
|
142
|
-
|
143
|
-
|
144
|
-
}
|
93
|
+
if (language && language !== "typescript" && language !== "ts" && language !== "javascript" && language !== "js") {
|
94
|
+
throw new Error("Invalid language. Please use 'typescript','javascript' or their respective 'ts','js'.");
|
95
|
+
}
|
145
96
|
|
146
|
-
|
147
|
-
|
148
|
-
|
97
|
+
if (!componentName) {
|
98
|
+
const response = await prompts({
|
99
|
+
type: "text",
|
100
|
+
name: "componentName",
|
101
|
+
message: "Please enter a component name:",
|
102
|
+
validate: (value) => isNameValid(value),
|
103
|
+
});
|
104
|
+
componentName = response.componentName;
|
105
|
+
|
106
|
+
if (!componentName) {
|
107
|
+
process.exit();
|
108
|
+
}
|
109
|
+
}
|
149
110
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
111
|
+
if (!tagName) {
|
112
|
+
const response = await prompts({
|
113
|
+
type: "text",
|
114
|
+
name: "tagName",
|
115
|
+
message: "Please enter a tag name:",
|
116
|
+
validate: (value) => isTagNameValid(value),
|
117
|
+
});
|
118
|
+
tagName = response.tagName;
|
119
|
+
|
120
|
+
if (!tagName) {
|
121
|
+
process.exit();
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
if (!language) {
|
126
|
+
const response = await prompts({
|
127
|
+
type: "select",
|
128
|
+
name: "isTypeScript",
|
129
|
+
message: "Please select a language:",
|
130
|
+
choices: [
|
131
|
+
{
|
132
|
+
title: "TypeScript (recommended)",
|
133
|
+
value: true,
|
134
|
+
},
|
135
|
+
{
|
136
|
+
title: "JavaScript",
|
137
|
+
value: false,
|
138
|
+
},
|
139
|
+
],
|
140
|
+
});
|
141
|
+
isTypeScript = response.isTypeScript;
|
142
|
+
} else if (language === "typescript" || language === "ts") {
|
143
|
+
isTypeScript = true;
|
144
|
+
} else {
|
145
|
+
isTypeScript = false;
|
146
|
+
}
|
147
|
+
|
148
|
+
generateFiles(componentName, tagName, library, packageName, isTypeScript);
|
149
|
+
};
|
150
|
+
|
151
|
+
createWebComponent();
|
@@ -0,0 +1,77 @@
|
|
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
|
+
static async onDefine() {
|
67
|
+
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
${componentName}.define();
|
72
|
+
|
73
|
+
export default ${componentName};
|
74
|
+
`;
|
75
|
+
};
|
76
|
+
|
77
|
+
module.exports = jsFileContentTemplate;
|
@@ -0,0 +1,84 @@
|
|
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
|
+
static async onDefine() {
|
74
|
+
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
${componentName}.define();
|
79
|
+
|
80
|
+
export default ${componentName};
|
81
|
+
`;
|
82
|
+
};
|
83
|
+
|
84
|
+
module.exports = tsFileContentTemplate;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ui5/webcomponents-tools",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.12.0-rc.0",
|
4
4
|
"description": "UI5 Web Components: webcomponents.tools",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -72,5 +72,5 @@
|
|
72
72
|
"devDependencies": {
|
73
73
|
"yargs": "^17.5.1"
|
74
74
|
},
|
75
|
-
"gitHead": "
|
75
|
+
"gitHead": "f5e3a2ba480455bc1154eee1b04ee04ebb0dbe14"
|
76
76
|
}
|