@ui5/webcomponents-tools 1.3.1 → 1.4.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.
@@ -1,74 +1,66 @@
1
- const fs = require('fs');
1
+ const fs = require('fs').promises;
2
2
  const path = require('path');
3
3
  const PropertiesReader = require('properties-reader');
4
- const mkdirp = require("mkdirp");
5
4
  const assets = require('../../assets-meta.js');
6
5
 
7
- const defaultLanguage = assets.languages.default;
6
+ const generate = async () => {
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`);
11
- const outputFile = path.normalize(`${process.argv[3]}/i18n-defaults.js`);
9
+ const messageBundle = path.normalize(`${process.argv[2]}/messagebundle.properties`);
10
+ const messageBundleDefaultLanguage = path.normalize(`${process.argv[2]}/messagebundle_${defaultLanguage}.properties`);
11
+ const outputFile = path.normalize(`${process.argv[3]}/i18n-defaults.js`);
12
12
 
13
- if (!messageBundle || !outputFile) {
14
- return;
15
- }
13
+ if (!messageBundle || !outputFile) {
14
+ return;
15
+ }
16
16
 
17
- const properties = PropertiesReader(messageBundle)._properties;
17
+ const properties = PropertiesReader(messageBundle)._properties;
18
18
 
19
- let defaultLanguageProperties;
20
- try {
21
- defaultLanguageProperties = PropertiesReader(messageBundleDefaultLanguage)._properties;
22
- }
23
- catch (e) {}
19
+ let defaultLanguageProperties;
20
+ try {
21
+ defaultLanguageProperties = PropertiesReader(messageBundleDefaultLanguage)._properties;
22
+ } catch (e) {
23
+ }
24
24
 
25
25
 
26
- /*
27
- * Returns the single text object to enable single export.
28
- *
29
- * Example:
30
- * const ARIA_LABEL_CARD_CONTENT = {
31
- * key: "ARIA_LABEL_CARD_CONTENT",
32
- * defaultText: "Card Content",
33
- * };
34
- */
35
- const getTextInfo = (key, value, defaultLanguageValue) => {
36
- let effectiveValue = defaultLanguageValue || value;
37
- effectiveValue = effectiveValue.replace(/\"/g, "\\\""); // escape double quotes in translations
26
+ /*
27
+ * Returns the single text object to enable single export.
28
+ *
29
+ * Example:
30
+ * const ARIA_LABEL_CARD_CONTENT = {
31
+ * key: "ARIA_LABEL_CARD_CONTENT",
32
+ * defaultText: "Card Content",
33
+ * };
34
+ */
35
+ const getTextInfo = (key, value, defaultLanguageValue) => {
36
+ let effectiveValue = defaultLanguageValue || value;
37
+ effectiveValue = effectiveValue.replace(/\"/g, "\\\""); // escape double quotes in translations
38
38
 
39
- return `const ${key} = {key: "${key}", defaultText: "${effectiveValue}"};`;
40
- };
39
+ return `const ${key} = {key: "${key}", defaultText: "${effectiveValue}"};`;
40
+ };
41
41
 
42
- /*
43
- * Returns the complete content of i18n-defaults.js file:
44
- * (1) the single text objects
45
- * (2) the export statement at the end of the file
46
- *
47
- * Example:
48
- * export {
49
- * ARIA_LABEL_CARD_CONTENT,
50
- * }
51
- */
52
- const getOutputFileContent = (properties, defaultLanguageProperties) => {
53
- const textKeys = Object.keys(properties);
54
- const texts = textKeys.map(prop => getTextInfo(prop, properties[prop], defaultLanguageProperties && defaultLanguageProperties[prop])).join('');
42
+ /*
43
+ * Returns the complete content of i18n-defaults.js file:
44
+ * (1) the single text objects
45
+ * (2) the export statement at the end of the file
46
+ *
47
+ * Example:
48
+ * export {
49
+ * ARIA_LABEL_CARD_CONTENT,
50
+ * }
51
+ */
52
+ const getOutputFileContent = (properties, defaultLanguageProperties) => {
53
+ const textKeys = Object.keys(properties);
54
+ const texts = textKeys.map(prop => getTextInfo(prop, properties[prop], defaultLanguageProperties && defaultLanguageProperties[prop])).join('');
55
55
 
56
- return `${texts}
56
+ return `${texts}
57
57
  export {${textKeys.join()}};`;
58
- };
59
-
60
- /*
61
- * Writes the i18n-defaults.js.
62
- */
63
- const writeI18nDefaultsFile = (file, content) => {
64
- fs.writeFile(file, content, (err) => {
65
- if (err) {
66
- return console.log(err);
67
- }
58
+ };
68
59
 
69
- console.log(`[i18n]: "${file}" file has been created`);
70
- });
60
+ await fs.mkdir(path.dirname(outputFile), { recursive: true });
61
+ await fs.writeFile(outputFile, getOutputFileContent(properties, defaultLanguageProperties));
71
62
  };
