@ui5/webcomponents-tools 0.0.0-ec448881d → 0.0.0-ee3bbe46b
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 +86 -0
- package/README.md +5 -6
- package/bin/dev.js +1 -5
- package/components-package/eslint.js +28 -0
- package/components-package/nps.js +71 -42
- package/components-package/vite.config.js +12 -0
- package/components-package/wdio.js +28 -4
- package/components-package/wdio.sync.js +1 -1
- package/icons-collection/nps.js +2 -1
- package/lib/copy-list/index.js +2 -2
- package/lib/create-icons/index.js +21 -2
- package/lib/create-new-component/index.js +5 -5
- package/lib/dev-server/dev-server.js +66 -0
- package/lib/dev-server/virtual-index-html-plugin.js +53 -0
- package/lib/generate-custom-elements-manifest/index.js +373 -0
- package/lib/generate-js-imports/illustrations.js +72 -0
- package/lib/generate-json-imports/themes.js +3 -3
- package/lib/hbs2lit/src/compiler.js +8 -0
- package/lib/hbs2lit/src/litVisitor2.js +46 -8
- package/lib/i18n/defaults.js +9 -0
- package/lib/jsdoc/configTypescript.json +29 -0
- package/lib/jsdoc/plugin.js +32 -0
- package/lib/jsdoc/preprocess.js +147 -0
- package/lib/jsdoc/template/publish.js +9 -1
- package/lib/postcss-css-to-esm/index.js +13 -1
- package/lib/postcss-css-to-json/index.js +12 -1
- package/lib/postcss-p/postcss-p.mjs +3 -0
- package/lib/scoping/get-all-tags.js +1 -8
- package/lib/scoping/scope-test-pages.js +1 -1
- package/lib/test-runner/test-runner.js +63 -0
- package/package.json +15 -16
- package/components-package/rollup-plugins/empty-module.js +0 -15
- package/components-package/rollup.js +0 -150
- package/lib/documentation/index.js +0 -168
- package/lib/documentation/templates/api-component-since.js +0 -3
- package/lib/documentation/templates/api-css-variables-section.js +0 -24
- package/lib/documentation/templates/api-events-section.js +0 -35
- package/lib/documentation/templates/api-methods-section.js +0 -26
- package/lib/documentation/templates/api-properties-section.js +0 -42
- package/lib/documentation/templates/api-slots-section.js +0 -28
- package/lib/documentation/templates/template.js +0 -39
- package/lib/serve/index.js +0 -46
- package/lib/serve/serve.json +0 -3
- package/package-lock.json +0 -48
package/lib/jsdoc/plugin.js
CHANGED
@@ -34,6 +34,10 @@
|
|
34
34
|
* native
|
35
35
|
*
|
36
36
|
* noattribute
|
37
|
+
*
|
38
|
+
* formEvents
|
39
|
+
*
|
40
|
+
* formProperty
|
37
41
|
*
|
38
42
|
* allowPreventDefault
|
39
43
|
*
|
@@ -2108,6 +2112,34 @@ exports.defineTags = function(dictionary) {
|
|
2108
2112
|
doclet.noattribute = true;
|
2109
2113
|
}
|
2110
2114
|
});
|
2115
|
+
|
2116
|
+
dictionary.defineTag('formEvents', {
|
2117
|
+
mustHaveValue: false,
|
2118
|
+
onTagged: function(doclet, tag) {
|
2119
|
+
if (tag.value) {
|
2120
|
+
doclet.formEvents = doclet.formEvents || [];
|
2121
|
+
tag.value.split(" ").forEach(function($) {
|
2122
|
+
if ( doclet.formEvents.indexOf($) < 0 ) {
|
2123
|
+
doclet.formEvents.push($);
|
2124
|
+
}
|
2125
|
+
});
|
2126
|
+
}
|
2127
|
+
}
|
2128
|
+
});
|
2129
|
+
|
2130
|
+
dictionary.defineTag('formProperty', {
|
2131
|
+
mustHaveValue: false,
|
2132
|
+
onTagged: function(doclet, tag) {
|
2133
|
+
doclet.formProperty = true;
|
2134
|
+
}
|
2135
|
+
});
|
2136
|
+
|
2137
|
+
dictionary.defineTag('formAssociated', {
|
2138
|
+
mustHaveValue: false,
|
2139
|
+
onTagged: function(doclet, tag) {
|
2140
|
+
doclet.formAssociated = doclet.formAssociated || true;
|
2141
|
+
}
|
2142
|
+
});
|
2111
2143
|
};
|
2112
2144
|
|
2113
2145
|
exports.handlers = {
|
@@ -0,0 +1,147 @@
|
|
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 + "**/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 + "/*.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, fileContent) => {
|
79
|
+
const index = fileContent.indexOf(comment);
|
80
|
+
return fileContent.substr(index + comment.length).trim().charAt(0) === "@";
|
81
|
+
}
|
82
|
+
|
83
|
+
const processComponentFile = async (fileName) => {
|
84
|
+
// source file (src/*.ts)
|
85
|
+
let tsFileContent = `${await fs.readFile(fileName)}`;
|
86
|
+
|
87
|
+
// Skip all non-component files
|
88
|
+
if (!isClass(tsFileContent)) {
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
|
92
|
+
// Gather all JSDocs from the original .ts file
|
93
|
+
const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
|
94
|
+
let allJSDocs = [...tsFileContent.matchAll(allJSDocsRegExp)];
|
95
|
+
allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
|
96
|
+
|
97
|
+
// Find where the class is defined in the original file
|
98
|
+
const tsClassDefinitionRegExp = new RegExp(`^class [\\w\\d_]+`, "gm");
|
99
|
+
let tsClassDefinitionMatch = tsFileContent.match(tsClassDefinitionRegExp);
|
100
|
+
if (!tsClassDefinitionMatch) {
|
101
|
+
return; // no class defined in this .ts file
|
102
|
+
}
|
103
|
+
const tsClassDefinition = tsClassDefinitionMatch[0];
|
104
|
+
const tsClassDefinitionIndex = tsFileContent.indexOf(tsClassDefinition);
|
105
|
+
|
106
|
+
// Gather all JSDocs that are before the class definition (except for the @class one)
|
107
|
+
const JSDocsToAppend = [];
|
108
|
+
allJSDocs.forEach(JSDoc => {
|
109
|
+
if (!isClass(JSDoc) && (tsFileContent.indexOf(JSDoc) < tsClassDefinitionIndex || isAnnotationComment(JSDoc, tsFileContent))) {
|
110
|
+
JSDocsToAppend.push(JSDoc);
|
111
|
+
}
|
112
|
+
});
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
// destination file (jsdoc-dist/*.js)
|
117
|
+
const destFileName = fileName.replace(sourceDir, inputDir).replace(/\.ts$/, ".js");
|
118
|
+
let jsFileContent = `${await fs.readFile(destFileName)}`;
|
119
|
+
|
120
|
+
const classDefinitionRegExp = new RegExp(`let.*? = class`, "gm");
|
121
|
+
let classDefinitionMatch = jsFileContent.match(classDefinitionRegExp);
|
122
|
+
if (!classDefinitionMatch) {
|
123
|
+
return; // not a file, generated by typescript, nothing to do here
|
124
|
+
}
|
125
|
+
|
126
|
+
const classDefinition = classDefinitionMatch[0];
|
127
|
+
const classDefinitionIndex = jsFileContent.indexOf(classDefinition); // classDefinitionIndex is the position in the file where the class is defined
|
128
|
+
|
129
|
+
// All comments before the class definition, except for the @class comment, must be removed
|
130
|
+
allJSDocs.forEach(JSDoc => {
|
131
|
+
if (!isClass(JSDoc) && jsFileContent.indexOf(JSDoc) < classDefinitionIndex) {
|
132
|
+
jsFileContent = jsFileContent.replace(JSDoc, "");
|
133
|
+
}
|
134
|
+
});
|
135
|
+
|
136
|
+
// Put all other comments at the end of the file
|
137
|
+
jsFileContent = jsFileContent + "\n\n" + JSDocsToAppend.join("\n\n");
|
138
|
+
return fs.writeFile(destFileName, jsFileContent);
|
139
|
+
};
|
140
|
+
|
141
|
+
Promise.all([
|
142
|
+
preprocessTypes(),
|
143
|
+
preprocessComponents(),
|
144
|
+
]).then(() => {
|
145
|
+
console.log("JSDoc preprocess ready.");
|
146
|
+
});
|
147
|
+
|
@@ -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
|
|
@@ -38,7 +38,19 @@ module.exports = function (opts) {
|
|
38
38
|
|
39
39
|
const filePath = `${targetFile}.js`;
|
40
40
|
const defaultTheme = opts.includeDefaultTheme ? getDefaultThemeCode(opts.packageName) : ``;
|
41
|
-
|
41
|
+
|
42
|
+
// it seems slower to read the old content, but writing the same content with no real changes
|
43
|
+
// (as in initial build and then watch mode) will cause an unnecessary dev server refresh
|
44
|
+
let oldContent = "";
|
45
|
+
try {
|
46
|
+
oldContent = fs.readFileSync(filePath).toString();
|
47
|
+
} catch (e) {
|
48
|
+
// file not found
|
49
|
+
}
|
50
|
+
const content = `${defaultTheme}export default {packageName:"${opts.packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
|
51
|
+
if (content !== oldContent) {
|
52
|
+
fs.writeFileSync(filePath, content);
|
53
|
+
}
|
42
54
|
}
|
43
55
|
};
|
44
56
|
};
|
@@ -28,7 +28,18 @@ module.exports = function (opts) {
|
|
28
28
|
fileName: targetFile.substr(targetFile.lastIndexOf("themes")),
|
29
29
|
content: css
|
30
30
|
};
|
31
|
-
|
31
|
+
// it seems slower to read the old content, but writing the same content with no real changes
|
32
|
+
// (as in initial build and then watch mode) will cause an unnecessary dev server refresh
|
33
|
+
let oldContent = "";
|
34
|
+
try {
|
35
|
+
oldContent = fs.readFileSync(filePath).toString();
|
36
|
+
} catch (e) {
|
37
|
+
// file not found
|
38
|
+
}
|
39
|
+
const content = JSON.stringify({_: data});
|
40
|
+
if (content !== oldContent) {
|
41
|
+
fs.writeFileSync(filePath, content);
|
42
|
+
}
|
32
43
|
}
|
33
44
|
};
|
34
45
|
};
|
@@ -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
|
|
@@ -27,7 +27,7 @@ const replaceTagsAny = content => {
|
|
27
27
|
// Replace bundle names and HTML tag names in test pages
|
28
28
|
glob.sync(path.join(root, "/**/*.html")).forEach(file => {
|
29
29
|
let content = String(fs.readFileSync(file));
|
30
|
-
content = content.replace(/bundle\.(.*?)\.js/g,
|
30
|
+
content = content.replace(/bundle\.(.*?)\.js/g, `../bundle.scoped.$1.js`);
|
31
31
|
content = replaceTagsHTML(content);
|
32
32
|
fs.writeFileSync(file, content);
|
33
33
|
});
|
@@ -0,0 +1,63 @@
|
|
1
|
+
const child_process = require("child_process");
|
2
|
+
const { readFileSync } = require("fs");
|
3
|
+
const path = require("path");
|
4
|
+
|
5
|
+
// search for dev-server port
|
6
|
+
// start in current folder
|
7
|
+
// traversing upwards in case of mono repo tests and dev-server running in root folder of repository
|
8
|
+
let devServerFolder = process.cwd();
|
9
|
+
let devServerPort;
|
10
|
+
while (true) {
|
11
|
+
try {
|
12
|
+
devServerPort = readFileSync(path.join(devServerFolder, ".dev-server-port")).toString();
|
13
|
+
break; // found
|
14
|
+
} catch (e) {
|
15
|
+
// file not found
|
16
|
+
if (devServerFolder === path.dirname(devServerFolder)) {
|
17
|
+
break; // reached root folder "/"
|
18
|
+
}
|
19
|
+
devServerFolder = path.dirname(devServerFolder);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
// check if we are in a monorepo and extract path from package.json
|
24
|
+
let packageRepositoryPath = "";
|
25
|
+
const pkg = require(path.join(process.cwd(), "package.json"));
|
26
|
+
packageRepositoryPath = pkg.repository.directory;
|
27
|
+
|
28
|
+
// construct base url
|
29
|
+
// use devServerPort if a dev server is running, otherwise let the baseUrl in the wdio config be used
|
30
|
+
// if a dev server is running in the root of a mono repo, append tha package path like this
|
31
|
+
// http://localhost:${devServerPort}/packages/main/
|
32
|
+
let baseUrl = "";
|
33
|
+
if (devServerPort) {
|
34
|
+
console.log(`Found port ${devServerPort} from '${path.join(devServerFolder, ".dev-server-port")}'`);
|
35
|
+
const devServerInRoot = !devServerFolder.includes(packageRepositoryPath);
|
36
|
+
if (devServerInRoot) {
|
37
|
+
baseUrl = `--base-url http://localhost:${devServerPort}/${packageRepositoryPath}/`;
|
38
|
+
} else {
|
39
|
+
baseUrl = `--base-url http://localhost:${devServerPort}/`;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
if (!baseUrl) {
|
44
|
+
console.log("No dev server running, running tests served from `dist`, make sure it is up to date");
|
45
|
+
}
|
46
|
+
|
47
|
+
// add single spec parameter if passed
|
48
|
+
let spec = "";
|
49
|
+
if (process.argv.length === 3) {
|
50
|
+
const specFile = process.argv[2];
|
51
|
+
spec = `--spec ${specFile}`;
|
52
|
+
}
|
53
|
+
|
54
|
+
// more parameters - pass them to wdio
|
55
|
+
let restParams = "";
|
56
|
+
if (process.argv.length > 3) {
|
57
|
+
restParams = process.argv.slice(2).join(" ");
|
58
|
+
}
|
59
|
+
|
60
|
+
// run wdio with calculated parameters
|
61
|
+
const cmd = `yarn cross-env WDIO_LOG_LEVEL=error wdio config/wdio.conf.js ${spec} ${baseUrl} ${restParams}`;
|
62
|
+
console.log(`executing: ${cmd}`);
|
63
|
+
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-ee3bbe46b",
|
4
4
|
"description": "UI5 Web Components: webcomponents.tools",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -21,20 +21,19 @@
|
|
21
21
|
"directory": "packages/tools"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
|
-
"@
|
25
|
-
"@
|
26
|
-
"@
|
27
|
-
"@wdio/
|
28
|
-
"@wdio/
|
29
|
-
"@wdio/
|
30
|
-
"@wdio/
|
31
|
-
"@wdio/
|
32
|
-
"@wdio/
|
24
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
25
|
+
"@typescript-eslint/parser": "^5.42.1",
|
26
|
+
"@wdio/cli": "^7.19.7",
|
27
|
+
"@wdio/devtools-service": "^7.19.7",
|
28
|
+
"@wdio/dot-reporter": "^7.19.7",
|
29
|
+
"@wdio/local-runner": "^7.19.7",
|
30
|
+
"@wdio/mocha-framework": "^7.19.7",
|
31
|
+
"@wdio/spec-reporter": "^7.19.7",
|
32
|
+
"@wdio/static-server-service": "^7.19.5",
|
33
33
|
"chai": "^4.3.4",
|
34
34
|
"child_process": "^1.0.2",
|
35
35
|
"chokidar": "^3.5.1",
|
36
36
|
"chokidar-cli": "^3.0.0",
|
37
|
-
"cli-color": "^2.0.1",
|
38
37
|
"command-line-args": "^5.1.1",
|
39
38
|
"concurrently": "^6.0.0",
|
40
39
|
"cross-env": "^7.0.3",
|
@@ -62,15 +61,15 @@
|
|
62
61
|
"recursive-readdir": "^2.2.2",
|
63
62
|
"resolve": "^1.20.0",
|
64
63
|
"rimraf": "^3.0.2",
|
65
|
-
"rollup": "^2.41.4",
|
66
|
-
"rollup-plugin-livereload": "^2.0.0",
|
67
|
-
"rollup-plugin-terser": "^7.0.2",
|
68
|
-
"serve": "^12.0.0",
|
69
64
|
"slash": "3.0.0",
|
70
|
-
"
|
65
|
+
"vite": "^2.9.12",
|
66
|
+
"wdio-chromedriver-service": "^7.3.2",
|
71
67
|
"zx": "^4.3.0"
|
72
68
|
},
|
73
69
|
"peerDependencies": {
|
74
70
|
"chromedriver": "*"
|
71
|
+
},
|
72
|
+
"devDependencies": {
|
73
|
+
"yargs": "^17.5.1"
|
75
74
|
}
|
76
75
|
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
const slash = require("slash");
|
2
|
-
|
3
|
-
function emptyModulePlugin({ emptyModules }) {
|
4
|
-
return {
|
5
|
-
name: "ui5-dev-empty-module-plugin",
|
6
|
-
load(id) {
|
7
|
-
if (emptyModules.some(mod => slash(id).includes(mod))) {
|
8
|
-
return `export default ""`;
|
9
|
-
}
|
10
|
-
return null;
|
11
|
-
},
|
12
|
-
};
|
13
|
-
}
|
14
|
-
|
15
|
-
module.exports = emptyModulePlugin;
|
@@ -1,150 +0,0 @@
|
|
1
|
-
const process = require("process");
|
2
|
-
const fs = require("fs");
|
3
|
-
const os = require("os");
|
4
|
-
const { nodeResolve } = require("@rollup/plugin-node-resolve");
|
5
|
-
const { terser } = require("rollup-plugin-terser");
|
6
|
-
const json = require("@rollup/plugin-json");
|
7
|
-
const replace = require("@rollup/plugin-replace");
|
8
|
-
const colors = require("cli-color");
|
9
|
-
const livereload = require("rollup-plugin-livereload");
|
10
|
-
const emptyModulePlugin = require("./rollup-plugins/empty-module.js");
|
11
|
-
|
12
|
-
const packageFile = JSON.parse(fs.readFileSync("./package.json"));
|
13
|
-
const packageName = packageFile.name;
|
14
|
-
|
15
|
-
const warningsToSkip = [{
|
16
|
-
warningCode: "THIS_IS_UNDEFINED",
|
17
|
-
filePath: /.+zxing.+/,
|
18
|
-
}];
|
19
|
-
|
20
|
-
function ui5DevImportCheckerPlugin() {
|
21
|
-
return {
|
22
|
-
name: "ui5-dev-import-checker-plugin",
|
23
|
-
transform(code, file) {
|
24
|
-
const re = new RegExp(`^import.*"${packageName}/`);
|
25
|
-
if (re.test(code)) {
|
26
|
-
throw new Error(`illegal import in ${file}`);
|
27
|
-
}
|
28
|
-
},
|
29
|
-
};
|
30
|
-
}
|
31
|
-
|
32
|
-
function onwarn(warning, warn) {
|
33
|
-
// Skip warning for known false positives that will otherwise polute the log
|
34
|
-
let skip = warningsToSkip.find(warningToSkip => {
|
35
|
-
let loc, file;
|
36
|
-
return warning.code === warningToSkip.warningCode
|
37
|
-
&& (loc = warning.loc)
|
38
|
-
&& (file = loc.file)
|
39
|
-
&& file.match(warningToSkip.filePath);
|
40
|
-
});
|
41
|
-
if (skip) {
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
|
45
|
-
// warn everything else
|
46
|
-
warn( warning );
|
47
|
-
}
|
48
|
-
|
49
|
-
const reportedForPackages = new Set(); // sometimes writeBundle is called more than once per bundle -> suppress extra messages
|
50
|
-
function ui5DevReadyMessagePlugin() {
|
51
|
-
return {
|
52
|
-
name: "ui5-dev-message-ready-plugin",
|
53
|
-
writeBundle: (assets, bundle) => {
|
54
|
-
if (reportedForPackages.has(packageName)) {
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
console.log(colors.blue(`${colors.bold(packageName)} successfully built!`));
|
58
|
-
|
59
|
-
if (fs.existsSync(".port")) {
|
60
|
-
const port = `${fs.readFileSync(".port")}`;
|
61
|
-
if (port) {
|
62
|
-
console.log(colors.blue(`Navigate to: ${colors.bold(`http://localhost:${port}/test-resources/pages/`)}`));
|
63
|
-
}
|
64
|
-
}
|
65
|
-
reportedForPackages.add(packageName);
|
66
|
-
},
|
67
|
-
};
|
68
|
-
}
|
69
|
-
|
70
|
-
const getPlugins = () => {
|
71
|
-
const plugins = [];
|
72
|
-
|
73
|
-
if (process.env.DEV) {
|
74
|
-
plugins.push(replace({
|
75
|
-
values: {
|
76
|
-
'const DEV_MODE = false': 'const DEV_MODE = true',
|
77
|
-
},
|
78
|
-
preventAssignment: false,
|
79
|
-
}));
|
80
|
-
}
|
81
|
-
|
82
|
-
if (process.env.DEV && !process.env.ENABLE_CLDR) {
|
83
|
-
// Empty the CLDR assets file for better performance during development
|
84
|
-
plugins.push(emptyModulePlugin({
|
85
|
-
emptyModules: [
|
86
|
-
"localization/dist/Assets.js",
|
87
|
-
],
|
88
|
-
}));
|
89
|
-
}
|
90
|
-
|
91
|
-
plugins.push(ui5DevImportCheckerPlugin());
|
92
|
-
|
93
|
-
plugins.push(json({
|
94
|
-
include: [
|
95
|
-
/.*assets\/.*\.json/,
|
96
|
-
],
|
97
|
-
namedExports: false,
|
98
|
-
}));
|
99
|
-
|
100
|
-
plugins.push(nodeResolve());
|
101
|
-
|
102
|
-
if (!process.env.DEV) {
|
103
|
-
plugins.push(terser({
|
104
|
-
numWorkers: 1,
|
105
|
-
}));
|
106
|
-
}
|
107
|
-
|
108
|
-
const es6DevMain = process.env.DEV && packageName === "@ui5/webcomponents";
|
109
|
-
if (es6DevMain && os.platform() !== "win32") {
|
110
|
-
plugins.push(livereload({
|
111
|
-
watch: [
|
112
|
-
"dist/resources/bundle.esm.js",
|
113
|
-
"dist/**/*.html",
|
114
|
-
"dist/**/*.json",
|
115
|
-
],
|
116
|
-
}));
|
117
|
-
}
|
118
|
-
|
119
|
-
if (process.env.DEV) {
|
120
|
-
plugins.push(ui5DevReadyMessagePlugin());
|
121
|
-
}
|
122
|
-
|
123
|
-
return plugins;
|
124
|
-
};
|
125
|
-
|
126
|
-
const getES6Config = (input = "bundle.esm.js") => {
|
127
|
-
return [{
|
128
|
-
input,
|
129
|
-
output: {
|
130
|
-
dir: "dist/resources",
|
131
|
-
format: "esm",
|
132
|
-
sourcemap: true,
|
133
|
-
},
|
134
|
-
watch: {
|
135
|
-
clearScreen: false,
|
136
|
-
},
|
137
|
-
plugins: getPlugins(),
|
138
|
-
onwarn: onwarn,
|
139
|
-
}];
|
140
|
-
};
|
141
|
-
|
142
|
-
let config = getES6Config();
|
143
|
-
|
144
|
-
if (process.env.SCOPE) {
|
145
|
-
if (fs.existsSync("bundle.scoped.esm.js")) {
|
146
|
-
config = config.concat(getES6Config("bundle.scoped.esm.js"));
|
147
|
-
}
|
148
|
-
}
|
149
|
-
|
150
|
-
module.exports = config;
|