@ui5/webcomponents-tools 0.0.0-9c26e8e4f → 0.0.0-a289c53b5
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 +258 -0
- package/components-package/eslint.js +34 -0
- package/components-package/nps.js +53 -22
- package/components-package/postcss.components.js +13 -13
- package/components-package/postcss.themes.js +15 -15
- package/components-package/vite.config.js +6 -5
- package/components-package/wdio.js +393 -386
- package/icons-collection/nps.js +6 -3
- package/lib/copy-list/index.js +2 -2
- package/lib/create-icons/index.js +52 -10
- package/lib/create-new-component/index.js +81 -108
- package/lib/create-new-component/jsFileContentTemplate.js +77 -0
- package/lib/create-new-component/tsFileContentTemplate.js +84 -0
- package/lib/dev-server/virtual-index-html-plugin.js +2 -2
- package/lib/esm-abs-to-rel/index.js +1 -1
- package/lib/generate-custom-elements-manifest/index.js +327 -0
- package/lib/generate-js-imports/illustrations.js +72 -0
- package/lib/hbs2lit/src/compiler.js +8 -0
- package/lib/hbs2lit/src/litVisitor2.js +46 -8
- package/lib/i18n/defaults.js +18 -2
- package/lib/i18n/toJSON.js +1 -1
- package/lib/jsdoc/configTypescript.json +29 -0
- package/lib/jsdoc/plugin.js +32 -0
- package/lib/jsdoc/preprocess.js +146 -0
- package/lib/jsdoc/template/publish.js +9 -1
- package/lib/postcss-css-to-esm/index.js +40 -7
- package/lib/replace-global-core/index.js +1 -1
- package/lib/scoping/get-all-tags.js +1 -8
- package/lib/test-runner/test-runner.js +10 -2
- package/package.json +11 -3
@@ -0,0 +1,146 @@
|
|
1
|
+
const process = require("process");
|
2
|
+
const path = require("path");
|
3
|
+
const fs = require("fs/promises");
|
4
|
+
|
5
|
+
const inputDir = process.argv[2];
|
6
|
+
const sourceDir = process.argv[3];
|
7
|
+
|
8
|
+
const preprocessTypes = async () => {
|
9
|
+
try {
|
10
|
+
const { globby } = await import("globby");
|
11
|
+
const fileNames = await globby(inputDir.replace(/\\/g, "/") + "**/types/*.js");
|
12
|
+
|
13
|
+
return Promise.all(fileNames.map(processTypeFile));
|
14
|
+
} catch(e) {
|
15
|
+
console.log("JSDoc types preprocess failed: ", e);
|
16
|
+
}
|
17
|
+
};
|
18
|
+
|
19
|
+
const processTypeFile = async (fileName) => {
|
20
|
+
let fileContent = `${await fs.readFile(fileName)}`;
|
21
|
+
|
22
|
+
const re = new RegExp(`(\\/\\*\\*\\s*\\n([^\\*]|(\\*(?!\\/)))*\\*\\/)\\s+[\\w\\d]+\\[\\"([\\w\\d]+)\\"\\]\\s*=\\s*\\"([\\w\\d]+)\\";`, "gm")
|
23
|
+
let matches = [...fileContent.matchAll(re)];
|
24
|
+
|
25
|
+
// Get all type values
|
26
|
+
const typeData = matches.map(match => {
|
27
|
+
return {
|
28
|
+
comment: match[1],
|
29
|
+
key: match[4],
|
30
|
+
value: match[5],
|
31
|
+
};
|
32
|
+
});
|
33
|
+
if (typeData.length === 0) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
37
|
+
const typeName = path.parse(fileName).name;
|
38
|
+
|
39
|
+
matches = fileContent.match(/\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\//gm);
|
40
|
+
const comment = matches[0];
|
41
|
+
|
42
|
+
const propsCode = typeData.map(item => {
|
43
|
+
return `${item.comment}\n get ${item.key}() { return "${item.value}"; }`;
|
44
|
+
}).join("\n");
|
45
|
+
|
46
|
+
const newClassCode = `
|
47
|
+
${comment}
|
48
|
+
class ${typeName} {
|
49
|
+
${propsCode}
|
50
|
+
};
|
51
|
+
|
52
|
+
export default ${typeName};`;
|
53
|
+
|
54
|
+
fileContent = newClassCode;
|
55
|
+
|
56
|
+
return fs.writeFile(fileName, fileContent);
|
57
|
+
};
|
58
|
+
|
59
|
+
const preprocessComponents = async () => {
|
60
|
+
if (!sourceDir) {
|
61
|
+
return; // if the second param was not passed, there are no components
|
62
|
+
}
|
63
|
+
|
64
|
+
try {
|
65
|
+
const { globby } = await import("globby");
|
66
|
+
const fileNames = await globby(sourceDir.replace(/\\/g, "/") + "/*.ts");
|
67
|
+
|
68
|
+
return Promise.all(fileNames.map(processComponentFile));
|
69
|
+
} catch(e) {
|
70
|
+
console.log("JSDoc components preprocess failed: ", e);
|
71
|
+
}
|
72
|
+
};
|
73
|
+
|
74
|
+
const isClass = text => {
|
75
|
+
return text.includes("@abstract") || text.includes("@class");
|
76
|
+
};
|
77
|
+
|
78
|
+
const isAnnotationComment = (comment) => {
|
79
|
+
return comment.includes("@name");
|
80
|
+
}
|
81
|
+
|
82
|
+
const processComponentFile = async (fileName) => {
|
83
|
+
// source file (src/*.ts)
|
84
|
+
let tsFileContent = `${await fs.readFile(fileName)}`;
|
85
|
+
|
86
|
+
// Skip all non-component files
|
87
|
+
if (!isClass(tsFileContent)) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
|
91
|
+
// Gather all JSDocs from the original .ts file
|
92
|
+
const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
|
93
|
+
let allJSDocs = [...tsFileContent.matchAll(allJSDocsRegExp)];
|
94
|
+
allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
|
95
|
+
|
96
|
+
// Find where the class is defined in the original file
|
97
|
+
const tsClassDefinitionRegExp = new RegExp(`^(abstract\\s)?class [\\w\\d_]+`, "gm");
|
98
|
+
let tsClassDefinitionMatch = tsFileContent.match(tsClassDefinitionRegExp);
|
99
|
+
if (!tsClassDefinitionMatch) {
|
100
|
+
return; // no class defined in this .ts file
|
101
|
+
}
|
102
|
+
const tsClassDefinition = tsClassDefinitionMatch[0];
|
103
|
+
const tsClassDefinitionIndex = tsFileContent.indexOf(tsClassDefinition);
|
104
|
+
|
105
|
+
// Gather all JSDocs that are before the class definition (except for the @class one)
|
106
|
+
const JSDocsToAppend = [];
|
107
|
+
allJSDocs.forEach(JSDoc => {
|
108
|
+
if (!isClass(JSDoc) && (tsFileContent.indexOf(JSDoc) < tsClassDefinitionIndex || isAnnotationComment(JSDoc, tsFileContent))) {
|
109
|
+
JSDocsToAppend.push(JSDoc);
|
110
|
+
}
|
111
|
+
});
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
// destination file (jsdoc-dist/*.js)
|
116
|
+
const destFileName = fileName.replace(sourceDir, inputDir).replace(/\.ts$/, ".js");
|
117
|
+
let jsFileContent = `${await fs.readFile(destFileName)}`;
|
118
|
+
|
119
|
+
const classDefinitionRegExp = new RegExp(`let.*? = class`, "gm");
|
120
|
+
let classDefinitionMatch = jsFileContent.match(classDefinitionRegExp);
|
121
|
+
if (!classDefinitionMatch) {
|
122
|
+
return; // not a file, generated by typescript, nothing to do here
|
123
|
+
}
|
124
|
+
|
125
|
+
const classDefinition = classDefinitionMatch[0];
|
126
|
+
const classDefinitionIndex = jsFileContent.indexOf(classDefinition); // classDefinitionIndex is the position in the file where the class is defined
|
127
|
+
|
128
|
+
// All comments before the class definition, except for the @class comment, must be removed
|
129
|
+
allJSDocs.forEach(JSDoc => {
|
130
|
+
if (!isClass(JSDoc) && jsFileContent.indexOf(JSDoc) < classDefinitionIndex) {
|
131
|
+
jsFileContent = jsFileContent.replace(JSDoc, "");
|
132
|
+
}
|
133
|
+
});
|
134
|
+
|
135
|
+
// Put all other comments at the end of the file
|
136
|
+
jsFileContent = jsFileContent + "\n\n" + JSDocsToAppend.join("\n\n");
|
137
|
+
return fs.writeFile(destFileName, jsFileContent);
|
138
|
+
};
|
139
|
+
|
140
|
+
Promise.all([
|
141
|
+
preprocessTypes(),
|
142
|
+
preprocessComponents(),
|
143
|
+
]).then(() => {
|
144
|
+
console.log("JSDoc preprocess ready.");
|
145
|
+
});
|
146
|
+
|
@@ -2820,6 +2820,14 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
|
|
2820
2820
|
attrib("since", extractVersion(member.since));
|
2821
2821
|
}
|
2822
2822
|
|
2823
|
+
if ( member.formEvents ) {
|
2824
|
+
attrib("formEvents", member.formEvents);
|
2825
|
+
}
|
2826
|
+
|
2827
|
+
if ( member.formEvents ) {
|
2828
|
+
attrib("formProperty", member.formProperty);
|
2829
|
+
}
|
2830
|
+
|
2823
2831
|
var type = listTypes(member.type);
|
2824
2832
|
attrib("type", type);
|
2825
2833
|
|
@@ -3865,7 +3873,7 @@ function createAPIJS(symbols, filename) {
|
|
3865
3873
|
|
3866
3874
|
var output = [];
|
3867
3875
|
|
3868
|
-
var rkeywords = /^(?:abstract|as|boolean|break|byte|case|catch|char|class|continue|const|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|is|long|namespace|native|new|null|noattribute|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|use|var|void|volatile|while|with)$/;
|
3876
|
+
var rkeywords = /^(?:abstract|as|boolean|break|byte|case|catch|char|class|continue|const|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|formEvents|formProperty|goto|if|implements|import|in|instanceof|int|interface|is|long|namespace|native|new|null|noattribute|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|use|var|void|volatile|while|with)$/;
|
3869
3877
|
|
3870
3878
|
function isNoKeyword($) { return !rkeywords.test($.name); }
|
3871
3879
|
|
@@ -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, targetFile, packageName, css, includeDefaultTheme);
|
51
84
|
if (content !== oldContent) {
|
52
85
|
fs.writeFileSync(filePath, content);
|
53
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
|
|
@@ -8,18 +8,11 @@ const getTag = file => {
|
|
8
8
|
return matches ? matches[1] : undefined;
|
9
9
|
};
|
10
10
|
|
11
|
-
const getAltTag = file => {
|
12
|
-
const fileContent = String(fs.readFileSync(file)).replace(/\n/g, "");
|
13
|
-
const matches = fileContent.match(/\baltTag\b:\s*\"(.*?)\"/);
|
14
|
-
return matches ? matches[1] : undefined;
|
15
|
-
};
|
16
|
-
|
17
11
|
const getPackageTags = (packageDir) => {
|
18
12
|
const srcDir = path.join(packageDir, "src/");
|
19
13
|
return glob.sync(path.join(srcDir, "/**/*.js")).flatMap(file => {
|
20
14
|
const tag = getTag(file);
|
21
|
-
|
22
|
-
return [tag, altTag];
|
15
|
+
return [tag];
|
23
16
|
}).filter(item => !!item);
|
24
17
|
};
|
25
18
|
|
@@ -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-a289c53b5",
|
4
4
|
"description": "UI5 Web Components: webcomponents.tools",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -21,6 +21,8 @@
|
|
21
21
|
"directory": "packages/tools"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
25
|
+
"@typescript-eslint/parser": "^5.42.1",
|
24
26
|
"@wdio/cli": "^7.19.7",
|
25
27
|
"@wdio/devtools-service": "^7.19.7",
|
26
28
|
"@wdio/dot-reporter": "^7.19.7",
|
@@ -60,12 +62,18 @@
|
|
60
62
|
"resolve": "^1.20.0",
|
61
63
|
"rimraf": "^3.0.2",
|
62
64
|
"slash": "3.0.0",
|
63
|
-
"vite": "^
|
65
|
+
"vite": "^3.0.4",
|
64
66
|
"wdio-chromedriver-service": "^7.3.2",
|
65
67
|
"zx": "^4.3.0"
|
66
68
|
},
|
67
69
|
"peerDependencies": {
|
68
|
-
"chromedriver": "*"
|
70
|
+
"chromedriver": "*",
|
71
|
+
"typescript": "^4.9.4"
|
72
|
+
},
|
73
|
+
"peerDependenciesMeta": {
|
74
|
+
"typescript": {
|
75
|
+
"optional": true
|
76
|
+
}
|
69
77
|
},
|
70
78
|
"devDependencies": {
|
71
79
|
"yargs": "^17.5.1"
|