@ui5/webcomponents-tools 0.0.0-1d11e4833 → 0.0.0-1f45608ac
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 +118 -0
- package/components-package/nps.js +18 -13
- package/components-package/postcss.components.js +13 -13
- package/components-package/postcss.themes.js +15 -15
- package/icons-collection/nps.js +6 -4
- package/lib/create-icons/index.js +33 -10
- package/lib/create-new-component/index.js +105 -108
- package/lib/create-new-component/jsFileContentTemplate.js +77 -0
- package/lib/create-new-component/tsFileContentTemplate.js +84 -0
- package/lib/generate-custom-elements-manifest/index.js +31 -77
- package/lib/i18n/defaults.js +9 -2
- package/lib/jsdoc/preprocess.js +2 -3
- package/lib/postcss-css-to-esm/index.js +40 -7
- package/package.json +2 -2
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.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
|
+
|
17
|
+
# [1.11.0](https://github.com/SAP/ui5-webcomponents/compare/v1.11.0-rc.4...v1.11.0) (2023-03-06)
|
18
|
+
|
19
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
# [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)
|
26
|
+
|
27
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
# [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)
|
34
|
+
|
35
|
+
|
36
|
+
### Features
|
37
|
+
|
38
|
+
* **playground:** next playground with storybook ([#5831](https://github.com/SAP/ui5-webcomponents/issues/5831)) ([79274c8](https://github.com/SAP/ui5-webcomponents/commit/79274c8e442cf5854a7fe6327f25aaed04312103)), closes [#5898](https://github.com/SAP/ui5-webcomponents/issues/5898)
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
# [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)
|
45
|
+
|
46
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
# [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)
|
53
|
+
|
54
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
# [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)
|
61
|
+
|
62
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
## [1.10.4-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.10.3...v1.10.4-rc.0) (2023-01-26)
|
69
|
+
|
70
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
## [1.10.3](https://github.com/SAP/ui5-webcomponents/compare/v1.10.2...v1.10.3) (2023-01-25)
|
77
|
+
|
78
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
## [1.10.2](https://github.com/SAP/ui5-webcomponents/compare/v1.10.1...v1.10.2) (2023-01-25)
|
85
|
+
|
86
|
+
**Note:** Version bump only for package ui5-webcomponents
|
87
|
+
|
88
|
+
## [1.10.1](https://github.com/SAP/ui5-webcomponents/compare/v0.0.0-7b49a7ff1...v1.10.1) (2023-01-24)
|
89
|
+
|
90
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
# [1.10.0](https://github.com/SAP/ui5-webcomponents/compare/v1.9.3...v1.10.0) (2023-01-20)
|
97
|
+
|
98
|
+
|
99
|
+
### Bug Fixes
|
100
|
+
|
101
|
+
* **infra:** set Content-Type header on testsuite ([#6108](https://github.com/SAP/ui5-webcomponents/issues/6108)) ([fae3f91](https://github.com/SAP/ui5-webcomponents/commit/fae3f91975ab1dad7135bea2227f61986eff403f))
|
102
|
+
|
103
|
+
|
104
|
+
### Features
|
105
|
+
|
106
|
+
* enable TS in main, fiori ([#6064](https://github.com/SAP/ui5-webcomponents/issues/6064)) ([0b56130](https://github.com/SAP/ui5-webcomponents/commit/0b561307b93b8af465dc5bee67650069ee138f7f))
|
107
|
+
* migrate illustrated-message component to TS, small refactor ([#6195](https://github.com/SAP/ui5-webcomponents/issues/6195)) ([046c779](https://github.com/SAP/ui5-webcomponents/commit/046c779f654648172619dd720c0d90342ec78fb9))
|
108
|
+
* support decorators for custom elements metadata ([#6072](https://github.com/SAP/ui5-webcomponents/issues/6072)) ([fc9ee6e](https://github.com/SAP/ui5-webcomponents/commit/fc9ee6e2af10b4315fde072a50ab37efa180c809))
|
109
|
+
* **ui5-button, ui5-date-picker, ui5-calendar:** migrate to TS ([#6173](https://github.com/SAP/ui5-webcomponents/issues/6173)) ([7232ca0](https://github.com/SAP/ui5-webcomponents/commit/7232ca08f286c5dde10080373fb62247f1acf7b7)), closes [#6080](https://github.com/SAP/ui5-webcomponents/issues/6080)
|
110
|
+
* use Typescript for the `base` package ([#5982](https://github.com/SAP/ui5-webcomponents/issues/5982)) ([bd184d8](https://github.com/SAP/ui5-webcomponents/commit/bd184d81a4218328bc7bf04baf2bc1f69a361679))
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
## [1.9.3](https://github.com/SAP/ui5-webcomponents/compare/v1.9.2...v1.9.3) (2022-12-16)
|
117
|
+
|
118
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
6
124
|
## [1.9.1](https://github.com/SAP/ui5-webcomponents/compare/v1.9.0...v1.9.1) (2022-11-10)
|
7
125
|
|
8
126
|
|
@@ -8,14 +8,17 @@ const getScripts = (options) => {
|
|
8
8
|
|
9
9
|
// The script creates all JS modules (dist/illustrations/{illustrationName}.js) out of the existing SVGs
|
10
10
|
const illustrationsData = options.illustrationsData || [];
|
11
|
-
illustrations = illustrationsData.map(illustration => `node "${LIB}/create-illustrations/index.js" ${illustration.path} ${illustration.defaultText} ${illustration.illustrationsPrefix} ${illustration.set} ${illustration.destinationPath}`);
|
11
|
+
const illustrations = illustrationsData.map(illustration => `node "${LIB}/create-illustrations/index.js" ${illustration.path} ${illustration.defaultText} ${illustration.illustrationsPrefix} ${illustration.set} ${illustration.destinationPath}`);
|
12
12
|
const createIllustrationsJSImportsScript = illustrations.join(" && ");
|
13
13
|
|
14
14
|
// The script creates the "dist/generated/js-imports/Illustration.js" file that registers loaders (dynamic JS imports) for each illustration
|
15
15
|
const illustrationDestinationPaths = illustrationsData.map(illustrations => illustrations.destinationPath);
|
16
16
|
const createIllustrationsLoadersScript = options.fioriPackage ? `node ${LIB}/generate-js-imports/illustrations.js ${illustrationDestinationPaths[0]} ${illustrationDestinationPaths[1]} dist/generated/js-imports` : "";
|
17
|
-
const
|
18
|
-
const
|
17
|
+
const tsOption = options.typescript;
|
18
|
+
const tsCommand = tsOption ? "tsc" : "";
|
19
|
+
const tsWatchCommand = tsOption ? "tsc --watch" : "";
|
20
|
+
const tsCrossEnv = tsOption ? "cross-env UI5_TS=true" : "";
|
21
|
+
const copySrcGenerated = tsOption ? "" : "copy.srcGenerated";
|
19
22
|
|
20
23
|
let viteConfig;
|
21
24
|
if (fs.existsSync("config/vite.config.js")) {
|
@@ -42,26 +45,26 @@ const getScripts = (options) => {
|
|
42
45
|
}
|
43
46
|
|
44
47
|
const scripts = {
|
45
|
-
clean: 'rimraf jsdoc-dist && rimraf dist && rimraf .port && nps "scope.testPages.clean"',
|
48
|
+
clean: 'rimraf jsdoc-dist && rimraf src/generated && rimraf dist && rimraf .port && nps "scope.testPages.clean"',
|
46
49
|
lint: `eslint . ${eslintConfig}`,
|
47
|
-
lintfix: `eslint . ${eslintConfig}`,
|
50
|
+
lintfix: `eslint . ${eslintConfig} --fix`,
|
48
51
|
prepare: {
|
49
|
-
default:
|
50
|
-
all: 'concurrently "nps build.templates" "nps build.i18n" "nps prepare.styleRelated" "nps copy" "nps
|
52
|
+
default: `${tsCrossEnv} nps clean prepare.all typescript generateAPI`,
|
53
|
+
all: 'concurrently "nps build.templates" "nps build.i18n" "nps prepare.styleRelated" "nps copy" "nps build.illustrations"',
|
51
54
|
styleRelated: "nps build.styles build.jsonImports build.jsImports",
|
52
55
|
},
|
53
56
|
typescript: tsCommand,
|
54
57
|
build: {
|
55
|
-
default: "nps lint
|
58
|
+
default: "nps prepare lint build.bundle",
|
56
59
|
templates: `mkdirp dist/generated/templates && node "${LIB}/hbs2ui5/index.js" -d src/ -o dist/generated/templates`,
|
57
60
|
styles: {
|
58
|
-
default:
|
61
|
+
default: `nps build.styles.themes build.styles.components ${copySrcGenerated}`,
|
59
62
|
themes: `node "${LIB}/postcss-p/postcss-p.mjs"`,
|
60
63
|
components: "postcss src/themes/*.css --config config/postcss.components --base src --dir dist/css/", // When updating this, also update the new files script
|
61
64
|
},
|
62
65
|
i18n: {
|
63
66
|
default: "nps build.i18n.defaultsjs build.i18n.json",
|
64
|
-
defaultsjs: `node "${LIB}/i18n/defaults.js" src/i18n
|
67
|
+
defaultsjs: `node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
|
65
68
|
json: `node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
|
66
69
|
},
|
67
70
|
jsonImports: {
|
@@ -79,10 +82,11 @@ const getScripts = (options) => {
|
|
79
82
|
copy: {
|
80
83
|
default: "nps copy.src copy.props",
|
81
84
|
src: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
|
85
|
+
srcGenerated: `node "${LIB}/copy-and-watch/index.js" --silent "src/generated/**/*.js" dist/generated/`,
|
82
86
|
props: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.properties" dist/`,
|
83
87
|
},
|
84
88
|
watch: {
|
85
|
-
default:
|
89
|
+
default: `${tsCrossEnv} concurrently "nps watch.templates" "nps watch.api" "nps watch.src" "nps watch.typescript" "nps watch.styles" "nps watch.i18n" "nps watch.props"`,
|
86
90
|
devServer: 'concurrently "nps watch.default" "nps watch.bundle"',
|
87
91
|
src: 'nps "copy.src --watch --safe --skip-initial-copy"',
|
88
92
|
typescript: tsWatchCommand,
|
@@ -120,8 +124,9 @@ const getScripts = (options) => {
|
|
120
124
|
bundle: `node ${LIB}/dev-server/dev-server.js ${viteConfig}`,
|
121
125
|
},
|
122
126
|
generateAPI: {
|
123
|
-
default: "nps generateAPI.prepare generateAPI.preprocess generateAPI.jsdoc generateAPI.cleanup",
|
124
|
-
prepare: `copy-and-watch "dist/**/*.js" jsdoc-dist/`,
|
127
|
+
default: "nps generateAPI.prepare generateAPI.preprocess generateAPI.jsdoc generateAPI.cleanup generateAPI.prepareManifest",
|
128
|
+
prepare: `node "${LIB}/copy-and-watch/index.js" --silent "dist/**/*.js" jsdoc-dist/`,
|
129
|
+
prepareManifest: `node "${LIB}/generate-custom-elements-manifest/index.js" dist dist`,
|
125
130
|
preprocess: `node "${preprocessJSDocScript}" jsdoc-dist/ src`,
|
126
131
|
jsdoc: `jsdoc -c "${LIB}/jsdoc/configTypescript.json"`,
|
127
132
|
cleanup: "rimraf jsdoc-dist/"
|
@@ -6,16 +6,16 @@ const fs = require("fs");
|
|
6
6
|
const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
|
7
7
|
|
8
8
|
module.exports = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
9
|
+
plugins: [
|
10
|
+
postcssImport(),
|
11
|
+
cssnano({
|
12
|
+
preset: [
|
13
|
+
'default', {
|
14
|
+
mergeLonghand: false, // https://github.com/cssnano/cssnano/issues/675
|
15
|
+
mergeRules: false, // https://github.com/cssnano/cssnano/issues/730
|
16
|
+
},
|
17
|
+
]
|
18
|
+
}),
|
19
|
+
postcssCSStoESM({ toReplace: 'src', includeDefaultTheme: true, packageName }),
|
20
|
+
]
|
21
|
+
}
|
@@ -8,19 +8,19 @@ const fs = require("fs");
|
|
8
8
|
const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
|
9
9
|
|
10
10
|
module.exports = {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
plugins: [
|
12
|
+
postcssImport(),
|
13
|
+
combineSelectors({
|
14
|
+
removeDuplicatedProperties: true
|
15
|
+
}),
|
16
|
+
cssnano({
|
17
|
+
preset: [
|
18
|
+
'default', {
|
19
|
+
mergeLonghand: false, // https://github.com/cssnano/cssnano/issues/675
|
20
|
+
},
|
21
|
+
]
|
22
|
+
},),
|
23
|
+
postcssCSStoJSON({ toReplace: 'src', packageName }),
|
24
|
+
postcssCSStoESM({ toReplace: 'src', packageName }),
|
25
|
+
]
|
26
26
|
};
|
package/icons-collection/nps.js
CHANGED
@@ -41,15 +41,17 @@ const copyIconAssetsCommand = (options) => {
|
|
41
41
|
const getScripts = (options) => {
|
42
42
|
const createJSImportsCmd = createIconImportsCommand(options);
|
43
43
|
const copyAssetsCmd = copyIconAssetsCommand(options);
|
44
|
+
const tsCommand = options.typescript ? "tsc" : "";
|
45
|
+
const tsCrossEnv = options.typescript ? "cross-env UI5_TS=true" : "";
|
44
46
|
|
45
47
|
const scripts = {
|
46
|
-
clean: "rimraf dist",
|
48
|
+
clean: "rimraf dist && rimraf src/generated",
|
47
49
|
copy: copyAssetsCmd,
|
48
50
|
build: {
|
49
|
-
default:
|
51
|
+
default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
|
50
52
|
i18n: {
|
51
53
|
default: "nps build.i18n.defaultsjs build.i18n.json",
|
52
|
-
defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n
|
54
|
+
defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
|
53
55
|
json: `mkdirp dist/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
|
54
56
|
},
|
55
57
|
jsonImports: {
|
@@ -58,7 +60,7 @@ const getScripts = (options) => {
|
|
58
60
|
},
|
59
61
|
icons: createJSImportsCmd,
|
60
62
|
},
|
61
|
-
typescript:
|
63
|
+
typescript: tsCommand,
|
62
64
|
};
|
63
65
|
|
64
66
|
return scripts;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
const fs = require("fs").promises;
|
2
2
|
const path = require("path");
|
3
3
|
|
4
|
-
const collectionName = process.argv[2] || "SAP-icons";
|
4
|
+
const collectionName = process.argv[2] || "SAP-icons-v4";
|
5
5
|
const collectionVersion = process.argv[3];
|
6
6
|
const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
|
7
7
|
const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
|
@@ -38,13 +38,13 @@ export { pathData, ltr, accData };`;
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
const collectionTemplate = (name) => `import { isThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
|
42
|
-
import {pathData as
|
43
|
-
import {pathData as
|
41
|
+
const collectionTemplate = (name, versions, fullName) => `import { isThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
|
42
|
+
import { pathData as pathData${versions[0]}, ltr, accData } from "./${versions[0]}/${name}.js";
|
43
|
+
import { pathData as pathData${versions[1]} } from "./${versions[1]}/${name}.js";
|
44
44
|
|
45
|
-
const pathData = isThemeFamily("sap_horizon") ?
|
45
|
+
const pathData = isThemeFamily("sap_horizon") ? pathData${versions[1]} : pathData${versions[0]};
|
46
46
|
|
47
|
-
export default "${
|
47
|
+
export default "${fullName}";
|
48
48
|
export { pathData, ltr, accData };`;
|
49
49
|
|
50
50
|
|
@@ -80,22 +80,45 @@ const createIcons = async (file) => {
|
|
80
80
|
const pathData = iconData.path;
|
81
81
|
const ltr = !!iconData.ltr;
|
82
82
|
const acc = iconData.acc;
|
83
|
+
const packageName = json.packageName;
|
84
|
+
const collection = json.collection;
|
83
85
|
|
84
|
-
const content = acc ? iconAccTemplate(name, pathData, ltr, acc,
|
86
|
+
const content = acc ? iconAccTemplate(name, pathData, ltr, acc, collection, packageName) : iconTemplate(name, pathData, ltr, collection, packageName);
|
85
87
|
|
86
88
|
promises.push(fs.writeFile(path.join(destDir, `${name}.js`), content));
|
87
89
|
promises.push(fs.writeFile(path.join(destDir, `${name}.svg`), svgTemplate(pathData)));
|
88
|
-
promises.push(fs.writeFile(path.join(destDir, `${name}.d.ts`), typeDefinitionTemplate(name, acc,
|
90
|
+
promises.push(fs.writeFile(path.join(destDir, `${name}.d.ts`), typeDefinitionTemplate(name, acc, collection)));
|
91
|
+
|
92
|
+
// For versioned icons collections, the script creates top level (unversioned) module that internally imports the versioned ones.
|
93
|
+
// For example, the top level "@ui5/ui5-webcomponents-icons/dist/accept.js" imports:
|
94
|
+
// - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
|
95
|
+
// - "@ui5/ui5-webcomponents-icons/dist/v4/accept.js"
|
89
96
|
|
90
97
|
if (json.version) {
|
91
|
-
|
92
|
-
|
98
|
+
// The exported value from the top level (unversioned) icon module depends on whether the collection is the default,
|
99
|
+
// to add or not the collection name to the exported value:
|
100
|
+
// For the default collection (SAPIcons) we export just the icon name - "export default { 'accept' }"
|
101
|
+
// For non-default collections (SAPTNTIcons and SAPBSIcons) we export the full name - "export default { 'tnt/actor' }"
|
102
|
+
const effectiveName = isDefaultCollection(collection) ? name : getUnversionedFullIconName(name, collection);
|
103
|
+
promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name, json.versions, effectiveName)));
|
104
|
+
promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.d.ts`), collectionTypeDefinitionTemplate(effectiveName, acc)));
|
93
105
|
}
|
94
106
|
}
|
95
107
|
|
96
108
|
return Promise.all(promises);
|
97
109
|
};
|
98
110
|
|
111
|
+
const isDefaultCollection = collectionName => collectionName === "SAP-icons-v4" || collectionName === "SAP-icons-v5";
|
112
|
+
const getUnversionedFullIconName = (name, collection) => `${getUnversionedCollectionName(collection)}/${name}`;
|
113
|
+
const getUnversionedCollectionName = collectionName => CollectionVersionedToUnversionedMap[collectionName] || collectionName;
|
114
|
+
|
115
|
+
const CollectionVersionedToUnversionedMap = {
|
116
|
+
"tnt-v2": "tnt",
|
117
|
+
"tnt-v3": "tnt",
|
118
|
+
"business-suite-v1": "business-suite",
|
119
|
+
"business-suite-v2": "business-suite",
|
120
|
+
};
|
121
|
+
|
99
122
|
createIcons(srcFile).then(() => {
|
100
123
|
console.log("Icons created.");
|
101
124
|
});
|
@@ -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;
|
@@ -1,9 +1,12 @@
|
|
1
1
|
const fs = require("fs").promises;
|
2
|
+
const path = require("path");
|
2
3
|
// https://github.com/webcomponents/custom-elements-manifest/blob/main/schema.json
|
3
4
|
|
5
|
+
const inputDir = process.argv[2];
|
6
|
+
const outputDir = process.argv[3];
|
7
|
+
|
4
8
|
const camelToKebabMap = new Map();
|
5
9
|
const apiIndex = new Map();
|
6
|
-
const processedApiIndex = new Set();
|
7
10
|
const forbiddenAttributeTypes = ["object", "array"];
|
8
11
|
|
9
12
|
const camelToKebabCase = string => {
|
@@ -16,7 +19,7 @@ const camelToKebabCase = string => {
|
|
16
19
|
|
17
20
|
const generateJavaScriptExport = entity => {
|
18
21
|
return {
|
19
|
-
declaration: generateRefenrece(entity),
|
22
|
+
declaration: generateRefenrece(entity.name),
|
20
23
|
deprecated: !!entity.deprecated,
|
21
24
|
kind: "js",
|
22
25
|
name: "default",
|
@@ -226,8 +229,6 @@ const generateSlots = slots => {
|
|
226
229
|
};
|
227
230
|
|
228
231
|
const generateCustomElementDeclaration = entity => {
|
229
|
-
entity = generateFullComponentApi(entity);
|
230
|
-
|
231
232
|
let generatedCustomElementDeclaration = {
|
232
233
|
deprecated: !!entity.deprecated,
|
233
234
|
customElement: true,
|
@@ -265,107 +266,60 @@ const generateCustomElementDeclaration = entity => {
|
|
265
266
|
}
|
266
267
|
|
267
268
|
if (entity.extends && entity.extends !== "HTMLElement") {
|
268
|
-
generatedCustomElementDeclaration.superclass = generateRefenrece(
|
269
|
+
generatedCustomElementDeclaration.superclass = generateRefenrece(entity.extends);
|
269
270
|
}
|
270
271
|
|
271
272
|
return generatedCustomElementDeclaration;
|
272
273
|
};
|
273
274
|
|
274
|
-
const generateRefenrece = (
|
275
|
+
const generateRefenrece = (entityName) => {
|
275
276
|
let packageName;
|
277
|
+
let basename;
|
276
278
|
|
277
|
-
if (!
|
279
|
+
if (!entityName) {
|
278
280
|
throw new Error("JSDoc error: entity not found in api.json.");
|
279
281
|
}
|
280
282
|
|
281
|
-
if (
|
283
|
+
if (entityName.includes(".")) {
|
284
|
+
basename = entityName.split(".").pop();
|
285
|
+
} else {
|
286
|
+
basename = entityName
|
287
|
+
}
|
288
|
+
|
289
|
+
if (entityName.includes("sap.ui.webc.main")) {
|
282
290
|
packageName = "@ui5/webcomponents";
|
283
|
-
} else if (
|
291
|
+
} else if (entityName.includes("sap.ui.webc.fiori")) {
|
284
292
|
packageName = "@ui5/webcomponents-fiori";
|
285
|
-
} else if (
|
293
|
+
} else if (entityName.includes("sap.ui.webc.base")) {
|
286
294
|
packageName = "@ui5/webcomponents-base";
|
287
295
|
}
|
288
296
|
|
289
297
|
return {
|
290
|
-
module: `${
|
291
|
-
name: `${
|
298
|
+
module: `${basename}.js`,
|
299
|
+
name: `${basename}`,
|
292
300
|
package: packageName,
|
293
301
|
};
|
294
302
|
};
|
295
303
|
|
296
|
-
const generateFullComponentApi = entity => {
|
297
|
-
const componentProps = ["properties", "slots", "events", "methods"];
|
298
|
-
let parent = apiIndex.get(entity.extends);
|
299
|
-
|
300
|
-
if (!parent) {
|
301
|
-
processedApiIndex.add(entity.name);
|
302
|
-
|
303
|
-
return entity;
|
304
|
-
}
|
305
|
-
|
306
|
-
parent = processedApiIndex.has(entity.extends) ? apiIndex.get(entity.extends) : generateFullComponentApi(parent);
|
307
|
-
|
308
|
-
componentProps.forEach(prop => {
|
309
|
-
if (parent[prop] && parent[prop].length) {
|
310
|
-
if (entity[prop] && entity[prop].length) {
|
311
|
-
const uniqueParentState = parent[prop].filter(pSlot => {
|
312
|
-
return !entity[prop].some(eSlot => eSlot.name === pSlot.name);
|
313
|
-
});
|
314
|
-
|
315
|
-
entity[prop] = entity[prop].concat(uniqueParentState);
|
316
|
-
} else {
|
317
|
-
entity[prop] = [...parent[prop]];
|
318
|
-
}
|
319
|
-
}
|
320
|
-
});
|
321
|
-
|
322
|
-
processedApiIndex.add(entity.name);
|
323
|
-
|
324
|
-
return entity;
|
325
|
-
};
|
326
|
-
|
327
304
|
const filterPublicApi = array => {
|
328
305
|
return (array || []).filter(el => el.visibility === "public");
|
329
306
|
};
|
330
307
|
|
331
308
|
const generate = async () => {
|
332
|
-
const
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
let apiFiles = new Map();
|
339
|
-
|
340
|
-
await Promise.all(apiFilesPaths.map(async (apiFilePath) => {
|
341
|
-
const file = JSON.parse(await fs.readFile(apiFilePath));
|
342
|
-
|
343
|
-
apiFiles.set(apiFilePath, file);
|
344
|
-
|
345
|
-
file.symbols.forEach(symbol => {
|
346
|
-
apiIndex.set(symbol.name, symbol);
|
347
|
-
});
|
348
|
-
}));
|
309
|
+
const file = JSON.parse(await fs.readFile(path.join(inputDir, "api.json")));
|
310
|
+
let customElementsManifest = {
|
311
|
+
schemaVersion: "1.0.0",
|
312
|
+
readme: "",
|
313
|
+
modules: [],
|
314
|
+
};
|
349
315
|
|
350
|
-
|
351
|
-
if (
|
352
|
-
|
316
|
+
file.symbols.forEach(entity => {
|
317
|
+
if (entity.tagname) {
|
318
|
+
customElementsManifest.modules.push(generateJavaScriptModule(entity));
|
353
319
|
}
|
320
|
+
});
|
354
321
|
|
355
|
-
|
356
|
-
schemaVersion: "1.0.0",
|
357
|
-
readme: "",
|
358
|
-
modules: [],
|
359
|
-
};
|
360
|
-
|
361
|
-
apiFiles.get(apiFilePath).symbols.forEach(entity => {
|
362
|
-
if (entity.tagname) {
|
363
|
-
customElementsManifest.modules.push(generateJavaScriptModule(entity));
|
364
|
-
}
|
365
|
-
});
|
366
|
-
|
367
|
-
await fs.writeFile(apiFilePath.replace("api.json", "custom-elements.json"), JSON.stringify(customElementsManifest));
|
368
|
-
}));
|
322
|
+
await fs.writeFile(path.join(outputDir, "custom-elements.json"), JSON.stringify(customElementsManifest));
|
369
323
|
};
|
370
324
|
|
371
325
|
generate().then(() => {
|
package/lib/i18n/defaults.js
CHANGED
@@ -8,7 +8,9 @@ const generate = async () => {
|
|
8
8
|
|
9
9
|
const messageBundle = path.normalize(`${process.argv[2]}/messagebundle.properties`);
|
10
10
|
const messageBundleDefaultLanguage = path.normalize(`${process.argv[2]}/messagebundle_${defaultLanguage}.properties`);
|
11
|
-
const
|
11
|
+
const tsMode = process.env.UI5_TS === "true"; // In Typescript mode, we output .ts files and set the required types, otherwise - output pure .js files
|
12
|
+
|
13
|
+
const outputFile = path.normalize(`${process.argv[3]}/i18n-defaults.${tsMode ? "ts": "js"}`);
|
12
14
|
|
13
15
|
if (!messageBundle || !outputFile) {
|
14
16
|
return;
|
@@ -45,6 +47,9 @@ const generate = async () => {
|
|
45
47
|
let effectiveValue = defaultLanguageValue || value;
|
46
48
|
effectiveValue = effectiveValue.replace(/\"/g, "\\\""); // escape double quotes in translations
|
47
49
|
|
50
|
+
if (tsMode) {
|
51
|
+
return `const ${key}: I18nText = {key: "${key}", defaultText: "${effectiveValue}"};`;
|
52
|
+
}
|
48
53
|
return `const ${key} = {key: "${key}", defaultText: "${effectiveValue}"};`;
|
49
54
|
};
|
50
55
|
|
@@ -62,7 +67,9 @@ const generate = async () => {
|
|
62
67
|
const textKeys = Object.keys(properties);
|
63
68
|
const texts = textKeys.map(prop => getTextInfo(prop, properties[prop], defaultLanguageProperties && defaultLanguageProperties[prop])).join('');
|
64
69
|
|
65
|
-
|
70
|
+
// tabs are intentionally mixed to have proper identation in the produced file
|
71
|
+
return `${tsMode ? `import { I18nText } from "@ui5/webcomponents-base/dist/i18nBundle.js";` : ""}
|
72
|
+
${texts}
|
66
73
|
export {${textKeys.join()}};`;
|
67
74
|
};
|
68
75
|
|
package/lib/jsdoc/preprocess.js
CHANGED
@@ -75,9 +75,8 @@ const isClass = text => {
|
|
75
75
|
return text.includes("@abstract") || text.includes("@class");
|
76
76
|
};
|
77
77
|
|
78
|
-
const isAnnotationComment = (comment
|
79
|
-
|
80
|
-
return fileContent.substr(index + comment.length).trim().charAt(0) === "@";
|
78
|
+
const isAnnotationComment = (comment) => {
|
79
|
+
return comment.includes("@name");
|
81
80
|
}
|
82
81
|
|
83
82
|
const processComponentFile = async (fileName) => {
|
@@ -11,11 +11,38 @@ const getDefaultThemeCode = packageName => {
|
|
11
11
|
import defaultThemeBase from "@ui5/webcomponents-theming/dist/generated/themes/${DEFAULT_THEME}/parameters-bundle.css.js";
|
12
12
|
import defaultTheme from "./${DEFAULT_THEME}/parameters-bundle.css.js";
|
13
13
|
|
14
|
-
registerThemePropertiesLoader("@ui5/webcomponents-theming", "${DEFAULT_THEME}", () => defaultThemeBase);
|
15
|
-
registerThemePropertiesLoader("${packageName}", "${DEFAULT_THEME}", () => defaultTheme);
|
14
|
+
registerThemePropertiesLoader("@ui5/webcomponents-theming", "${DEFAULT_THEME}", async () => defaultThemeBase);
|
15
|
+
registerThemePropertiesLoader("${packageName}", "${DEFAULT_THEME}", async () => defaultTheme);
|
16
16
|
`;
|
17
17
|
};
|
18
18
|
|
19
|
+
const getFileContent = (tsMode, targetFile, packageName, css, includeDefaultTheme) => {
|
20
|
+
if (tsMode) {
|
21
|
+
return getTSContent(targetFile, packageName, css, includeDefaultTheme);
|
22
|
+
}
|
23
|
+
|
24
|
+
return getJSContent(targetFile, packageName, css, includeDefaultTheme);
|
25
|
+
}
|
26
|
+
|
27
|
+
const getTSContent = (targetFile, packageName, css, includeDefaultTheme) => {
|
28
|
+
const typeImport = "import type { StyleData } from \"@ui5/webcomponents-base/dist/types.js\";"
|
29
|
+
const defaultTheme = includeDefaultTheme ? getDefaultThemeCode(packageName) : "";
|
30
|
+
|
31
|
+
// tabs are intentionally mixed to have proper identation in the produced file
|
32
|
+
return `${typeImport}
|
33
|
+
${defaultTheme}
|
34
|
+
const styleData: StyleData = {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}};
|
35
|
+
export default styleData;
|
36
|
+
`;
|
37
|
+
}
|
38
|
+
|
39
|
+
const getJSContent = (targetFile, packageName, css, includeDefaultTheme) => {
|
40
|
+
const defaultTheme = includeDefaultTheme ? getDefaultThemeCode(packageName) : "";
|
41
|
+
|
42
|
+
return `${defaultTheme}export default {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
|
43
|
+
}
|
44
|
+
|
45
|
+
|
19
46
|
const proccessCSS = css => {
|
20
47
|
css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
|
21
48
|
css = css.replace(/\.background-image.*{.*}/, "");
|
@@ -27,18 +54,23 @@ const proccessCSS = css => {
|
|
27
54
|
module.exports = function (opts) {
|
28
55
|
opts = opts || {};
|
29
56
|
|
57
|
+
const packageName = opts.packageName;
|
58
|
+
const includeDefaultTheme = opts.includeDefaultTheme;
|
59
|
+
const toReplace = opts.toReplace;
|
60
|
+
|
30
61
|
return {
|
31
62
|
postcssPlugin: 'postcss-css-to-esm',
|
32
63
|
Once (root) {
|
64
|
+
const tsMode = process.env.UI5_TS === "true";
|
65
|
+
|
33
66
|
let css = root.toString();
|
34
67
|
css = proccessCSS(css);
|
35
68
|
|
36
|
-
const targetFile = root.source.input.from.replace(`/${
|
69
|
+
const targetFile = root.source.input.from.replace(`/${toReplace}/`, "/src/generated/").replace(`\\${toReplace}\\`, "\\src\\generated\\");
|
37
70
|
mkdirp.sync(path.dirname(targetFile));
|
38
71
|
|
39
|
-
const filePath = `${targetFile}
|
40
|
-
|
41
|
-
|
72
|
+
const filePath = `${targetFile}.${tsMode ? "ts" : "js"}`;
|
73
|
+
|
42
74
|
// it seems slower to read the old content, but writing the same content with no real changes
|
43
75
|
// (as in initial build and then watch mode) will cause an unnecessary dev server refresh
|
44
76
|
let oldContent = "";
|
@@ -47,7 +79,8 @@ module.exports = function (opts) {
|
|
47
79
|
} catch (e) {
|
48
80
|
// file not found
|
49
81
|
}
|
50
|
-
|
82
|
+
|
83
|
+
const content = getFileContent(tsMode, filePath, packageName, css, includeDefaultTheme);
|
51
84
|
if (content !== oldContent) {
|
52
85
|
fs.writeFileSync(filePath, content);
|
53
86
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ui5/webcomponents-tools",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-1f45608ac",
|
4
4
|
"description": "UI5 Web Components: webcomponents.tools",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -62,7 +62,7 @@
|
|
62
62
|
"resolve": "^1.20.0",
|
63
63
|
"rimraf": "^3.0.2",
|
64
64
|
"slash": "3.0.0",
|
65
|
-
"vite": "^
|
65
|
+
"vite": "^3.0.4",
|
66
66
|
"wdio-chromedriver-service": "^7.3.2",
|
67
67
|
"zx": "^4.3.0"
|
68
68
|
},
|