@ui5/webcomponents-tools 0.0.0-fc993d8cd → 0.0.0-fca1107e7
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 +623 -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 -26
- package/components-package/wdio.js +15 -3
- package/components-package/wdio.sync.js +9 -1
- package/icons-collection/nps.js +8 -6
- 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 +28 -58
- package/lib/create-new-component/jsFileContentTemplate.js +1 -5
- package/lib/create-new-component/tsFileContentTemplate.js +3 -16
- 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/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 +3 -3
- 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/lib/test-runner/test-runner.js +2 -2
- package/package.json +13 -10
- 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
@@ -15,6 +15,7 @@ const overrides = tsMode ? [{
|
|
15
15
|
],
|
16
16
|
parserOptions: {
|
17
17
|
"project": ["./tsconfig.json", "./packages/*/tsconfig.json"],
|
18
|
+
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
|
18
19
|
},
|
19
20
|
rules: {
|
20
21
|
"no-shadow": "off",
|
@@ -27,6 +28,7 @@ const overrides = tsMode ? [{
|
|
27
28
|
"@typescript-eslint/no-unsafe-call": "off",
|
28
29
|
"@typescript-eslint/no-non-null-assertion": "off",
|
29
30
|
"@typescript-eslint/no-empty-function": "off",
|
31
|
+
"@typescript-eslint/no-empty-interface": "off",
|
30
32
|
"lines-between-class-members": "off",
|
31
33
|
}
|
32
34
|
}] : [];
|
@@ -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,26 +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 fs = require("fs");
|
7
|
-
|
8
|
-
const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
|
9
|
-
|
10
|
-
module.exports = {
|
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
|
-
};
|
1
|
+
module.exports = {};
|
@@ -1,3 +1,5 @@
|
|
1
|
+
const dns = require("node:dns");
|
2
|
+
|
1
3
|
exports.config = {
|
2
4
|
//
|
3
5
|
// ====================
|
@@ -56,7 +58,15 @@ exports.config = {
|
|
56
58
|
'goog:chromeOptions': {
|
57
59
|
// to run chrome headless the following flags are required
|
58
60
|
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
|
59
|
-
args: [
|
61
|
+
args: [
|
62
|
+
'--headless',
|
63
|
+
'--start-maximized',
|
64
|
+
'--no-sandbox',
|
65
|
+
'--disable-gpu',
|
66
|
+
'--disable-infobars',
|
67
|
+
'--disable-extensions',
|
68
|
+
'--disable-dev-shm-usage',
|
69
|
+
],
|
60
70
|
// args: ['--disable-gpu'],
|
61
71
|
}
|
62
72
|
}],
|
@@ -99,8 +109,7 @@ exports.config = {
|
|
99
109
|
// Services take over a specific job you don't want to take care of. They enhance
|
100
110
|
// your test setup with almost no effort. Unlike plugins, they don't add new
|
101
111
|
// commands. Instead, they hook themselves up into the test process.
|
102
|
-
services: ['chromedriver', '
|
103
|
-
['static-server', {
|
112
|
+
services: ['chromedriver', ['static-server', {
|
104
113
|
folders: [
|
105
114
|
{ mount: '/', path: './dist' },
|
106
115
|
],
|
@@ -153,6 +162,9 @@ exports.config = {
|
|
153
162
|
*/
|
154
163
|
// beforeSession: function (config, capabilities, specs) {
|
155
164
|
// },
|
165
|
+
beforeSession: () => {
|
166
|
+
dns.setDefaultResultOrder('ipv4first');
|
167
|
+
},
|
156
168
|
/**
|
157
169
|
* Gets executed before test execution begins. At this point you can access to all global
|
158
170
|
* variables like `browser`. It is the perfect place to define custom commands.
|
@@ -56,7 +56,15 @@ exports.config = {
|
|
56
56
|
'goog:chromeOptions': {
|
57
57
|
// to run chrome headless the following flags are required
|
58
58
|
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
|
59
|
-
args: [
|
59
|
+
args: [
|
60
|
+
'--headless',
|
61
|
+
'--start-maximized',
|
62
|
+
'--no-sandbox',
|
63
|
+
'--disable-gpu',
|
64
|
+
'--disable-infobars',
|
65
|
+
'--disable-extensions',
|
66
|
+
'--disable-dev-shm-usage',
|
67
|
+
],
|
60
68
|
// args: ['--disable-gpu'],
|
61
69
|
}
|
62
70
|
}],
|
package/icons-collection/nps.js
CHANGED
@@ -21,7 +21,7 @@ const copyIconAssetsCommand = (options) => {
|
|
21
21
|
return {
|
22
22
|
default: "nps copy.json-imports copy.icon-collection",
|
23
23
|
"json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
|
24
|
-
"icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json"
|
24
|
+
"icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" src/generated/assets/`,
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
@@ -32,7 +32,7 @@ const copyIconAssetsCommand = (options) => {
|
|
32
32
|
|
33
33
|
options.versions.forEach((v) => {
|
34
34
|
command.default += ` copy.icon-collection${v}`;
|
35
|
-
command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json"
|
35
|
+
command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
|
36
36
|
});
|
37
37
|
|
38
38
|
return command;
|
@@ -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();
|