@ui5/webcomponents-tools 0.0.0-974b11d82 → 0.0.0-97db186fd
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 +146 -0
- package/components-package/eslint.js +34 -28
- package/components-package/nps.js +12 -6
- package/components-package/postcss.themes.js +10 -0
- package/components-package/vite.config.js +9 -5
- package/components-package/wdio.js +401 -393
- package/components-package/wdio.sync.js +9 -1
- package/icons-collection/nps.js +2 -2
- package/lib/create-icons/index.js +2 -2
- package/lib/create-new-component/index.js +71 -104
- package/lib/create-new-component/jsFileContentTemplate.js +73 -0
- package/lib/create-new-component/tsFileContentTemplate.js +80 -0
- package/lib/dev-server/virtual-index-html-plugin.js +1 -2
- package/lib/esm-abs-to-rel/index.js +1 -1
- package/lib/hbs2lit/src/compiler.js +9 -6
- package/lib/hbs2lit/src/litVisitor2.js +42 -17
- package/lib/hbs2lit/src/svgProcessor.js +12 -5
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
- package/lib/hbs2ui5/index.js +21 -4
- package/lib/i18n/toJSON.js +1 -1
- package/lib/jsdoc/preprocess.js +2 -2
- package/lib/postcss-css-to-esm/index.js +2 -2
- package/lib/replace-global-core/index.js +1 -1
- package/lib/test-runner/test-runner.js +10 -2
- package/package.json +10 -2
@@ -1,7 +1,35 @@
|
|
1
|
-
const
|
2
|
-
|
3
|
-
|
1
|
+
const tsImports = (controlName, hasTypes) => {
|
2
|
+
if (!process.env.UI5_TS) {
|
3
|
+
return "";
|
4
|
+
}
|
5
|
+
|
6
|
+
const importPrefix = process.env.UI5_BASE ? "../../../" : "@ui5/webcomponents-base/dist/"
|
7
|
+
|
8
|
+
return `import type UI5Element from "${importPrefix}UI5Element.js";
|
9
|
+
${importForControl(controlName, hasTypes)}
|
10
|
+
import type { ClassMapValue } from "${importPrefix}types.js";
|
11
|
+
`;
|
12
|
+
}
|
13
|
+
const importForControl = (controlName, hasTypes) => {
|
14
|
+
|
15
|
+
if (!hasTypes) {
|
16
|
+
return `type ${controlName} = any;`;
|
17
|
+
}
|
4
18
|
|
19
|
+
if (process.env.UI5_BASE) {
|
20
|
+
// base package has a component in `test/elements` instead of `src`
|
21
|
+
return `import type ${controlName} from "../../../../test/elements/${controlName}.js";`
|
22
|
+
}
|
23
|
+
return `import type ${controlName} from "../../${controlName}.js";`
|
24
|
+
}
|
25
|
+
|
26
|
+
const buildRenderer = (controlName, litTemplate, hasTypes) => {
|
27
|
+
const importPrefix = process.env.UI5_BASE ? "../../../" : "@ui5/webcomponents-base/dist/"
|
28
|
+
|
29
|
+
// typescript cannot process package imports for the same package and the paths are changed to relative for base package templates
|
30
|
+
return `/* eslint no-unused-vars: 0 */
|
31
|
+
import { html, svg, repeat, classMap, styleMap, ifDefined, unsafeHTML, scopeTag } from "${importPrefix}renderer/LitRenderer.js";
|
32
|
+
${tsImports(controlName, hasTypes)}
|
5
33
|
${litTemplate}
|
6
34
|
|
7
35
|
export default block0;`;
|
@@ -9,4 +37,4 @@ export default block0;`;
|
|
9
37
|
|
10
38
|
module.exports = {
|
11
39
|
generateTemplate: buildRenderer
|
12
|
-
};
|
40
|
+
};
|
package/lib/hbs2ui5/index.js
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
const fs = require('fs').promises;
|
2
|
+
const existsSync = require('fs').existsSync;
|
2
3
|
const getopts = require('getopts');
|
3
4
|
const hbs2lit = require('../hbs2lit');
|
4
5
|
const path = require('path');
|
5
6
|
const litRenderer = require('./RenderTemplates/LitRenderer');
|
6
7
|
const recursiveReadDir = require("recursive-readdir");
|
7
8
|
|
9
|
+
let missingTypesReported = false;
|
10
|
+
|
8
11
|
const args = getopts(process.argv.slice(2), {
|
9
12
|
alias: {
|
10
13
|
o: 'output',
|
@@ -23,13 +26,27 @@ const onError = (place) => {
|
|
23
26
|
|
24
27
|
const isHandlebars = (fileName) => fileName.indexOf('.hbs') !== -1;
|
25
28
|
|
29
|
+
const hasTypes = (file, componentName) => {
|
30
|
+
const tsFile = path.join(path.dirname(file), componentName + ".ts")
|
31
|
+
const dtsFile = path.join(path.dirname(file), componentName + ".d.ts")
|
32
|
+
return existsSync(tsFile) || existsSync(dtsFile);
|
33
|
+
}
|
34
|
+
|
26
35
|
const processFile = async (file, outputDir) => {
|
27
|
-
const litCode = await hbs2lit(file);
|
28
|
-
const absoluteOutputDir = composeAbsoluteOutputDir(file, outputDir);
|
29
36
|
const componentNameMatcher = /(\w+)(\.hbs)/gim;
|
30
37
|
const componentName = componentNameMatcher.exec(file)[1];
|
38
|
+
const componentHasTypes = hasTypes(file, componentName);
|
39
|
+
if (!componentHasTypes) {
|
40
|
+
if (!missingTypesReported) {
|
41
|
+
console.warn("[Warn] The following templates do not have a corresponging .ts or .d.ts file and won't be type checked:")
|
42
|
+
missingTypesReported = true;
|
43
|
+
}
|
44
|
+
console.log(" -> " + componentName + ".hbs");
|
45
|
+
}
|
46
|
+
const litCode = await hbs2lit(file, componentName);
|
47
|
+
const absoluteOutputDir = composeAbsoluteOutputDir(file, outputDir);
|
31
48
|
|
32
|
-
return writeRenderers(absoluteOutputDir, componentName, litRenderer.generateTemplate(componentName, litCode));
|
49
|
+
return writeRenderers(absoluteOutputDir, componentName, litRenderer.generateTemplate(componentName, litCode, componentHasTypes));
|
33
50
|
};
|
34
51
|
|
35
52
|
const composeAbsoluteOutputDir = (file, outputDir) => {
|
@@ -70,7 +87,7 @@ const writeRenderers = async (outputDir, controlName, fileContent) => {
|
|
70
87
|
|
71
88
|
await fs.mkdir(outputDir, { recursive: true });
|
72
89
|
|
73
|
-
const compiledFilePath = `${outputDir}${path.sep}${controlName}Template.lit.js`;
|
90
|
+
const compiledFilePath = `${outputDir}${path.sep}${controlName}Template.lit.${process.env.UI5_TS ? "ts" : "js"}`;
|
74
91
|
|
75
92
|
// strip DOS line endings because the break the source maps
|
76
93
|
let fileContentUnix = fileContent.replace(/\r\n/g, "\n");
|
package/lib/i18n/toJSON.js
CHANGED
@@ -34,7 +34,7 @@ const convertToJSON = async (file) => {
|
|
34
34
|
const generate = async () => {
|
35
35
|
const { globby } = await import("globby");
|
36
36
|
await fs.mkdir(messagesJSONDist, { recursive: true });
|
37
|
-
const files = await globby(messagesBundles);
|
37
|
+
const files = await globby(messagesBundles.replace(/\\/g, "/"));
|
38
38
|
return Promise.all(files.map(convertToJSON));
|
39
39
|
};
|
40
40
|
|
package/lib/jsdoc/preprocess.js
CHANGED
@@ -8,7 +8,7 @@ const sourceDir = process.argv[3];
|
|
8
8
|
const preprocessTypes = async () => {
|
9
9
|
try {
|
10
10
|
const { globby } = await import("globby");
|
11
|
-
const fileNames = await globby(inputDir + "**/types/*.js");
|
11
|
+
const fileNames = await globby(inputDir.replace(/\\/g, "/") + "**/types/*.js");
|
12
12
|
|
13
13
|
return Promise.all(fileNames.map(processTypeFile));
|
14
14
|
} catch(e) {
|
@@ -63,7 +63,7 @@ const preprocessComponents = async () => {
|
|
63
63
|
|
64
64
|
try {
|
65
65
|
const { globby } = await import("globby");
|
66
|
-
const fileNames = await globby(sourceDir + "/*.ts");
|
66
|
+
const fileNames = await globby(sourceDir.replace(/\\/g, "/") + "/*.ts");
|
67
67
|
|
68
68
|
return Promise.all(fileNames.map(processComponentFile));
|
69
69
|
} catch(e) {
|
@@ -70,7 +70,7 @@ module.exports = function (opts) {
|
|
70
70
|
mkdirp.sync(path.dirname(targetFile));
|
71
71
|
|
72
72
|
const filePath = `${targetFile}.${tsMode ? "ts" : "js"}`;
|
73
|
-
|
73
|
+
|
74
74
|
// it seems slower to read the old content, but writing the same content with no real changes
|
75
75
|
// (as in initial build and then watch mode) will cause an unnecessary dev server refresh
|
76
76
|
let oldContent = "";
|
@@ -80,7 +80,7 @@ module.exports = function (opts) {
|
|
80
80
|
// file not found
|
81
81
|
}
|
82
82
|
|
83
|
-
const content = getFileContent(tsMode,
|
83
|
+
const content = getFileContent(tsMode, targetFile, packageName, css, includeDefaultTheme);
|
84
84
|
if (content !== oldContent) {
|
85
85
|
fs.writeFileSync(filePath, content);
|
86
86
|
}
|
@@ -16,7 +16,7 @@ const replaceGlobalCoreUsage = async (srcPath) => {
|
|
16
16
|
|
17
17
|
const generate = async () => {
|
18
18
|
const { globby } = await import("globby");
|
19
|
-
const fileNames = await globby(basePath + "**/*.js");
|
19
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
20
20
|
return Promise.all(fileNames.map(replaceGlobalCoreUsage).filter(x => !!x));
|
21
21
|
};
|
22
22
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
const child_process = require("child_process");
|
2
2
|
const { readFileSync } = require("fs");
|
3
3
|
const path = require("path");
|
4
|
+
const fs = require("fs");
|
4
5
|
|
5
6
|
// search for dev-server port
|
6
7
|
// start in current folder
|
@@ -23,7 +24,7 @@ while (true) {
|
|
23
24
|
// check if we are in a monorepo and extract path from package.json
|
24
25
|
let packageRepositoryPath = "";
|
25
26
|
const pkg = require(path.join(process.cwd(), "package.json"));
|
26
|
-
packageRepositoryPath = pkg.repository.directory;
|
27
|
+
packageRepositoryPath = pkg.repository ? pkg.repository.directory : "";
|
27
28
|
|
28
29
|
// construct base url
|
29
30
|
// use devServerPort if a dev server is running, otherwise let the baseUrl in the wdio config be used
|
@@ -57,7 +58,14 @@ if (process.argv.length > 3) {
|
|
57
58
|
restParams = process.argv.slice(2).join(" ");
|
58
59
|
}
|
59
60
|
|
61
|
+
let wdioConfig = "";
|
62
|
+
if (fs.existsSync("config/wdio.conf.cjs")) {
|
63
|
+
wdioConfig = "config/wdio.conf.cjs";
|
64
|
+
} else if (fs.existsSync("config/wdio.conf.js")) {
|
65
|
+
wdioConfig = "config/wdio.conf.js";
|
66
|
+
}
|
67
|
+
|
60
68
|
// run wdio with calculated parameters
|
61
|
-
const cmd = `yarn cross-env WDIO_LOG_LEVEL=error wdio
|
69
|
+
const cmd = `yarn cross-env WDIO_LOG_LEVEL=error wdio ${wdioConfig} ${spec} ${baseUrl} ${restParams}`;
|
62
70
|
console.log(`executing: ${cmd}`);
|
63
71
|
child_process.execSync(cmd, {stdio: 'inherit'});
|
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-97db186fd",
|
4
4
|
"description": "UI5 Web Components: webcomponents.tools",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -52,11 +52,13 @@
|
|
52
52
|
"jsdoc": "^3.6.6",
|
53
53
|
"json-beautify": "^1.1.1",
|
54
54
|
"mkdirp": "^1.0.4",
|
55
|
+
"modify-selectors": "^2.0.0",
|
55
56
|
"nps": "^5.10.0",
|
56
57
|
"postcss": "^8.4.5",
|
57
58
|
"postcss-cli": "^9.1.0",
|
58
59
|
"postcss-import": "^14.0.2",
|
59
60
|
"postcss-selector-parser": "^6.0.10",
|
61
|
+
"prompts": "^2.4.2",
|
60
62
|
"properties-reader": "^2.2.0",
|
61
63
|
"recursive-readdir": "^2.2.2",
|
62
64
|
"resolve": "^1.20.0",
|
@@ -67,7 +69,13 @@
|
|
67
69
|
"zx": "^4.3.0"
|
68
70
|
},
|
69
71
|
"peerDependencies": {
|
70
|
-
"chromedriver": "*"
|
72
|
+
"chromedriver": "*",
|
73
|
+
"typescript": "^4.9.4"
|
74
|
+
},
|
75
|
+
"peerDependenciesMeta": {
|
76
|
+
"typescript": {
|
77
|
+
"optional": true
|
78
|
+
}
|
71
79
|
},
|
72
80
|
"devDependencies": {
|
73
81
|
"yargs": "^17.5.1"
|