@ui5/webcomponents-tools 2.15.0-rc.0 → 2.15.0-rc.3

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.
@@ -7,72 +7,82 @@ import chokidar from "chokidar";
7
7
  import scopeVariables from "./scope-variables.mjs";
8
8
  import { writeFileIfChanged, getFileContent } from "./shared.mjs";
9
9
 
10
- const tsMode = process.env.UI5_TS === "true";
11
- const extension = tsMode ? ".css.ts" : ".css.js";
10
+ const generate = async (argv) => {
11
+ const tsMode = process.env.UI5_TS === "true";
12
+ const extension = tsMode ? ".css.ts" : ".css.js";
12
13
 
13
- const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
14
- const inputFilesGlob = "src/themes/*.css";
15
- const restArgs = process.argv.slice(2);
14
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
15
+ const inputFilesGlob = "src/themes/*.css";
16
+ const restArgs = argv.slice(2);
16
17
 
17
- let customPlugin = {
18
- name: 'ui5-tools',
19
- setup(build) {
20
- build.initialOptions.write = false;
18
+ let customPlugin = {
19
+ name: 'ui5-tools',
20
+ setup(build) {
21
+ build.initialOptions.write = false;
21
22
 
22
- build.onEnd(result => {
23
- result.outputFiles.forEach(async f => {
24
- // scoping
25
- let newText = scopeVariables(f.text, packageJSON);
26
- newText = newText.replaceAll(/\\/g, "\\\\"); // Escape backslashes as they might appear in css rules
27
- await mkdir(path.dirname(f.path), {recursive: true});
28
- writeFile(f.path, newText);
23
+ build.onEnd(result => {
24
+ result.outputFiles.forEach(async f => {
25
+ // scoping
26
+ let newText = scopeVariables(f.text, packageJSON);
27
+ newText = newText.replaceAll(/\\/g, "\\\\"); // Escape backslashes as they might appear in css rules
28
+ await mkdir(path.dirname(f.path), { recursive: true });
29
+ writeFile(f.path, newText);
29
30
 
30
- // JS/TS
31
- const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
32
- const jsContent = getFileContent(packageJSON.name, "\`" + newText + "\`", true);
33
- writeFileIfChanged(jsPath, jsContent);
34
- });
35
- })
36
- },
37
- }
31
+ // JS/TS
32
+ const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
33
+ const jsContent = getFileContent(packageJSON.name, "\`" + newText + "\`", true);
34
+ writeFileIfChanged(jsPath, jsContent);
35
+ });
36
+ })
37
+ },
38
+ }
38
39
 
39
- const getConfig = async () => {
40
- const config = {
41
- entryPoints: await globby(inputFilesGlob),
42
- bundle: true,
43
- minify: true,
44
- outdir: 'dist/css',
45
- outbase: 'src',
46
- plugins: [
47
- customPlugin,
48
- ]
49
- };
50
- return config;
51
- }
40
+ const getConfig = async () => {
41
+ const config = {
42
+ entryPoints: await globby(inputFilesGlob),
43
+ bundle: true,
44
+ minify: true,
45
+ outdir: 'dist/css',
46
+ outbase: 'src',
47
+ plugins: [
48
+ customPlugin,
49
+ ]
50
+ };
51
+ return config;
52
+ }
52
53
 
53
- if (restArgs.includes("-w")) {
54
- let ready;
55
- let config = await getConfig();
56
- let ctx = await esbuild.context(config);
57
- await ctx.watch()
58
- console.log('watching...')
54
+ if (restArgs.includes("-w")) {
55
+ let ready;
56
+ let config = await getConfig();
57
+ let ctx = await esbuild.context(config);
58
+ await ctx.watch()
59
+ console.log('watching...')
59
60
 
60
- // when new component css files are added, they do not trigger a build as no one directly imports them
61
- // restart the watch mode with the new entry points if a css file is added.
62
- const watcher = chokidar.watch(inputFilesGlob);
63
- watcher.on("ready", () => {
64
- ready = true; // Initial scan is over -> waiting for new files
65
- });
66
- watcher.on("add", async path => {
67
- if (ready) {
68
- // new file
69
- ctx.dispose();
70
- config = await getConfig();
71
- ctx = await esbuild.context(config);
72
- ctx.watch();
73
- }
74
- });
75
- } else {
76
- const config = await getConfig();
77
- const result = await esbuild.build(config);
61
+ // when new component css files are added, they do not trigger a build as no one directly imports them
62
+ // restart the watch mode with the new entry points if a css file is added.
63
+ const watcher = chokidar.watch(inputFilesGlob);
64
+ watcher.on("ready", () => {
65
+ ready = true; // Initial scan is over -> waiting for new files
66
+ });
67
+ watcher.on("add", async path => {
68
+ if (ready) {
69
+ // new file
70
+ ctx.dispose();
71
+ config = await getConfig();
72
+ ctx = await esbuild.context(config);
73
+ ctx.watch();
74
+ }
75
+ });
76
+ } else {
77
+ const config = await getConfig();
78
+ const result = await esbuild.build(config);
79
+ }
78
80
  }
81
+
82
+ if (import.meta.url === `file://${process.argv[1]}`) {
83
+ generate(process.argv)
84
+ }
85
+
86
+ export default {
87
+ _ui5mainFn: generate
88
+ }
@@ -8,81 +8,91 @@ import combineDuplicatedSelectors from "../postcss-combine-duplicated-selectors/
8
8
  import { writeFileIfChanged, getFileContent } from "./shared.mjs";
9
9
  import scopeVariables from "./scope-variables.mjs";
10
10
 
11
- const tsMode = process.env.UI5_TS === "true";
12
- const extension = tsMode ? ".css.ts" : ".css.js";
11
+ const generate = async (argv) => {
12
+ const tsMode = process.env.UI5_TS === "true";
13
+ const extension = tsMode ? ".css.ts" : ".css.js";
13
14
 
14
- const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
15
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
15
16
 
16
- const inputFiles = await globby([
17
- "src/**/parameters-bundle.css",
18
- ]);
19
- const restArgs = process.argv.slice(2);
17
+ const inputFiles = await globby([
18
+ "src/**/parameters-bundle.css",
19
+ ]);
20
+ const restArgs = argv.slice(2);
20
21
 
21
- const processThemingPackageFile = async (f) => {
22
- const selector = ':root';
23
- const result = await postcss().process(f.text);
22
+ const processThemingPackageFile = async (f) => {
23
+ const selector = ':root';
24
+ const result = await postcss().process(f.text);
24
25
 
25
- const newRule = postcss.rule({ selector });
26
+ const newRule = postcss.rule({ selector });
26
27
 
27
- result.root.walkRules(selector, rule => {
28
- rule.walkDecls(decl => {
29
- if (!decl.prop.startsWith('--sapFontUrl')) {
30
- newRule.append(decl.clone());
31
- }
28
+ result.root.walkRules(selector, rule => {
29
+ rule.walkDecls(decl => {
30
+ if (!decl.prop.startsWith('--sapFontUrl')) {
31
+ newRule.append(decl.clone());
32
+ }
33
+ });
32
34
  });
33
- });
34
-
35
- return newRule.toString();
36
- };
37
35
 
38
- const processComponentPackageFile = async (f) => {
39
- const result = await postcss(combineDuplicatedSelectors).process(f.text);
40
-
41
- return scopeVariables(result.css, packageJSON, f.path);
36
+ return newRule.toString();
37
+ };
38
+
39
+ const processComponentPackageFile = async (f) => {
40
+ const result = await postcss(combineDuplicatedSelectors).process(f.text);
41
+
42
+ return scopeVariables(result.css, packageJSON, f.path);
43
+ }
44
+
45
+ let scopingPlugin = {
46
+ name: 'scoping',
47
+ setup(build) {
48
+ build.initialOptions.write = false;
49
+
50
+ build.onEnd(result => {
51
+ result.outputFiles.forEach(async f => {
52
+ let newText = f.path.includes("packages/theming") ? await processThemingPackageFile(f) : await processComponentPackageFile(f);
53
+
54
+ await mkdir(path.dirname(f.path), { recursive: true });
55
+ writeFile(f.path, newText);
56
+
57
+ // JSON
58
+ const jsonPath = f.path.replace(/dist[\/\\]css/, "dist/generated/assets").replace(".css", ".css.json");
59
+ await mkdir(path.dirname(jsonPath), { recursive: true });
60
+ writeFileIfChanged(jsonPath, JSON.stringify(newText));
61
+
62
+ // JS/TS
63
+ const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
64
+ const jsContent = getFileContent(packageJSON.name, "\`" + newText + "\`");
65
+ writeFileIfChanged(jsPath, jsContent);
66
+ });
67
+ })
68
+ },
69
+ }
70
+
71
+ const config = {
72
+ entryPoints: inputFiles,
73
+ bundle: true,
74
+ minify: true,
75
+ outdir: 'dist/css',
76
+ outbase: 'src',
77
+ plugins: [
78
+ scopingPlugin,
79
+ ],
80
+ external: ["*.ttf", "*.woff", "*.woff2"],
81
+ };
82
+
83
+ if (restArgs.includes("-w")) {
84
+ let ctx = await esbuild.context(config);
85
+ console.log('watching...')
86
+ await ctx.watch()
87
+ } else {
88
+ await esbuild.build(config);
89
+ }
42
90
  }
43
91
 
44
- let scopingPlugin = {
45
- name: 'scoping',
46
- setup(build) {
47
- build.initialOptions.write = false;
48
-
49
- build.onEnd(result => {
50
- result.outputFiles.forEach(async f => {
51
- let newText = f.path.includes("packages/theming") ? await processThemingPackageFile(f) : await processComponentPackageFile(f);
52
-
53
- await mkdir(path.dirname(f.path), { recursive: true });
54
- writeFile(f.path, newText);
55
-
56
- // JSON
57
- const jsonPath = f.path.replace(/dist[\/\\]css/, "dist/generated/assets").replace(".css", ".css.json");
58
- await mkdir(path.dirname(jsonPath), { recursive: true });
59
- writeFileIfChanged(jsonPath, JSON.stringify(newText));
60
-
61
- // JS/TS
62
- const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
63
- const jsContent = getFileContent(packageJSON.name, "\`" + newText + "\`");
64
- writeFileIfChanged(jsPath, jsContent);
65
- });
66
- })
67
- },
92
+ if (import.meta.url === `file://${process.argv[1]}`) {
93
+ generate(process.argv)
68
94
  }
69
95
 
70
- const config = {
71
- entryPoints: inputFiles,
72
- bundle: true,
73
- minify: true,
74
- outdir: 'dist/css',
75
- outbase: 'src',
76
- plugins: [
77
- scopingPlugin,
78
- ],
79
- external: ["*.ttf", "*.woff", "*.woff2"],
80
- };
81
-
82
- if (restArgs.includes("-w")) {
83
- let ctx = await esbuild.context(config);
84
- await ctx.watch()
85
- console.log('watching...')
86
- } else {
87
- const result = await esbuild.build(config);
96
+ export default {
97
+ _ui5mainFn: generate
88
98
  }
@@ -2,85 +2,84 @@ const fs = require("fs").promises;
2
2
  const path = require("path");
3
3
 
4
4
  const generateDynamicImportLines = async (fileNames, location, exclusionPatterns = []) => {
5
- const packageName = JSON.parse(await fs.readFile("package.json")).name;
6
- return fileNames
7
- .filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
8
- .map((fileName) => {
9
- const illustrationName = fileName.replace(".js", "");
10
- const illustrationPath = `${location}/${illustrationName}`;
11
- return `\t\tcase "${fileName.replace('.js', '')}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-${illustrationName.toLowerCase()}" */ "${illustrationPath}.js")).default;`;
12
- })
13
- .join("\n");
14
- };
15
-
16
- const generateAvailableIllustrationsArray = (fileNames, exclusionPatterns = []) => {
17
- return JSON.stringify(
18
- fileNames
19
- .filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
20
- .map((fileName) => fileName.replace(".js", ""))
21
- );
5
+ const packageName = JSON.parse(await fs.readFile("package.json")).name;
6
+ return fileNames
7
+ .filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
8
+ .map((fileName) => {
9
+ const illustrationName = fileName.replace(".svg", "");
10
+ const illustrationPath = `${location}/${illustrationName}`;
11
+ return `\t\tcase "${fileName.replace('.js', '')}": return (await import(/* webpackChunkName: "${packageName.replace("@", "").replace("/", "-")}-${illustrationName.toLowerCase()}" */ "${illustrationPath}.js")).default;`;
12
+ })
13
+ .join("\n");
22
14
  };
23
15
 
24
16
  const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, set, prefix = "") => {
25
- return `// @ts-nocheck
26
- import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
17
+ return `// @ts-nocheck
18
+ import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
27
19
 
28
20
  export const loadIllustration = async (illustrationName) => {
29
- const collectionAndPrefix = "${set}/${collection}/${prefix}";
30
- const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
31
- switch (cleanIllustrationName) {
21
+ const collectionAndPrefix = "${set}/${collection}/${prefix}";
22
+ const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
23
+ switch (cleanIllustrationName) {
32
24
  ${dynamicImports}
33
- default:
34
- throw new Error("[Illustrations] Illustration not found: " + illustrationName);
35
- }
25
+ default:
26
+ throw new Error("[Illustrations] Illustration not found: " + illustrationName);
27
+ }
36
28
  };
37
29
 
38
30
  const loadAndCheck = async (illustrationName) => {
39
- const data = await loadIllustration(illustrationName);
40
- return data;
31
+ const data = await loadIllustration(illustrationName);
32
+ return data;
41
33
  };
42
34
 
43
35
  ${availableIllustrations}.forEach((illustrationName) =>
44
- registerIllustrationLoader(\`${set}/${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
36
+ registerIllustrationLoader(\`${set}/${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
45
37
  );
46
38
  `;
47
39
  };
48
40
 
49
41
  const getMatchingFiles = async (folder, pattern) => {
50
- const dir = await fs.readdir(folder);
51
- return dir.filter((fileName) => fileName.match(pattern));
42
+ const dir = await fs.readdir(folder);
43
+ return dir.filter((fileName) => fileName.match(pattern));
52
44
  };
53
45
 
54
- const generateIllustrations = async (config) => {
55
- const { inputFolder, outputFile, collection, location, prefix, filterOut, set } = config;
46
+ const generateIllustrations = async (argv) => {
47
+ const config = {
48
+ inputFolder: argv[2],
49
+ outputFile: argv[3],
50
+ set: argv[4],
51
+ collection: argv[5],
52
+ location: argv[6],
53
+ filterOut: argv[7].slice().split(","),
54
+ };
56
55
 
57
- const normalizedInputFolder = path.normalize(inputFolder);
58
- const normalizedOutputFile = path.normalize(outputFile);
59
56
 
60
- const illustrations = await getMatchingFiles(normalizedInputFolder, /^.*\.js$/);
57
+ const { inputFolder, outputFile, collection, location, prefix, filterOut, set } = config;
61
58
 
62
- const dynamicImports = await generateDynamicImportLines(illustrations, location, filterOut);
63
- const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
59
+ const normalizedInputFolder = path.normalize(inputFolder);
60
+ const normalizedOutputFile = path.normalize(outputFile);
64
61
 
65
- const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, set, prefix);
62
+ const svgFiles = await getMatchingFiles(normalizedInputFolder, /\.svg$/);
66
63
 
67
- await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
68
- await fs.writeFile(normalizedOutputFile, contentDynamic);
64
+ const illustrations = [
65
+ ...new Set(
66
+ svgFiles
67
+ .filter(name => !name.includes("sapIllus-Patterns"))
68
+ .map(name => name.split("-").pop().replace(".svg", ""))
69
+ ),
70
+ ];
69
71
 
70
- console.log(`Generated ${normalizedOutputFile}`);
71
- };
72
+ const dynamicImports = await generateDynamicImportLines(illustrations, location, filterOut);
73
+ const contentDynamic = generateDynamicImportsFileContent(dynamicImports, JSON.stringify(illustrations), collection, set, prefix);
72
74
 
73
- // Parse configuration from command-line arguments
74
- const config = {
75
- inputFolder: process.argv[2],
76
- outputFile: process.argv[3],
77
- set: process.argv[4],
78
- collection: process.argv[5],
79
- location: process.argv[6],
80
- filterOut: process.argv.slice[7],
75
+ await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
76
+ await fs.writeFile(normalizedOutputFile, contentDynamic);
77
+
78
+ console.log("Generated illustration imports.");
81
79
  };
82
80
 
83
- // Run the generation process
84
- generateIllustrations(config).catch((error) => {
85
- console.error("Error generating illustrations:", error);
86
- });
81
+ if (require.main === module) {
82
+ generateIllustrations(process.argv)
83
+ }
84
+
85
+ exports._ui5mainFn = generateIllustrations;
@@ -32,19 +32,19 @@ localeIds.forEach(localeId => {
32
32
  `;
33
33
  }
34
34
 
35
- const generate = async () => {
35
+ const generate = async (argv) => {
36
36
 
37
37
  const packageName = JSON.parse(await fs.readFile("package.json")).name;
38
38
 
39
- const inputFolder = path.normalize(process.argv[2]);
40
- const outputFileDynamic = path.normalize(`${process.argv[3]}/i18n.${ext}`);
41
- const outputFileFetchMetaResolve = path.normalize(`${process.argv[3]}/i18n-fetch.${ext}`);
42
- const outputFileDynamicImportJSONImport = path.normalize(`${process.argv[3]}/i18n-node.${ext}`);
39
+ const inputFolder = path.normalize(argv[2]);
40
+ const outputFileDynamic = path.normalize(`${argv[3]}/i18n.${ext}`);
41
+ const outputFileFetchMetaResolve = path.normalize(`${argv[3]}/i18n-fetch.${ext}`);
42
+ const outputFileDynamicImportJSONImport = path.normalize(`${argv[3]}/i18n-node.${ext}`);
43
43
 
44
44
  // All languages present in the file system
45
45
  const files = await fs.readdir(inputFolder);
46
46
  const languages = files.map(file => {
47
- const matches = file.match(/messagebundle_(.+?).json$/);
47
+ const matches = file.match(/messagebundle_(.+?).properties$/);
48
48
  return matches ? matches[1] : undefined;
49
49
  }).filter(key => !!key);
50
50
 
@@ -79,9 +79,13 @@ const generate = async () => {
79
79
  fs.writeFile(outputFileDynamic, contentDynamic),
80
80
  fs.writeFile(outputFileFetchMetaResolve, contentFetchMetaResolve),
81
81
  fs.writeFile(outputFileDynamicImportJSONImport, contentDynamicImportJSONAttr),
82
- ]);
82
+ ]).then(() => {
83
+ console.log("Generated i18n JSON imports.");
84
+ });
83
85
  }
84
86
 
85
- generate().then(() => {
86
- console.log("Generated i18n JSON imports.");
87
- });
87
+ if (require.main === module) {
88
+ generate(process.argv)
89
+ }
90
+
91
+ exports._ui5mainFn = generate;
@@ -5,11 +5,11 @@ const assets = require("../../assets-meta.js");
5
5
  const isTypeScript = process.env.UI5_TS;
6
6
  const ext = isTypeScript ? 'ts' : 'js';
7
7
 
8
- const generate = async () => {
9
- const inputFolder = path.normalize(process.argv[2]);
10
- const outputFileDynamic = path.normalize(`${process.argv[3]}/Themes.${ext}`);
11
- const outputFileDynamicImportJSONAttr = path.normalize(`${process.argv[3]}/Themes-node.${ext}`);
12
- const outputFileFetchMetaResolve = path.normalize(`${process.argv[3]}/Themes-fetch.${ext}`);
8
+ const generate = async (argv) => {
9
+ const inputFolder = path.normalize(argv[2]);
10
+ const outputFileDynamic = path.normalize(`${argv[3]}/Themes.${ext}`);
11
+ const outputFileDynamicImportJSONAttr = path.normalize(`${argv[3]}/Themes-node.${ext}`);
12
+ const outputFileFetchMetaResolve = path.normalize(`${argv[3]}/Themes-fetch.${ext}`);
13
13
 
14
14
  // All supported optional themes
15
15
  const allThemes = assets.themes.all;
@@ -49,7 +49,7 @@ const loadAndCheck = async (themeName) => {
49
49
  };
50
50
 
51
51
  ${availableThemesArray}
52
- .forEach(themeName => registerThemePropertiesLoader(${ packageName.split("").map(c => `"${c}"`).join (" + ") }, themeName, loadAndCheck));
52
+ .forEach(themeName => registerThemePropertiesLoader(${packageName.split("").map(c => `"${c}"`).join(" + ")}, themeName, loadAndCheck));
53
53
  `;
54
54
  }
55
55
 
@@ -58,9 +58,14 @@ ${availableThemesArray}
58
58
  fs.writeFile(outputFileDynamic, contentDynamic(dynamicImportLines)),
59
59
  fs.writeFile(outputFileDynamicImportJSONAttr, contentDynamic(dynamicImportJSONAttrLines)),
60
60
  fs.writeFile(outputFileFetchMetaResolve, contentDynamic(fetchMetaResolveLines)),
61
- ]);
61
+ ]).
62
+ then(() => {
63
+ console.log("Generated themes JSON imports.");
64
+ })
62
65
  };
63
66
 
64
- generate().then(() => {
65
- console.log("Generated themes JSON imports.");
66
- });
67
+ if (require.main === module) {
68
+ generate(process.argv)
69
+ }
70
+
71
+ exports._ui5mainFn = generate;
@@ -3,14 +3,14 @@ const path = require('path');
3
3
  const PropertiesReader = require('properties-reader');
4
4
  const assets = require('../../assets-meta.js');
5
5
 
6
- const generate = async () => {
6
+ const generate = async (argv) => {
7
7
  const defaultLanguage = assets.languages.default;
8
8
 
9
- const messageBundle = path.normalize(`${process.argv[2]}/messagebundle.properties`);
10
- const messageBundleDefaultLanguage = path.normalize(`${process.argv[2]}/messagebundle_${defaultLanguage}.properties`);
9
+ const messageBundle = path.normalize(`${argv[2]}/messagebundle.properties`);
10
+ const messageBundleDefaultLanguage = path.normalize(`${argv[2]}/messagebundle_${defaultLanguage}.properties`);
11
11
  const tsMode = process.env.UI5_TS === "true"; // In Typescript mode, we output .ts files and set the required types, otherwise - output pure .js files
12
12
 
13
- const outputFile = path.normalize(`${process.argv[3]}/i18n-defaults.${tsMode ? "ts": "js"}`);
13
+ const outputFile = path.normalize(`${argv[3]}/i18n-defaults.${tsMode ? "ts" : "js"}`);
14
14
 
15
15
  if (!messageBundle || !outputFile) {
16
16
  return;
@@ -76,8 +76,13 @@ export {${textKeys.join()}};`;
76
76
 
77
77
  await fs.mkdir(path.dirname(outputFile), { recursive: true });
78
78
  await fs.writeFile(outputFile, getOutputFileContent(properties, defaultLanguageProperties));
79
+
80
+
81
+ console.log("i18n default file generated.")
79
82
  };
80
83
 
81
- generate().then(() => {
82
- console.log("i18n default file generated.");
83
- });
84
+ if (require.main === module) {
85
+ generate(process.argv)
86
+ }
87
+
88
+ exports._ui5mainFn = generate;
@@ -14,10 +14,7 @@ const assets = require('../../assets-meta.js');
14
14
 
15
15
  const allLanguages = assets.languages.all;
16
16
 
17
- const messagesBundles = path.normalize(`${process.argv[2]}/messagebundle_*.properties`);
18
- const messagesJSONDist = path.normalize(`${process.argv[3]}`);
19
-
20
- const convertToJSON = async (file) => {
17
+ const convertToJSON = async (file, distPath) => {
21
18
  const properties = PropertiesReader(file)._properties;
22
19
  const filename = path.basename(file, path.extname(file));
23
20
  const language = filename.match(/^messagebundle_(.*?)$/)[1];
@@ -25,19 +22,26 @@ const convertToJSON = async (file) => {
25
22
  console.log("Not supported language: ", language);
26
23
  return;
27
24
  }
28
- const outputFile = path.normalize(`${messagesJSONDist}/${filename}.json`);
25
+ const outputFile = path.normalize(`${distPath}/${filename}.json`);
29
26
 
30
27
  return fs.writeFile(outputFile, JSON.stringify(properties));
31
28
  // console.log(`[i18n]: "${filename}.json" has been generated!`);
32
29
  };
33
30
 
34
- const generate = async () => {
31
+ const generate = async (agrv) => {
35
32
  const { globby } = await import("globby");
33
+ const messagesBundles = path.normalize(`${agrv[2]}/messagebundle_*.properties`);
34
+ const messagesJSONDist = path.normalize(`${agrv[3]}`);
36
35
  await fs.mkdir(messagesJSONDist, { recursive: true });
37
36
  const files = await globby(messagesBundles.replace(/\\/g, "/"));
38
- return Promise.all(files.map(convertToJSON));
37
+ return Promise.all(files.map(file => convertToJSON(file, messagesJSONDist)))
38
+ .then(() => {
39
+ console.log("Message bundle JSON files generated.");
40
+ });
39
41
  };
40
42
 
41
- generate().then(() => {
42
- console.log("Message bundle JSON files generated.");
43
- });
43
+ if (require.main === module) {
44
+ generate(process.argv)
45
+ }
46
+
47
+ exports._ui5mainFn = generate;