@ui5/webcomponents-tools 2.15.0-rc.2 → 2.15.0

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 CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.15.0](https://github.com/UI5/webcomponents/compare/v2.15.0-rc.3...v2.15.0) (2025-10-03)
7
+
8
+ **Note:** Version bump only for package @ui5/webcomponents-tools
9
+
10
+
11
+
12
+
13
+
14
+ # [2.15.0-rc.3](https://github.com/UI5/webcomponents/compare/v2.15.0-rc.2...v2.15.0-rc.3) (2025-10-02)
15
+
16
+ **Note:** Version bump only for package @ui5/webcomponents-tools
17
+
18
+
19
+
20
+
21
+
6
22
  # [2.15.0-rc.2](https://github.com/UI5/webcomponents/compare/v2.15.0-rc.1...v2.15.0-rc.2) (2025-09-25)
7
23
 
8
24
  **Note:** Version bump only for package @ui5/webcomponents-tools
package/bin/ui5nps.js CHANGED
@@ -5,6 +5,7 @@
5
5
  const fs = require("fs");
6
6
  const path = require("path");
7
7
  const { exec } = require("child_process");
8
+ var { parseArgsStringToArgv } = require('string-argv');
8
9
 
9
10
  const SCRIPT_NAMES = [
10
11
  "package-scripts.js",
@@ -75,7 +76,7 @@ class Parser {
75
76
  throw new Error(`Command "${commandName}" not found in scripts`);
76
77
  }
77
78
 
78
- if (!executableCommand.startsWith("ui5nps") && !executableCommand.startsWith("ui5nps-p")) {
79
+ if (!executableCommand.startsWith("ui5nps") || executableCommand.startsWith("ui5nps-script")) {
79
80
  this.resolvedScripts.set(commandName, { commandName, commands: [executableCommand], parallel: false });
80
81
  return this.resolvedScripts.get(commandName);
81
82
  }
@@ -93,7 +94,7 @@ class Parser {
93
94
  this.resolveScripts(part);
94
95
  }
95
96
 
96
- commands.push(this.resolvedScripts.get(part) || parsedScript);
97
+ commands.push(this.resolvedScripts.get(part) || { commandName: part, commands: [parsedScript], parallel: parsedScript.startsWith("ui5nps-p") });
97
98
  }
98
99
 
99
100
 
@@ -155,10 +156,31 @@ class Parser {
155
156
  * @param {string|Object} command - Command string or command object with commands array
156
157
  * @returns {Promise} Promise that resolves when command(s) complete
157
158
  */
158
- async executeCommand(command) {
159
+ async executeCommand(command, commandName = "unknown") {
159
160
  if (typeof command === "string" && command) {
160
- return new Promise((resolve, reject) => {
161
- console.log(`= Executing command: ${command}`);
161
+ return new Promise(async (resolve, reject) => {
162
+ if (command.trim().startsWith("ui5nps-script")) {
163
+ const argv = parseArgsStringToArgv(command);
164
+ const importedContent = require(argv[1]);
165
+ let _ui5mainFn;
166
+
167
+ if (importedContent.__esModule) {
168
+ _ui5mainFn = importedContent.default._ui5mainFn;
169
+ } else {
170
+ _ui5mainFn = importedContent._ui5mainFn;
171
+ }
172
+
173
+ console.log(` | Executing command ${commandName} as module.`);
174
+ const result = _ui5mainFn(argv);
175
+
176
+ if (result instanceof Promise) {
177
+ return result.then(resolve).catch(reject);
178
+ } else {
179
+ return resolve();
180
+ }
181
+ }
182
+
183
+ console.log(` | Executing command ${commandName} as command.\n Running: ${command}`);
162
184
  const child = exec(command, { stdio: "inherit", env: { ...process.env, ...this.envs } });
163
185
 
164
186
  child.stdout.on("data", (data) => {
@@ -181,12 +203,12 @@ class Parser {
181
203
  } else if (typeof command === "object" && command.commands) {
182
204
  if (command.parallel) {
183
205
  // Execute commands in parallel
184
- const promises = command.commands.filter(Boolean).map(cmd => this.executeCommand(cmd));
206
+ const promises = command.commands.filter(Boolean).map(cmd => this.executeCommand(cmd, cmd.commandName || commandName));
185
207
  await Promise.all(promises);
186
208
  } else {
187
209
  // Execute commands sequentially
188
210
  for (const cmd of command.commands) {
189
- await this.executeCommand(cmd);
211
+ await this.executeCommand(cmd, cmd.commandName || commandName);
190
212
  }
191
213
  }
192
214
  }
@@ -204,7 +226,7 @@ class Parser {
204
226
  throw new Error(`Command "${commandName}" not found in scripts`);
205
227
  }
206
228
 
207
- return this.executeCommand(this.resolvedScripts.get(commandName));
229
+ return this.executeCommand(this.resolvedScripts.get(commandName), commandName);
208
230
  }
209
231
  }
210
232
 
@@ -218,7 +240,18 @@ if (commands.length === 0) {
218
240
  process.exit(1);
219
241
  }
220
242
 
243
+ if (commands.includes("--help") || commands.includes("-h")) {
244
+ console.log("Usage: ui5nps <command> [command2] [command3] ...");
245
+ console.log("Available commands:");
246
+ for (const [key, value] of parser.parsedScripts.entries()) {
247
+ console.log(` - ${key}: ${value}`);
248
+ }
249
+ process.exit(0);
250
+ }
251
+
221
252
  (async () => {
253
+ process.env = { ...process.env, ...parser.envs };
254
+
222
255
  for (const commandName of commands) {
223
256
  await parser.execute(commandName);
224
257
  }
@@ -3,25 +3,41 @@ const fs = require("fs");
3
3
  const LIB = path.join(__dirname, `../lib/`);
4
4
  let websiteBaseUrl = "/";
5
5
 
6
+ const isPreview = !!process.env.PR_NUMBER;
7
+ const getPreviewBaseUrl = () => {
8
+ if (process.env.DEPLOYMENT_TYPE === "netlify_preview") {
9
+ return "/";
10
+ }
11
+ return `/webcomponents/pr-${process.env.PR_NUMBER}/`;
12
+ }
13
+
6
14
  if (process.env.DEPLOY) {
7
15
  websiteBaseUrl = "/webcomponents/";
8
16
  } else if (process.env.DEPLOY_NIGHTLY) {
9
17
  websiteBaseUrl = "/webcomponents/nightly/";
10
- } else if (process.env.DEPLOYMENT_TYPE === "preview" && process.env.PR_NUMBER) {
11
- websiteBaseUrl = `/webcomponents/pr-${process.env.PR_NUMBER}/`;
18
+ } else if (isPreview) {
19
+ websiteBaseUrl = getPreviewBaseUrl();
12
20
  }
13
21
 
14
22
  const getScripts = (options) => {
15
-
16
23
  // The script creates all JS modules (dist/illustrations/{illustrationName}.js) out of the existing SVGs
17
24
  const illustrationsData = options.illustrationsData || [];
18
- const illustrations = illustrationsData.map(illustration => `node "${LIB}/create-illustrations/index.js" ${illustration.path} ${illustration.defaultText} ${illustration.illustrationsPrefix} ${illustration.set} ${illustration.destinationPath} ${illustration.collection}`);
19
- const createIllustrationsJSImportsScript = illustrations.join(" && ");
20
-
25
+ const createIllustrationsJSImportsScript = {
26
+ default: `ui5nps-p ${illustrationsData.map(illustrations => `build.illustrations.build-${illustrations.set}-${illustrations.collection}`).join(" ")}` // concurently,
27
+ }
28
+ illustrationsData.forEach((illustration) => {
29
+ createIllustrationsJSImportsScript[`build-${illustration.set}-${illustration.collection}`] = `ui5nps-script "${LIB}create-illustrations/index.js" ${illustration.path} ${illustration.defaultText} ${illustration.illustrationsPrefix} ${illustration.set} ${illustration.destinationPath} ${illustration.collection}`
30
+ });
21
31
  // The script creates the "src/generated/js-imports/Illustration.js" file that registers loaders (dynamic JS imports) for each illustration
22
- const createIllustrationsLoadersScript = illustrationsData.map(illustrations => `node ${LIB}/generate-js-imports/illustrations.js ${illustrations.path} ${illustrations.dynamicImports.outputFile} ${illustrations.set} ${illustrations.collection} ${illustrations.dynamicImports.location} ${illustrations.dynamicImports.filterOut.join(",")}`).join(" && ");
32
+ const createIllustrationsLoadersScript = {
33
+ default: `ui5nps-p ${illustrationsData.map(illustrations => `build.jsImports.illustrationsLoaders.generate-${illustrations.set}-${illustrations.collection}`).join(" ")}` // concurently,
34
+ }
35
+ illustrationsData.forEach((illustrations) => {
36
+ createIllustrationsLoadersScript[`generate-${illustrations.set}-${illustrations.collection}`] = `ui5nps-script ${LIB}generate-js-imports/illustrations.js ${illustrations.path} ${illustrations.dynamicImports.outputFile} ${illustrations.set} ${illustrations.collection} ${illustrations.dynamicImports.location} ${illustrations.dynamicImports.filterOut.join(",")}`
37
+ });
38
+
23
39
 
24
- const tsOption = !options.legacy || options.jsx;
40
+ const tsOption = !!(!options.legacy || options.jsx);
25
41
  const tsCommandOld = tsOption ? "tsc" : "";
26
42
  let tsWatchCommandStandalone = tsOption ? "tsc --watch" : "";
27
43
  // this command is only used for standalone projects. monorepo projects get their watch from vite, so opt-out here
@@ -62,13 +78,14 @@ const getScripts = (options) => {
62
78
  const scripts = {
63
79
  __ui5envs: {
64
80
  UI5_CEM_MODE: options.dev,
65
- UI5_TS: !!tsOption,
81
+ UI5_TS: `${tsOption}`,
66
82
  CYPRESS_COVERAGE: !!(options.internal?.cypress_code_coverage),
67
83
  CYPRESS_UI5_ACC: !!(options.internal?.cypress_acc_tests),
68
84
  },
69
85
  clean: {
70
- default: 'ui5nps clean.generated scope.testPages.clean',
71
- generated: 'rimraf src/generated && rimraf dist',
86
+ "default": "ui5nps clean.generated clean.dist scope.testPages.clean",
87
+ "generated": `ui5nps-script "${LIB}/rimraf/rimraf.js src/generated`,
88
+ "dist": `ui5nps-script "${LIB}/rimraf/rimraf.js dist`,
72
89
  },
73
90
  lint: `eslint . ${eslintConfig}`,
74
91
  lintfix: `eslint . ${eslintConfig} --fix`,
@@ -85,23 +102,23 @@ const getScripts = (options) => {
85
102
  },
86
103
  build: {
87
104
  default: "ui5nps prepare lint build.bundle", // build.bundle2
88
- templates: options.legacy ? `mkdirp src/generated/templates && node "${LIB}/hbs2ui5/index.js" -d src/ -o src/generated/templates` : "",
105
+ templates: options.legacy ? `mkdirp src/generated/templates && node "${LIB}hbs2ui5/index.js" -d src/ -o src/generated/templates` : "",
89
106
  styles: {
90
107
  default: `ui5nps-p build.styles.themes build.styles.components`, // concurently
91
- themes: `node "${LIB}/css-processors/css-processor-themes.mjs"`,
92
- themesWithWatch: `node "${LIB}/css-processors/css-processor-themes.mjs" -w`,
93
- components: `node "${LIB}/css-processors/css-processor-components.mjs"`,
94
- componentsWithWatch: `node "${LIB}/css-processors/css-processor-components.mjs" -w`,
108
+ themes: `ui5nps-script "${LIB}css-processors/css-processor-themes.mjs"`,
109
+ themesWithWatch: `ui5nps-script "${LIB}css-processors/css-processor-themes.mjs" -w`,
110
+ components: `ui5nps-script "${LIB}css-processors/css-processor-components.mjs"`,
111
+ componentsWithWatch: `ui5nps-script "${LIB}css-processors/css-processor-components.mjs" -w`,
95
112
  },
96
113
  i18n: {
97
114
  default: "ui5nps build.i18n.defaultsjs build.i18n.json",
98
- defaultsjs: `node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
99
- json: `node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
115
+ defaultsjs: `ui5nps-script "${LIB}i18n/defaults.js" src/i18n src/generated/i18n`,
116
+ json: `ui5nps-script "${LIB}i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
100
117
  },
101
118
  jsonImports: {
102
119
  default: "ui5nps build.jsonImports.themes build.jsonImports.i18n",
103
- themes: `node "${LIB}/generate-json-imports/themes.js" src/themes src/generated/json-imports`,
104
- i18n: `node "${LIB}/generate-json-imports/i18n.js" src/i18n src/generated/json-imports`,
120
+ themes: `ui5nps-script "${LIB}generate-json-imports/themes.js" src/themes src/generated/json-imports`,
121
+ i18n: `ui5nps-script "${LIB}generate-json-imports/i18n.js" src/i18n src/generated/json-imports`,
105
122
  },
106
123
  jsImports: {
107
124
  default: "ui5nps build.jsImports.illustrationsLoaders",
@@ -111,12 +128,12 @@ const getScripts = (options) => {
111
128
  bundle2: ``,
112
129
  illustrations: createIllustrationsJSImportsScript,
113
130
  },
114
- copyProps: `node "${LIB}/copy-and-watch/index.js" --silent "src/i18n/*.properties" dist/`,
115
- copyPropsWithWatch: `node "${LIB}/copy-and-watch/index.js" --silent "src/i18n/*.properties" dist/ --watch --safe --skip-initial-copy`,
131
+ copyProps: `ui5nps-script "${LIB}copy-and-watch/index.js" --silent "src/i18n/*.properties" dist/`,
132
+ copyPropsWithWatch: `ui5nps-script "${LIB}copy-and-watch/index.js" --silent "src/i18n/*.properties" dist/ --watch --safe --skip-initial-copy`,
116
133
  copy: {
117
134
  default: options.legacy ? "ui5nps copy.src copy.props" : "",
118
- src: options.legacy ? `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.{js,json}" dist/` : "",
119
- props: options.legacy ? `node "${LIB}/copy-and-watch/index.js" --silent "src/i18n/*.properties" dist/` : "",
135
+ src: options.legacy ? `ui5nps-script "${LIB}copy-and-watch/index.js" --silent "src/**/*.{js,json}" dist/` : "",
136
+ props: options.legacy ? `ui5nps-script "${LIB}copy-and-watch/index.js" --silent "src/i18n/*.properties" dist/` : "",
120
137
  },
121
138
  watch: {
122
139
  default: `ui5nps-p watch.templates watch.typescript watch.src watch.styles watch.i18n watch.props`, // concurently
@@ -124,7 +141,7 @@ const getScripts = (options) => {
124
141
  src: options.legacy ? 'ui5nps "copy.src --watch --safe --skip-initial-copy"' : "",
125
142
  typescript: tsWatchCommandStandalone,
126
143
  props: 'ui5nps copyPropsWithWatch',
127
- bundle: `node ${LIB}/dev-server/dev-server.mjs ${viteConfig}`,
144
+ bundle: `ui5nps-script ${LIB}dev-server/dev-server.mjs ${viteConfig}`,
128
145
  styles: {
129
146
  default: 'ui5nps-p watch.styles.themes watch.styles.components', // concurently
130
147
  themes: 'ui5nps build.styles.themesWithWatch',
@@ -134,7 +151,7 @@ const getScripts = (options) => {
134
151
  i18n: 'chokidar "src/i18n/messagebundle.properties" -c "ui5nps build.i18n.defaultsjs"'
135
152
  },
136
153
  start: "ui5nps prepare watch.devServer",
137
- test: `node "${LIB}/test-runner/test-runner.js"`,
154
+ test: `ui5nps-script "${LIB}/test-runner/test-runner.js"`,
138
155
  "test-cy-ci": `cypress run --component --browser chrome`,
139
156
  "test-cy-ci-suite-1": `cypress run --component --browser chrome --spec "**/specs/[A-C]*.cy.{js,jsx,ts,tsx},**/specs/[^D-Z]*.cy.{js,jsx,ts,tsx}"`,
140
157
  "test-cy-ci-suite-2": `cypress run --component --browser chrome --spec "**/specs/[D-L]*.cy.{js,jsx,ts,tsx}"`,
@@ -144,21 +161,21 @@ const getScripts = (options) => {
144
161
  startWithScope: "ui5nps scope.prepare scope.watchWithBundle",
145
162
  scope: {
146
163
  prepare: "ui5nps scope.lint scope.testPages",
147
- lint: `node "${LIB}/scoping/lint-src.js"`,
164
+ lint: `ui5nps-script "${LIB}scoping/lint-src.js"`,
148
165
  testPages: {
149
166
  default: "ui5nps scope.testPages.clean scope.testPages.copy scope.testPages.replace",
150
- clean: "rimraf test/pages/scoped",
151
- copy: `node "${LIB}/copy-and-watch/index.js" --silent "test/pages/**/*" test/pages/scoped`,
152
- replace: `node "${LIB}/scoping/scope-test-pages.js" test/pages/scoped demo`,
167
+ "clean": `ui5nps-script "${LIB}/rimraf/rimraf.js test/pages/scoped`,
168
+ copy: `ui5nps-script "${LIB}copy-and-watch/index.js" --silent "test/pages/**/*" test/pages/scoped`,
169
+ replace: `ui5nps-script "${LIB}scoping/scope-test-pages.js" test/pages/scoped demo`,
153
170
  },
154
171
  watchWithBundle: 'ui5nps-p scope.watch scope.bundle', // concurently
155
172
  watch: 'ui5nps-p watch.templates watch.props watch.styles', // concurently
156
- bundle: `node ${LIB}/dev-server/dev-server.mjs ${viteConfig}`,
173
+ bundle: `ui5nps-script ${LIB}dev-server/dev-server.mjs ${viteConfig}`,
157
174
  },
158
175
  generateAPI: {
159
176
  default: tsOption ? "ui5nps generateAPI.generateCEM generateAPI.validateCEM" : "",
160
- generateCEM: `cem analyze --config "${LIB}/cem/custom-elements-manifest.config.mjs"`,
161
- validateCEM: `node "${LIB}/cem/validate.js"`,
177
+ generateCEM: `ui5nps-script "${LIB}cem/cem.js" analyze --config "${LIB}cem/custom-elements-manifest.config.mjs"`,
178
+ validateCEM: `ui5nps-script "${LIB}cem/validate.js"`,
162
179
  },
163
180
  };
164
181
 
@@ -4,13 +4,13 @@ const LIB = path.join(__dirname, `../lib/`);
4
4
 
5
5
  const createIconImportsCommand = (options) => {
6
6
  if (!options.versions) {
7
- return `node "${LIB}/create-icons/index.js" "${options.collectionName}"`;
7
+ return `ui5nps-script "${LIB}/create-icons/index.js" "${options.collectionName}"`;
8
8
  }
9
9
 
10
10
  const command = { default: "ui5nps" };
11
11
  options.versions.forEach((v) => {
12
12
  command.default += ` build.icons.create${v}`;
13
- command[`create${v}`] = `node "${LIB}/create-icons/index.js" "${options.collectionName}" "${v}"`;
13
+ command[`create${v}`] = `ui5nps-script "${LIB}/create-icons/index.js" "${options.collectionName}" "${v}"`;
14
14
  });
15
15
 
16
16
  return command;
@@ -22,19 +22,19 @@ const copyIconAssetsCommand = (options) => {
22
22
  if (!options.versions) {
23
23
  return {
24
24
  default: "ui5nps copy.json-imports copy.icon-collection",
25
- "json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
26
- "icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" src/generated/assets/`,
25
+ "json-imports": `ui5nps-script "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
26
+ "icon-collection": `ui5nps-script "${LIB}/copy-and-watch/index.js" --silent "src/*.json" src/generated/assets/`,
27
27
  }
28
28
  }
29
29
 
30
30
  const command = {
31
31
  default: "ui5nps copy.json-imports ",
32
- "json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
32
+ "json-imports": `ui5nps-script "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
33
33
  };
34
34
 
35
35
  options.versions.forEach((v) => {
36
36
  command.default += ` copy.icon-collection${v}`;
37
- command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
37
+ command[`icon-collection${v}`] = `ui5nps-script "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
38
38
  });
39
39
 
40
40
  return command;
@@ -47,23 +47,27 @@ const getScripts = (options) => {
47
47
  const tsOption = !options.legacy;
48
48
 
49
49
  const scripts = {
50
- __ui5envs:{
51
- UI5_TS: tsOption,
50
+ __ui5envs: {
51
+ UI5_TS: `${tsOption}`,
52
+ },
53
+ clean: {
54
+ default: "ui5nps clean.generated clean.dist",
55
+ "generated": `ui5nps-script "${LIB}/rimraf/rimraf.js src/generated`,
56
+ "dist": `ui5nps-script "${LIB}/rimraf/rimraf.js dist`,
52
57
  },
53
- clean: "rimraf dist && rimraf src/generated",
54
58
  copy: copyAssetsCmd,
55
59
  generate: hashesCheck(`ui5nps clean copy build.i18n build.icons build.jsonImports copyjson`),
56
- copyjson: "copy-and-watch \"src/generated/**/*.json\" dist/generated/",
60
+ copyjson: `ui5nps-script "${LIB}copy-and-watch/index.js" "src/generated/**/*.json" dist/generated`,
57
61
  build: {
58
62
  default: hashesCheck(`ui5nps clean copy build.i18n typescript build.icons build.jsonImports`),
59
63
  i18n: {
60
64
  default: "ui5nps build.i18n.defaultsjs build.i18n.json",
61
- defaultsjs: `node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
62
- json: `node "${LIB}/i18n/toJSON.js" src/i18n src/generated/assets/i18n`,
65
+ defaultsjs: `ui5nps-script "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
66
+ json: `ui5nps-script "${LIB}/i18n/toJSON.js" src/i18n src/generated/assets/i18n`,
63
67
  },
64
68
  jsonImports: {
65
69
  default: "ui5nps build.jsonImports.i18n",
66
- i18n: `node "${LIB}/generate-json-imports/i18n.js" src/generated/assets/i18n src/generated/json-imports`,
70
+ i18n: `ui5nps-script "${LIB}/generate-json-imports/i18n.js" src/generated/assets/i18n src/generated/json-imports`,
67
71
  },
68
72
  icons: createJSImportsCmd,
69
73
  },
@@ -1,6 +1,5 @@
1
1
  const fs = require("fs").promises;
2
2
  const path = require("path");
3
- const basePath = process.argv[2];
4
3
  const babelCore = require("@babel/core");
5
4
  const babelParser = require("@babel/parser");
6
5
  const babelGenerator = require("@babel/generator").default;
@@ -21,7 +20,7 @@ const convertAmdToEs6 = async (code) => {
21
20
  })).code;
22
21
  }
23
22
 
24
- const convertAbsImportsToRelative = (filePath, code) => {
23
+ const convertAbsImportsToRelative = (filePath, code, basePath) => {
25
24
  let changed = false;
26
25
  // console.log("File processing started: ", srcPath);
27
26
 
@@ -69,7 +68,7 @@ const convertAbsImportsToRelative = (filePath, code) => {
69
68
  }
70
69
 
71
70
  const replaceGlobalCoreUsage = (filePath, code) => {
72
- if (!filePath.includes("Configuration")) {
71
+ if (!filePath.includes("Configuration")) {
73
72
  const replaced = code.replace(/sap\.ui\.getCore\(\)/g, `Core`);
74
73
  return code !== replaced ? `import Core from 'sap/ui/core/Core';${replaced}` : code;
75
74
  }
@@ -77,7 +76,7 @@ const replaceGlobalCoreUsage = (filePath, code) => {
77
76
  return code;
78
77
  };
79
78
 
80
- const transformAmdToES6Module = async (filePath) => {
79
+ const transformAmdToES6Module = async (filePath, basePath) => {
81
80
  await convertSAPUIDefineToDefine(filePath);
82
81
 
83
82
  let code = (await fs.readFile(filePath)).toString();
@@ -86,17 +85,23 @@ const transformAmdToES6Module = async (filePath) => {
86
85
 
87
86
  code = replaceGlobalCoreUsage(filePath, code);
88
87
 
89
- code = convertAbsImportsToRelative(filePath, code);
88
+ code = convertAbsImportsToRelative(filePath, code, basePath);
90
89
 
91
90
  return fs.writeFile(filePath, code);
92
91
  }
93
92
 
94
- const transformAmdToES6Modules = async () => {
93
+ const transformAmdToES6Modules = async (argv) => {
94
+ const basePath = argv[2];
95
95
  const { globby } = await import("globby");
96
96
  const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
97
- return Promise.all(fileNames.map(transformAmdToES6Module).filter(x => !!x));
97
+ return Promise.all(fileNames.map(fileName => transformAmdToES6Module(fileName, basePath)).filter(x => !!x))
98
+ .then(() => {
99
+ console.log("Success: all amd modules are transformed to es6!");
100
+ });
98
101
  };
99
102
 
100
- transformAmdToES6Modules().then(() => {
101
- console.log("Success: all amd modules are transformed to es6!");
102
- });
103
+ if (require.main === module) {
104
+ transformAmdToES6Modules(process.argv)
105
+ }
106
+
107
+ exports._ui5mainFn = transformAmdToES6Modules;
package/lib/cem/cem.js ADDED
@@ -0,0 +1,12 @@
1
+ const cemCLI = require("@custom-elements-manifest/analyzer/cli")
2
+
3
+ const main = async argv => {
4
+ const patchedArgv = argv.slice(2);
5
+ await cemCLI.cli({ argv: patchedArgv, cwd: process.cwd(), noWrite: false });
6
+ }
7
+
8
+ if (require.main === module) {
9
+ main(process.argv)
10
+ }
11
+
12
+ exports._ui5mainFn = main;
@@ -5,63 +5,72 @@ const path = require('path');
5
5
  const extenalSchema = require('./schema.json');
6
6
  const internalSchema = require('./schema-internal.json');
7
7
 
8
- // Load your JSON data from the input file
9
- const inputFilePath = path.join(process.cwd(), "dist/custom-elements.json"); // Update with your file path
10
- const customManifest = fs.readFileSync(inputFilePath, 'utf8');
11
- const inputDataInternal = JSON.parse(customManifest);
12
- const devMode = process.env.UI5_CEM_MODE === "dev";
13
8
 
14
- inputDataInternal.modules.forEach(moduleDoc => {
15
- moduleDoc.exports = moduleDoc.exports.
16
- filter(e => moduleDoc.declarations.find(d => d.name === e.declaration.name && ["class", "function", "variable", "enum"].includes(d.kind)) || e.name === "default");
17
- })
9
+ const validateFn = async () => {
10
+ // Load your JSON data from the input file
11
+ const inputFilePath = path.join(process.cwd(), "dist/custom-elements.json"); // Update with your file path
12
+ const customManifest = fs.readFileSync(inputFilePath, 'utf8');
13
+ const inputDataInternal = JSON.parse(customManifest);
14
+ const devMode = process.env.UI5_CEM_MODE === "dev";
18
15
 
19
- const clearProps = (data) => {
20
- if (Array.isArray(data)) {
21
- for (let i = 0; i < data.length; i++) {
22
- if (typeof data[i] === "object") {
23
- if (["enum", "interface"].includes(data[i].kind)) {
24
- data.splice(i, 1);
25
- i--;
26
- } else {
27
- clearProps(data[i]);
16
+ inputDataInternal.modules.forEach(moduleDoc => {
17
+ moduleDoc.exports = moduleDoc.exports.
18
+ filter(e => moduleDoc.declarations.find(d => d.name === e.declaration.name && ["class", "function", "variable", "enum"].includes(d.kind)) || e.name === "default");
19
+ })
20
+
21
+ const clearProps = (data) => {
22
+ if (Array.isArray(data)) {
23
+ for (let i = 0; i < data.length; i++) {
24
+ if (typeof data[i] === "object") {
25
+ if (["enum", "interface"].includes(data[i].kind)) {
26
+ data.splice(i, 1);
27
+ i--;
28
+ } else {
29
+ clearProps(data[i]);
30
+ }
28
31
  }
29
32
  }
33
+ } else if (typeof data === "object") {
34
+ Object.keys(data).forEach(prop => {
35
+ if (prop.startsWith("_ui5")) {
36
+ delete data[prop];
37
+ } else if (typeof data[prop] === "object") {
38
+ clearProps(data[prop]);
39
+ }
40
+ });
30
41
  }
31
- } else if (typeof data === "object") {
32
- Object.keys(data).forEach(prop => {
33
- if (prop.startsWith("_ui5")) {
34
- delete data[prop];
35
- } else if (typeof data[prop] === "object") {
36
- clearProps(data[prop]);
37
- }
38
- });
42
+
43
+ return data;
39
44
  }
40
45
 
41
- return data;
42
- }
46
+ const ajv = new Ajv({ allowUnionTypes: true, allError: true })
47
+ let validate = ajv.compile(internalSchema)
43
48
 
44
- const ajv = new Ajv({ allowUnionTypes: true, allError: true })
45
- let validate = ajv.compile(internalSchema)
49
+ // Validate the JSON data against the schema
50
+ if (devMode) {
51
+ if (validate(inputDataInternal)) {
52
+ console.log('Internal custom element manifest is validated successfully');
53
+ } else {
54
+ console.log(validate.errors)
55
+ throw new Error(`Validation of internal custom elements manifest failed: ${validate.errors}`);
56
+ }
57
+ }
46
58
 
47
- // Validate the JSON data against the schema
48
- if (devMode) {
49
- if (validate(inputDataInternal)) {
50
- console.log('Internal custom element manifest is validated successfully');
51
- } else {
52
- console.log(validate.errors)
53
- throw new Error(`Validation of internal custom elements manifest failed: ${validate.errors}`);
59
+ const inputDataExternal = clearProps(JSON.parse(JSON.stringify(inputDataInternal)));
60
+ validate = ajv.compile(extenalSchema)
61
+
62
+ // Validate the JSON data against the schema
63
+ if (validate(inputDataExternal)) {
64
+ console.log('Custom element manifest is validated successfully');
65
+ fs.writeFileSync(inputFilePath, JSON.stringify(inputDataExternal, null, 2), 'utf8');
66
+ fs.writeFileSync(inputFilePath.replace("custom-elements", "custom-elements-internal"), JSON.stringify(inputDataInternal, null, 2), 'utf8');
67
+ } else if (devMode) {
68
+ throw new Error(`Validation of public custom elements manifest failed: ${validate.errors}`);
54
69
  }
55
70
  }
56
71
 
57
- const inputDataExternal = clearProps(JSON.parse(JSON.stringify(inputDataInternal)));
58
- validate = ajv.compile(extenalSchema)
72
+ if (require.main === module) {
73
+ validateFn()
74
+ }
59
75
 
60
- // Validate the JSON data against the schema
61
- if (validate(inputDataExternal)) {
62
- console.log('Custom element manifest is validated successfully');
63
- fs.writeFileSync(inputFilePath, JSON.stringify(inputDataExternal, null, 2), 'utf8');
64
- fs.writeFileSync(inputFilePath.replace("custom-elements", "custom-elements-internal"), JSON.stringify(inputDataInternal, null, 2), 'utf8');
65
- } else if (devMode) {
66
- throw new Error(`Validation of public custom elements manifest failed: ${validate.errors}`);
67
- }
76
+ exports._ui5mainFn = validateFn;