@ui5/webcomponents-tools 0.0.0-c41f1b293 → 0.0.0-c48b38fdc
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 +531 -0
- package/README.md +2 -1
- package/assets-meta.js +15 -7
- package/components-package/eslint.js +2 -0
- package/components-package/nps.js +41 -32
- package/components-package/postcss.components.js +1 -21
- package/components-package/postcss.themes.js +1 -36
- package/components-package/vite.config.js +0 -3
- package/components-package/wdio.js +6 -2
- package/icons-collection/nps.js +6 -4
- package/lib/amd-to-es6/index.js +102 -0
- package/lib/amd-to-es6/no-remaining-require.js +33 -0
- package/lib/cem/custom-elements-manifest.config.mjs +501 -0
- package/lib/cem/event.mjs +131 -0
- package/lib/cem/schema-internal.json +1357 -0
- package/lib/cem/schema.json +1098 -0
- package/lib/cem/types-internal.d.ts +796 -0
- package/lib/cem/types.d.ts +736 -0
- package/lib/cem/utils.mjs +384 -0
- package/lib/cem/validate.js +70 -0
- package/lib/create-illustrations/index.js +51 -30
- package/lib/create-new-component/index.js +1 -1
- package/lib/create-new-component/jsFileContentTemplate.js +1 -1
- package/lib/create-new-component/tsFileContentTemplate.js +3 -12
- package/lib/css-processors/css-processor-component-styles.mjs +47 -0
- package/lib/css-processors/css-processor-components.mjs +77 -0
- package/lib/css-processors/css-processor-themes.mjs +79 -0
- package/lib/css-processors/scope-variables.mjs +49 -0
- package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
- package/lib/dev-server/custom-hot-update-plugin.js +39 -0
- package/lib/generate-custom-elements-manifest/index.js +51 -107
- package/lib/generate-js-imports/illustrations.js +78 -64
- package/lib/generate-json-imports/i18n.js +10 -5
- package/lib/generate-json-imports/themes.js +10 -5
- package/lib/jsdoc/preprocess.js +1 -1
- package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
- package/lib/scoping/get-all-tags.js +1 -1
- package/lib/scoping/scope-test-pages.js +2 -1
- package/package.json +12 -11
- package/lib/esm-abs-to-rel/index.js +0 -58
- package/lib/postcss-css-to-json/index.js +0 -47
- package/lib/postcss-new-files/index.js +0 -36
- package/lib/postcss-p/postcss-p.mjs +0 -14
- package/lib/replace-global-core/index.js +0 -25
@@ -8,17 +8,20 @@ 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
|
-
const 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} ${illustration.collection}`);
|
12
12
|
const createIllustrationsJSImportsScript = illustrations.join(" && ");
|
13
13
|
|
14
|
-
// The script creates the "
|
15
|
-
|
16
|
-
|
14
|
+
// The script creates the "src/generated/js-imports/Illustration.js" file that registers loaders (dynamic JS imports) for each illustration
|
15
|
+
const createIllustrationsLoadersScript = illustrationsData.map(illustrations => `node ${LIB}/generate-js-imports/illustrations.js ${illustrations.destinationPath} ${illustrations.dynamicImports.outputFile} ${illustrations.set} ${illustrations.collection} ${illustrations.dynamicImports.location} ${illustrations.dynamicImports.filterOut.join(" ")}`).join(" && ");
|
16
|
+
|
17
17
|
const tsOption = options.typescript;
|
18
|
-
const
|
19
|
-
|
18
|
+
const tsCommandOld = tsOption ? "tsc" : "";
|
19
|
+
let tsWatchCommandStandalone = tsOption ? "tsc --watch" : "";
|
20
|
+
// this command is only used for standalone projects. monorepo projects get their watch from vite, so opt-out here
|
21
|
+
if (options.noWatchTS) {
|
22
|
+
tsWatchCommandStandalone = "";
|
23
|
+
}
|
20
24
|
const tsCrossEnv = tsOption ? "cross-env UI5_TS=true" : "";
|
21
|
-
const copySrcGenerated = tsOption ? "" : "copy.srcGenerated";
|
22
25
|
|
23
26
|
if (tsOption) {
|
24
27
|
try {
|
@@ -54,19 +57,25 @@ const getScripts = (options) => {
|
|
54
57
|
clean: 'rimraf jsdoc-dist && rimraf src/generated && rimraf dist && rimraf .port && nps "scope.testPages.clean"',
|
55
58
|
lint: `eslint . ${eslintConfig}`,
|
56
59
|
lintfix: `eslint . ${eslintConfig} --fix`,
|
57
|
-
|
58
|
-
default: `${tsCrossEnv} nps
|
60
|
+
generate: {
|
61
|
+
default: `${tsCrossEnv} nps prepare.all`,
|
59
62
|
all: 'concurrently "nps build.templates" "nps build.i18n" "nps prepare.styleRelated" "nps copy" "nps build.illustrations"',
|
60
63
|
styleRelated: "nps build.styles build.jsonImports build.jsImports",
|
61
64
|
},
|
62
|
-
|
65
|
+
prepare: {
|
66
|
+
default: `${tsCrossEnv} nps clean prepare.all copy prepare.typescript generateAPI`,
|
67
|
+
all: 'concurrently "nps build.templates" "nps build.i18n" "nps prepare.styleRelated" "nps build.illustrations"',
|
68
|
+
styleRelated: "nps build.styles build.jsonImports build.jsImports",
|
69
|
+
typescript: tsCommandOld,
|
70
|
+
},
|
63
71
|
build: {
|
64
|
-
default: "nps prepare lint build.bundle",
|
65
|
-
templates: `mkdirp
|
72
|
+
default: "nps prepare lint build.bundle", // build.bundle2
|
73
|
+
templates: `mkdirp src/generated/templates && ${tsCrossEnv} node "${LIB}/hbs2ui5/index.js" -d src/ -o src/generated/templates`,
|
66
74
|
styles: {
|
67
|
-
default: `nps build.styles.themes build.styles.components
|
68
|
-
themes: `node "${LIB}/
|
69
|
-
components: "
|
75
|
+
default: `concurrently "nps build.styles.themes" "nps build.styles.components" "nps build.styles.componentStyles"`,
|
76
|
+
themes: `node "${LIB}/css-processors/css-processor-themes.mjs"`,
|
77
|
+
components: `node "${LIB}/css-processors/css-processor-components.mjs"`,
|
78
|
+
componentStyles: `node "${LIB}/css-processors/css-processor-component-styles.mjs"`,
|
70
79
|
},
|
71
80
|
i18n: {
|
72
81
|
default: "nps build.i18n.defaultsjs build.i18n.json",
|
@@ -74,38 +83,36 @@ const getScripts = (options) => {
|
|
74
83
|
json: `node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
|
75
84
|
},
|
76
85
|
jsonImports: {
|
77
|
-
default: "mkdirp
|
78
|
-
themes: `node "${LIB}/generate-json-imports/themes.js" dist/generated/assets/themes
|
79
|
-
i18n: `node "${LIB}/generate-json-imports/i18n.js" dist/generated/assets/i18n
|
86
|
+
default: "mkdirp src/generated/json-imports && nps build.jsonImports.themes build.jsonImports.i18n",
|
87
|
+
themes: `node "${LIB}/generate-json-imports/themes.js" dist/generated/assets/themes src/generated/json-imports`,
|
88
|
+
i18n: `node "${LIB}/generate-json-imports/i18n.js" dist/generated/assets/i18n src/generated/json-imports`,
|
80
89
|
},
|
81
90
|
jsImports: {
|
82
|
-
default: "mkdirp
|
91
|
+
default: "mkdirp src/generated/js-imports && nps build.jsImports.illustrationsLoaders",
|
83
92
|
illustrationsLoaders: createIllustrationsLoadersScript,
|
84
93
|
},
|
85
94
|
bundle: `vite build ${viteConfig}`,
|
95
|
+
bundle2: ``,
|
86
96
|
illustrations: createIllustrationsJSImportsScript,
|
87
97
|
},
|
88
98
|
copy: {
|
89
99
|
default: "nps copy.src copy.props",
|
90
|
-
src: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
|
91
|
-
|
100
|
+
src: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.{js,json}" dist/`,
|
101
|
+
// srcGenerated2: `node "${LIB}/copy-and-watch/index.js" --silent "src/generated/**/*.{js,json}" dist/generated/`,
|
92
102
|
props: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.properties" dist/`,
|
93
103
|
},
|
94
104
|
watch: {
|
95
|
-
default: `${tsCrossEnv} concurrently "nps watch.templates" "nps watch.
|
105
|
+
default: `${tsCrossEnv} concurrently "nps watch.templates" "nps watch.typescript" "nps watch.api" "nps watch.src" "nps watch.styles" "nps watch.i18n" "nps watch.props"`,
|
96
106
|
devServer: 'concurrently "nps watch.default" "nps watch.bundle"',
|
97
107
|
src: 'nps "copy.src --watch --safe --skip-initial-copy"',
|
98
|
-
typescript:
|
108
|
+
typescript: tsWatchCommandStandalone,
|
99
109
|
props: 'nps "copy.props --watch --safe --skip-initial-copy"',
|
100
110
|
bundle: `node ${LIB}/dev-server/dev-server.js ${viteConfig}`,
|
101
111
|
styles: {
|
102
|
-
default: 'concurrently "nps watch.styles.themes" "nps watch.styles.components"',
|
112
|
+
default: 'concurrently "nps watch.styles.themes" "nps watch.styles.components" "nps watch.styles.componentStyles" ',
|
103
113
|
themes: 'nps "build.styles.themes -w"',
|
104
|
-
components:
|
105
|
-
|
106
|
-
existingFiles: `nps "build.styles.components -w"`,
|
107
|
-
newFiles: `node "${LIB}/postcss-new-files/index.js" --srcFiles="src/themes/*.css"`,
|
108
|
-
},
|
114
|
+
components: `nps "build.styles.components -w"`,
|
115
|
+
componentStyles: `nps "build.styles.componentStyles -w"`,
|
109
116
|
},
|
110
117
|
templates: 'chokidar "src/**/*.hbs" -c "nps build.templates"',
|
111
118
|
api: 'chokidar "test/**/*.sample.html" -c "nps generateAPI"',
|
@@ -117,7 +124,7 @@ const getScripts = (options) => {
|
|
117
124
|
"test-suite-2": `node "${LIB}/test-runner/test-runner.js" --suite suite2`,
|
118
125
|
startWithScope: "nps scope.prepare scope.watchWithBundle",
|
119
126
|
scope: {
|
120
|
-
prepare: "nps scope.lint
|
127
|
+
prepare: "nps scope.lint scope.testPages",
|
121
128
|
lint: `node "${LIB}/scoping/lint-src.js"`,
|
122
129
|
testPages: {
|
123
130
|
default: "nps scope.testPages.clean scope.testPages.copy scope.testPages.replace",
|
@@ -130,11 +137,13 @@ const getScripts = (options) => {
|
|
130
137
|
bundle: `node ${LIB}/dev-server/dev-server.js ${viteConfig}`,
|
131
138
|
},
|
132
139
|
generateAPI: {
|
133
|
-
default:
|
140
|
+
default: `nps ${ tsOption ? "generateAPI.generateCEM generateAPI.validateCEM" : "generateAPI.prepare generateAPI.preprocess generateAPI.jsdoc generateAPI.cleanup generateAPI.prepareManifest generateAPI.validateCEM"}`,
|
141
|
+
generateCEM: `cem analyze --config "${LIB}/cem/custom-elements-manifest.config.mjs" ${ options.dev ? "--dev" : "" }`,
|
142
|
+
validateCEM: `node "${LIB}/cem/validate.js" ${ options.dev ? "--dev" : "" }`,
|
134
143
|
prepare: `node "${LIB}/copy-and-watch/index.js" --silent "dist/**/*.js" jsdoc-dist/`,
|
135
144
|
prepareManifest: `node "${LIB}/generate-custom-elements-manifest/index.js" dist dist`,
|
136
145
|
preprocess: `node "${preprocessJSDocScript}" jsdoc-dist/ src`,
|
137
|
-
jsdoc: `jsdoc -c "${LIB}/jsdoc/
|
146
|
+
jsdoc: `jsdoc -c "${LIB}/jsdoc/config.json"`,
|
138
147
|
cleanup: "rimraf jsdoc-dist/"
|
139
148
|
},
|
140
149
|
};
|
@@ -1,21 +1 @@
|
|
1
|
-
|
2
|
-
const postcssCSStoESM = require('../lib/postcss-css-to-esm/index.js');
|
3
|
-
const cssnano = require('cssnano');
|
4
|
-
const fs = require("fs");
|
5
|
-
|
6
|
-
const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
|
7
|
-
|
8
|
-
module.exports = {
|
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
|
-
}
|
1
|
+
module.exports = {}
|
@@ -1,36 +1 @@
|
|
1
|
-
|
2
|
-
const combineSelectors = require('../lib/postcss-combine-duplicated-selectors/index.js');
|
3
|
-
const postcssCSStoJSON = require('../lib/postcss-css-to-json/index.js');
|
4
|
-
const postcssCSStoESM = require('../lib/postcss-css-to-esm/index.js');
|
5
|
-
const cssnano = require('cssnano');
|
6
|
-
const modifySelectors = require("modify-selectors");
|
7
|
-
const fs = require("fs");
|
8
|
-
|
9
|
-
const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
|
10
|
-
|
11
|
-
module.exports = {
|
12
|
-
plugins: [
|
13
|
-
postcssImport(),
|
14
|
-
combineSelectors({
|
15
|
-
removeDuplicatedProperties: true
|
16
|
-
}),
|
17
|
-
cssnano({
|
18
|
-
preset: [
|
19
|
-
'default', {
|
20
|
-
mergeLonghand: false, // https://github.com/cssnano/cssnano/issues/675
|
21
|
-
},
|
22
|
-
]
|
23
|
-
},),
|
24
|
-
modifySelectors({
|
25
|
-
enable: true,
|
26
|
-
suffix: [
|
27
|
-
{
|
28
|
-
match: '*',
|
29
|
-
with: '[_ui5host]', // Add suffix to each selector in the file (:root => :root [_ui5host])
|
30
|
-
},
|
31
|
-
],
|
32
|
-
}),
|
33
|
-
postcssCSStoJSON({ toReplace: 'src', packageName }),
|
34
|
-
postcssCSStoESM({ toReplace: 'src', packageName }),
|
35
|
-
]
|
36
|
-
};
|
1
|
+
module.exports = {};
|
@@ -1,3 +1,5 @@
|
|
1
|
+
const dns = require("node:dns");
|
2
|
+
|
1
3
|
exports.config = {
|
2
4
|
//
|
3
5
|
// ====================
|
@@ -107,8 +109,7 @@ exports.config = {
|
|
107
109
|
// Services take over a specific job you don't want to take care of. They enhance
|
108
110
|
// your test setup with almost no effort. Unlike plugins, they don't add new
|
109
111
|
// commands. Instead, they hook themselves up into the test process.
|
110
|
-
services: ['chromedriver', '
|
111
|
-
['static-server', {
|
112
|
+
services: ['chromedriver', ['static-server', {
|
112
113
|
folders: [
|
113
114
|
{ mount: '/', path: './dist' },
|
114
115
|
],
|
@@ -161,6 +162,9 @@ exports.config = {
|
|
161
162
|
*/
|
162
163
|
// beforeSession: function (config, capabilities, specs) {
|
163
164
|
// },
|
165
|
+
beforeSession: () => {
|
166
|
+
dns.setDefaultResultOrder('ipv4first');
|
167
|
+
},
|
164
168
|
/**
|
165
169
|
* Gets executed before test execution begins. At this point you can access to all global
|
166
170
|
* variables like `browser`. It is the perfect place to define custom commands.
|
package/icons-collection/nps.js
CHANGED
@@ -41,22 +41,24 @@ 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" : "";
|
44
|
+
const tsCommand = options.typescript ? "tsc --build" : "";
|
45
45
|
const tsCrossEnv = options.typescript ? "cross-env UI5_TS=true" : "";
|
46
46
|
|
47
47
|
const scripts = {
|
48
48
|
clean: "rimraf dist && rimraf src/generated",
|
49
49
|
copy: copyAssetsCmd,
|
50
|
+
generate: `${tsCrossEnv} nps clean copy build.i18n build.icons build.jsonImports copyjson`,
|
51
|
+
copyjson: "copy-and-watch \"src/generated/**/*.json\" dist/generated/",
|
50
52
|
build: {
|
51
53
|
default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
|
52
54
|
i18n: {
|
53
55
|
default: "nps build.i18n.defaultsjs build.i18n.json",
|
54
56
|
defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
|
55
|
-
json: `mkdirp
|
57
|
+
json: `mkdirp src/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n src/generated/assets/i18n`,
|
56
58
|
},
|
57
59
|
jsonImports: {
|
58
|
-
default: "mkdirp
|
59
|
-
i18n: `node "${LIB}/generate-json-imports/i18n.js"
|
60
|
+
default: "mkdirp src/generated/json-imports && nps build.jsonImports.i18n",
|
61
|
+
i18n: `node "${LIB}/generate-json-imports/i18n.js" src/generated/assets/i18n src/generated/json-imports`,
|
60
62
|
},
|
61
63
|
icons: createJSImportsCmd,
|
62
64
|
},
|
@@ -0,0 +1,102 @@
|
|
1
|
+
const fs = require("fs").promises;
|
2
|
+
const path = require("path");
|
3
|
+
const basePath = process.argv[2];
|
4
|
+
const babelCore = require("@babel/core");
|
5
|
+
const babelParser = require("@babel/parser");
|
6
|
+
const babelGenerator = require("@babel/generator").default;
|
7
|
+
const replaceAsync = require('replace-in-file');
|
8
|
+
|
9
|
+
const convertSAPUIDefineToDefine = async (filePath) => {
|
10
|
+
return replaceAsync({
|
11
|
+
files: filePath,
|
12
|
+
processor: (input) => {
|
13
|
+
return input.replace("sap.ui.define", "define").replace(", /* bExport= */ false", "").replace(", /* bExport= */ true", "");
|
14
|
+
}
|
15
|
+
})
|
16
|
+
}
|
17
|
+
|
18
|
+
const convertAmdToEs6 = async (code) => {
|
19
|
+
return (await babelCore.transformAsync(code, {
|
20
|
+
plugins: [['babel-plugin-amd-to-esm', {}]]
|
21
|
+
})).code;
|
22
|
+
}
|
23
|
+
|
24
|
+
const convertAbsImportsToRelative = (filePath, code) => {
|
25
|
+
let changed = false;
|
26
|
+
// console.log("File processing started: ", srcPath);
|
27
|
+
|
28
|
+
if (code.includes("import(")) {
|
29
|
+
// esprima can't parse this, but it's from the project files
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
|
33
|
+
const tree = babelParser.parse(code, { sourceType: "module" });
|
34
|
+
const importer = filePath.replace(basePath, "");
|
35
|
+
const importerDir = path.dirname(importer);
|
36
|
+
// console.log("Importer -> ", importer);
|
37
|
+
|
38
|
+
tree?.program?.body?.forEach(node => {
|
39
|
+
if (node.type === "ImportDeclaration") {
|
40
|
+
let importee = node.source.value;
|
41
|
+
// console.log(importee);
|
42
|
+
if (importee.startsWith(".")) {
|
43
|
+
// add .js extension if missing
|
44
|
+
if (!importee.endsWith(".js")) {
|
45
|
+
node.source.value += ".js"
|
46
|
+
changed = true;
|
47
|
+
}
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
let importeeDir = path.dirname(importee);
|
51
|
+
let importeeFile = path.basename(importee);
|
52
|
+
let relativePath = path.relative(importerDir, importeeDir);
|
53
|
+
if (relativePath.length === 0) {
|
54
|
+
relativePath = "."
|
55
|
+
}
|
56
|
+
if (!relativePath.startsWith(".")) {
|
57
|
+
relativePath = "./" + relativePath;
|
58
|
+
}
|
59
|
+
|
60
|
+
relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
|
61
|
+
let relativeImport = `${relativePath}/${importeeFile}.js`;
|
62
|
+
// console.log(importee + " --> " + relativeImport);
|
63
|
+
node.source.value = relativeImport;
|
64
|
+
changed = true;
|
65
|
+
}
|
66
|
+
});
|
67
|
+
|
68
|
+
return changed ? babelGenerator(tree).code : code;
|
69
|
+
}
|
70
|
+
|
71
|
+
const replaceGlobalCoreUsage = (filePath, code) => {
|
72
|
+
if (!filePath.includes("Configuration")) {
|
73
|
+
const replaced = code.replace(/sap\.ui\.getCore\(\)/g, `Core`);
|
74
|
+
return code !== replaced ? `import Core from 'sap/ui/core/Core';${replaced}` : code;
|
75
|
+
}
|
76
|
+
|
77
|
+
return code;
|
78
|
+
};
|
79
|
+
|
80
|
+
const transformAmdToES6Module = async (filePath) => {
|
81
|
+
await convertSAPUIDefineToDefine(filePath);
|
82
|
+
|
83
|
+
let code = (await fs.readFile(filePath)).toString();
|
84
|
+
|
85
|
+
code = await convertAmdToEs6(code);
|
86
|
+
|
87
|
+
code = replaceGlobalCoreUsage(filePath, code);
|
88
|
+
|
89
|
+
code = convertAbsImportsToRelative(filePath, code);
|
90
|
+
|
91
|
+
return fs.writeFile(filePath, code);
|
92
|
+
}
|
93
|
+
|
94
|
+
const transformAmdToES6Modules = async () => {
|
95
|
+
const { globby } = await import("globby");
|
96
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
97
|
+
return Promise.all(fileNames.map(transformAmdToES6Module).filter(x => !!x));
|
98
|
+
};
|
99
|
+
|
100
|
+
transformAmdToES6Modules().then(() => {
|
101
|
+
console.log("Success: all amd modules are transformed to es6!");
|
102
|
+
});
|
@@ -0,0 +1,33 @@
|
|
1
|
+
const fs = require("fs").promises;
|
2
|
+
const path = require("path");
|
3
|
+
const basePath = process.argv[2];
|
4
|
+
const babelCore = require("@babel/core");
|
5
|
+
const babelParser = require("@babel/parser");
|
6
|
+
const babelGenerator = require("@babel/generator").default;
|
7
|
+
const walk = require("estree-walk");
|
8
|
+
|
9
|
+
const checkHasRequire = (filePath, code) => {
|
10
|
+
code = code.replace(/sap\.ui\.require/g, "unhandledRequire");
|
11
|
+
|
12
|
+
const tree = babelParser.parse(code, { sourceType: "module" });
|
13
|
+
walk(tree, {
|
14
|
+
CallExpression: function (node) {
|
15
|
+
if (node.type === "CallExpression" && node?.callee?.name === "unhandledRequire") {
|
16
|
+
throw new Error(`sap.ui.require found in ${filePath}`);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
});
|
20
|
+
}
|
21
|
+
|
22
|
+
const checkFile = async (filePath) => {
|
23
|
+
let code = (await fs.readFile(filePath)).toString();
|
24
|
+
checkHasRequire(filePath, code);
|
25
|
+
}
|
26
|
+
|
27
|
+
const checkAll = async () => {
|
28
|
+
const { globby } = await import("globby");
|
29
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
30
|
+
return Promise.all(fileNames.map(checkFile).filter(x => !!x));
|
31
|
+
};
|
32
|
+
|
33
|
+
checkAll();
|