72
63
 
73
- mkdirp.sync(path.dirname(outputFile));
74
- writeI18nDefaultsFile(outputFile, getOutputFileContent(properties, defaultLanguageProperties));
64
+ generate().then(() => {
65
+ console.log("i18n default file generated.");
66
+ });
@@ -8,18 +8,16 @@
8
8
  * The 2nd param './../dist/generated/assets/i18n' is where the JSON files would be written to.
9
9
  */
10
10
  const path = require("path");
11
- const glob = require("glob");
12
11
  const PropertiesReader = require('properties-reader');
13
- const fs = require('fs');
12
+ const fs = require('fs').promises;
14
13
  const assets = require('../../assets-meta.js');
15
- const mkdirp = require("mkdirp");
16
14
 
17
15
  const allLanguages = assets.languages.all;
18
16
 
19
17
  const messagesBundles = path.normalize(`${process.argv[2]}/messagebundle_*.properties`);
20
18
  const messagesJSONDist = path.normalize(`${process.argv[3]}`);
21
19
 
22
- const convertToJSON = (file) => {
20
+ const convertToJSON = async (file) => {
23
21
  const properties = PropertiesReader(file)._properties;
24
22
  const filename = path.basename(file, path.extname(file));
25
23
  const language = filename.match(/^messagebundle_(.*?)$/)[1];
@@ -29,14 +27,17 @@ const messagesJSONDist = path.normalize(`${process.argv[3]}`);
29
27
  }
30
28
  const outputFile = path.normalize(`${messagesJSONDist}/${filename}.json`);
31
29
 
32
- fs.writeFileSync(outputFile, JSON.stringify(properties));
30
+ return fs.writeFile(outputFile, JSON.stringify(properties));
33
31
  // console.log(`[i18n]: "${filename}.json" has been generated!`);
34
32
  };
35
33
 
36
- mkdirp.sync(messagesJSONDist);
37
- glob(messagesBundles, {}, (err, files) => {
38
- if (err) {
39
- return console.log("No messagebundle files found!");
40
- }
41
- files.forEach(convertToJSON);
34
+ const generate = async () => {
35
+ const { globby } = await import("globby");
36
+ await fs.mkdir(messagesJSONDist, { recursive: true });
37
+ const files = await globby(messagesBundles);
38
+ return Promise.all(files.map(convertToJSON));
39
+ };
40
+
41
+ generate().then(() => {
42
+ console.log("Message bundle JSON files generated.");
42
43
  });
@@ -1,20 +1,25 @@
1
- const fs = require("fs");
2
- const glob = require("glob");
1
+ const fs = require("fs").promises;
3
2
 
4
3
  const basePath = process.argv[2];
5
4
 
6
- const replaceGlobalCoreUsage = (srcPath) => {
5
+ const replaceGlobalCoreUsage = async (srcPath) => {
7
6
 
8
- const original = fs.readFileSync(srcPath).toString();
7
+ const original = (await fs.readFile(srcPath)).toString();
9
8
  let replaced = original.replace(/sap\.ui\.getCore\(\)/g, `Core`);
10
9
 
11
10
  if (original !== replaced) {
12
11
  replaced = `import Core from 'sap/ui/core/Core';
13
12
  ${replaced}`;
14
- fs.writeFileSync(srcPath, replaced);
13
+ return fs.writeFile(srcPath, replaced);
15
14
  }
16
15
  };
17
16
 
18
- const fileNames = glob.sync(basePath + "**/*.js");
19
- fileNames.forEach(replaceGlobalCoreUsage);
20
- console.log("Success: Replaced global core usage in:", basePath);
17
+ const generate = async () => {
18
+ const { globby } = await import("globby");
19
+ const fileNames = await globby(basePath + "**/*.js");
20
+ return Promise.all(fileNames.map(replaceGlobalCoreUsage).filter(x => !!x));
21
+ };
22
+
23
+ generate().then(() => {
24
+ console.log("Success: Replaced global core usage in:", basePath);
25
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-tools",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "UI5 Web Components: webcomponents.tools",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -21,11 +21,11 @@
21
21
  "directory": "packages/tools"
22
22
  },
23
23
  "dependencies": {
24
- "@openui5/sap.ui.core": "1.95.0",
25
24
  "@rollup/plugin-json": "^4.1.0",
26
25
  "@rollup/plugin-node-resolve": "^13.0.5",
27
26
  "@rollup/plugin-replace": "^3.0.0",
28
27
  "@wdio/cli": "^7.12.2",
28
+ "@wdio/devtools-service": "^7.19.5",
29
29
  "@wdio/dot-reporter": "^7.10.1",
30
30
  "@wdio/local-runner": "^7.12.2",
31
31
  "@wdio/mocha-framework": "^7.12.2",
@@ -44,10 +44,10 @@
44
44
  "eslint-config-airbnb-base": "^14.2.1",
45
45
  "eslint-plugin-import": "^2.22.1",
46
46
  "esprima": "^4.0.1",
47
- "folder-hash": "^4.0.1",
48
47
  "getopts": "^2.3.0",
49
48
  "glob": "^7.1.6",
50
49
  "glob-parent": "^6.0.2",
50
+ "globby": "^13.1.1",
51
51
  "handlebars": "^4.7.7",
52
52
  "is-port-reachable": "^3.1.0",
53
53
  "jsdoc": "^3.6.6",
@@ -1,10 +0,0 @@
1
- const config = {
2
- files: {
3
- exclude: ['serve.json']
4
- },
5
- folders: {
6
- exclude: ['resources']
7
- },
8
- };
9
-
10
- module.exports = config;
@@ -1,19 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const process = require("process");
4
- const { hashElement } = require("folder-hash");
5
- const config = require("./config.js");
6
-
7
- const inputDir = path.normalize(process.argv[2]);
8
- const outputFileName = path.normalize(process.argv[3]);
9
-
10
- const generateHash = async (inputDir, outputFileName) => {
11
- const result = await hashElement(inputDir, config);
12
- const hash = result.hash;
13
- fs.writeFileSync(outputFileName, hash);
14
- return hash;
15
- };
16
-
17
- generateHash(inputDir, outputFileName).then(hash => {
18
- console.log(`Generated hash: ${hash}`);
19
- });
@@ -1,31 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const process = require("process");
4
- const { hashElement } = require("folder-hash");
5
- const config = require("./config.js");
6
-
7
- const inputDir = path.normalize(process.argv[2]);
8
- const hashFileName = path.normalize(process.argv[3]);
9
-
10
- const isUpToDate = async (inputDir, hashFileName) => {
11
- // No dist/ directory or no hash file
12
- if (!fs.existsSync(inputDir) || !fs.existsSync(hashFileName)) {
13
- return false;
14
- }
15
-
16
- // Empty hash file
17
- const existingHash = `${fs.readFileSync(hashFileName)}`;
18
- if (!existingHash) {
19
- return false;
20
- }
21
-
22
- // Calculate the hash of the dist/ directory
23
- const result = await hashElement(inputDir, config);
24
- const newHash = result.hash;
25
-
26
- return newHash === existingHash;
27
- };
28
-
29
- isUpToDate(inputDir, hashFileName).then(upToDate => {
30
- process.exit(upToDate ? 0 : 1); // 0 means success (it is up to date), 1 means failure (must rebuild the dist/)
31
- });