@ui5/webcomponents-tools 0.0.0-fd6264051 → 0.0.0-ff1549e7b

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +375 -0
  2. package/README.md +5 -6
  3. package/assets-meta.js +1 -0
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +34 -0
  6. package/components-package/nps.js +87 -58
  7. package/components-package/postcss.components.js +13 -13
  8. package/components-package/postcss.themes.js +26 -16
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +401 -369
  11. package/components-package/wdio.sync.js +10 -2
  12. package/icons-collection/nps.js +8 -11
  13. package/lib/copy-and-watch/index.js +24 -1
  14. package/lib/copy-list/index.js +17 -17
  15. package/lib/create-icons/index.js +124 -72
  16. package/lib/create-illustrations/index.js +101 -90
  17. package/lib/create-new-component/index.js +71 -104
  18. package/lib/create-new-component/jsFileContentTemplate.js +73 -0
  19. package/lib/create-new-component/tsFileContentTemplate.js +80 -0
  20. package/lib/dev-server/dev-server.js +66 -0
  21. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  22. package/lib/esm-abs-to-rel/index.js +13 -9
  23. package/lib/generate-custom-elements-manifest/index.js +327 -0
  24. package/lib/generate-js-imports/illustrations.js +72 -0
  25. package/lib/generate-json-imports/i18n.js +38 -31
  26. package/lib/generate-json-imports/themes.js +31 -24
  27. package/lib/hbs2lit/src/compiler.js +24 -4
  28. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  29. package/lib/hbs2lit/src/litVisitor2.js +85 -22
  30. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  31. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
  32. package/lib/hbs2ui5/index.js +56 -23
  33. package/lib/i18n/defaults.js +65 -57
  34. package/lib/i18n/toJSON.js +12 -11
  35. package/lib/jsdoc/configTypescript.json +29 -0
  36. package/lib/jsdoc/plugin.js +32 -0
  37. package/lib/jsdoc/preprocess.js +146 -0
  38. package/lib/jsdoc/template/publish.js +9 -1
  39. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  40. package/lib/postcss-css-to-esm/index.js +51 -6
  41. package/lib/postcss-css-to-json/index.js +12 -1
  42. package/lib/postcss-p/postcss-p.mjs +14 -0
  43. package/lib/replace-global-core/index.js +13 -8
  44. package/lib/scoping/get-all-tags.js +1 -8
  45. package/lib/scoping/scope-test-pages.js +1 -1
  46. package/lib/test-runner/test-runner.js +71 -0
  47. package/package.json +27 -26
  48. package/components-package/rollup-plugins/empty-module.js +0 -15
  49. package/components-package/rollup.js +0 -239
  50. package/lib/documentation/index.js +0 -165
  51. package/lib/documentation/templates/api-component-since.js +0 -3
  52. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  53. package/lib/documentation/templates/api-events-section.js +0 -35
  54. package/lib/documentation/templates/api-methods-section.js +0 -26
  55. package/lib/documentation/templates/api-properties-section.js +0 -42
  56. package/lib/documentation/templates/api-slots-section.js +0 -28
  57. package/lib/documentation/templates/template.js +0 -39
  58. package/lib/hash/config.js +0 -10
  59. package/lib/hash/generate.js +0 -19
  60. package/lib/hash/upToDate.js +0 -31
  61. package/lib/polyfill-placeholder/index.js +0 -5
  62. package/lib/serve/index.js +0 -46
  63. package/lib/serve/serve.json +0 -3
  64. package/package-lock.json +0 -48
@@ -50,13 +50,21 @@ exports.config = {
50
50
  // maxInstances can get overwritten per capability. So if you have an in-house Selenium
51
51
  // grid with only 5 firefox instances available you can make sure that not more than
52
52
  // 5 instances get started at a time.
53
- maxInstances: process.env.TRAVIS ? 1 : 5,
53
+ maxInstances: 5,
54
54
  //
55
55
  browserName: 'chrome',
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: ['--headless', '--disable-gpu'],
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
  }],
@@ -1,9 +1,4 @@
1
1
  const path = require("path");
2
- const resolve = require("resolve");
3
-
4
- const generateHash = resolve.sync("@ui5/webcomponents-tools/lib/hash/generate.js");
5
- const hashIsUpToDate = resolve.sync("@ui5/webcomponents-tools/lib/hash/upToDate.js");
6
- const UP_TO_DATE = `node "${hashIsUpToDate}" dist/ hash.txt && echo "Up to date."`;
7
2
 
8
3
  const LIB = path.join(__dirname, `../lib/`);
9
4
 
@@ -26,7 +21,7 @@ const copyIconAssetsCommand = (options) => {
26
21
  return {
27
22
  default: "nps copy.json-imports copy.icon-collection",
28
23
  "json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
29
- "icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" dist/generated/assets/`,
24
+ "icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" src/generated/assets/`,
30
25
  }
31
26
  }
32
27
 
@@ -37,7 +32,7 @@ const copyIconAssetsCommand = (options) => {
37
32
 
38
33
  options.versions.forEach((v) => {
39
34
  command.default += ` copy.icon-collection${v}`;
40
- command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" dist/generated/assets/${v}/`;
35
+ command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
41
36
  });
42
37
 
43
38
  return command;
@@ -46,15 +41,17 @@ const copyIconAssetsCommand = (options) => {
46
41
  const getScripts = (options) => {
47
42
  const createJSImportsCmd = createIconImportsCommand(options);
48
43
  const copyAssetsCmd = copyIconAssetsCommand(options);
44
+ const tsCommand = options.typescript ? "tsc" : "";
45
+ const tsCrossEnv = options.typescript ? "cross-env UI5_TS=true" : "";
49
46
 
50
47
  const scripts = {
51
- clean: "rimraf dist",
48
+ clean: "rimraf dist && rimraf src/generated",
52
49
  copy: copyAssetsCmd,
53
50
  build: {
54
- default: `${UP_TO_DATE} || nps clean copy build.i18n build.icons build.jsonImports hash`,
51
+ default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
55
52
  i18n: {
56
53
  default: "nps build.i18n.defaultsjs build.i18n.json",
57
- defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n dist/generated/i18n`,
54
+ defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
58
55
  json: `mkdirp dist/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
59
56
  },
60
57
  jsonImports: {
@@ -63,7 +60,7 @@ const getScripts = (options) => {
63
60
  },
64
61
  icons: createJSImportsCmd,
65
62
  },
66
- hash: `node "${generateHash}" dist/ hash.txt`,
63
+ typescript: tsCommand,
67
64
  };
68
65
 
69
66
  return scripts;
@@ -1,9 +1,32 @@
1
+ /*
2
+ MIT License
3
+
4
+ Copyright (c) 2017
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+
1
25
  const fs = require('fs');
2
26
  const path = require('path');
3
27
  const chokidar = require('chokidar');
4
28
  const glob = require('glob');
5
29
  const globParent = require('glob-parent');
6
- require('colors');
7
30
 
8
31
  /* CODE */
9
32
 
@@ -1,28 +1,28 @@
1
- const fs = require("fs");
1
+ const fs = require("fs").promises;
2
2
  const path = require("path");
3
- const mkdirp = require("mkdirp");
4
3
 
5
4
  const fileList = process.argv[2];
6
5
  const dest = process.argv[3];
7
- const src = "../../node_modules/@openui5/sap.ui.core/src/";
6
+ const src = "@openui5/sap.ui.core/src/";
8
7
 
9
- const filesToCopy = fs.readFileSync(fileList).toString();
10
- // console.log(filesToCopy);
8
+ const generate = async () => {
9
+ const filesToCopy = (await fs.readFile(fileList)).toString();
10
+ // console.log(filesToCopy);
11
11
 
12
- // Support full-line comments starting with # in the used-modules.txt file
13
- const shouldCopy = file => file.length && !file.startsWith("#");
12
+ // Support full-line comments starting with # in the used-modules.txt file
13
+ const shouldCopy = file => file.length && !file.startsWith("#");
14
14
 
15
- const trimFile = file => file.trim();
15
+ const trimFile = file => file.trim();
16
16
 
17
- filesToCopy.split("\n").map(trimFile).filter(shouldCopy).forEach(async moduleName => {
18
- const srcPath = path.join(src, moduleName);
19
- const destPath = path.join(dest, moduleName);
17
+ return filesToCopy.split("\n").map(trimFile).filter(shouldCopy).map(async moduleName => {
18
+ const srcPath = require.resolve(path.join(src, moduleName), {paths: [process.cwd()]});
19
+ const destPath = path.join(dest, moduleName);
20
20
 
21
- await mkdirp(path.dirname(destPath));
22
- fs.copyFile(srcPath, destPath, (err) => {
23
- if (err) {
24
- throw err;
25
- }
26
- console.log(`${destPath} created.`);
21
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
22
+ return fs.copyFile(srcPath, destPath);
27
23
  });
24
+ };
25
+
26
+ generate().then(() => {
27
+ console.log("Files copied.");
28
28
  });
@@ -1,72 +1,124 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const mkdirp = require("mkdirp");
4
-
5
- const collectionName = process.argv[2] || "SAP-icons";
6
- const collectionVersion = process.argv[3];
7
- const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
8
- const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
9
-
10
- mkdirp.sync(destDir);
11
-
12
- const iconTemplate = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
13
-
14
- const name = "${name}";
15
- const pathData = "${pathData}";
16
- const ltr = ${ltr};
17
- const collection = "${collection}";
18
- const packageName = "${packageName}";
19
-
20
- registerIcon(name, { pathData, ltr, collection, packageName });
21
-
22
- export default { pathData };`;
23
-
24
-
25
- const iconAccTemplate = (name, pathData, ltr, accData, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
26
- import { ${accData.key} } from "../generated/i18n/i18n-defaults.js";
27
-
28
- const name = "${name}";
29
- const pathData = "${pathData}";
30
- const ltr = ${ltr};
31
- const accData = ${accData.key};
32
- const collection = "${collection}";
33
- const packageName = "${packageName}";
34
-
35
- registerIcon(name, { pathData, ltr, accData, collection, packageName });
36
-
37
- export default { pathData, accData };`;
38
-
39
-
40
-
41
- const collectionTemplate = (name) => `import { isThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
42
- import pathDataV4 from "./v5/${name}.js";
43
- import pathDataV5 from "./v4/${name}.js";
44
- const pathData = isThemeFamily("sap_horizon") ? pathDataV5 : pathDataV4;
45
- export default { pathData };`;
46
-
47
-
48
- const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
49
- <path d="${pathData}"/>
50
- </svg>`;
51
-
52
- const createIcons = (file) => {
53
- const json = JSON.parse(fs.readFileSync(file));
54
-
55
- for (let name in json.data) {
56
- const iconData = json.data[name];
57
- const pathData = iconData.path;
58
- const ltr = !!iconData.ltr;
59
- const acc = iconData.acc;
60
-
61
- const content = acc ? iconAccTemplate(name, pathData, ltr, acc, json.collection, json.packageName) : iconTemplate(name, pathData, ltr, json.collection, json.packageName);
62
-
63
- fs.writeFileSync(path.join(destDir, `${name}.js`), content);
64
- fs.writeFileSync(path.join(destDir, `${name}.svg`), svgTemplate(pathData));
65
-
66
- if (json.version) {
67
- fs.writeFileSync(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name));
68
- }
69
- }
70
- };
71
-
72
- createIcons(srcFile);
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const collectionName = process.argv[2] || "SAP-icons-v4";
5
+ const collectionVersion = process.argv[3];
6
+ const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
7
+ const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
8
+
9
+ const iconTemplate = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
10
+
11
+ const name = "${name}";
12
+ const pathData = "${pathData}";
13
+ const ltr = ${ltr};
14
+ const accData = null;
15
+ const collection = "${collection}";
16
+ const packageName = "${packageName}";
17
+
18
+ registerIcon(name, { pathData, ltr, collection, packageName });
19
+
20
+ export default "${collection}/${name}";
21
+ export { pathData, ltr, accData };`;
22
+
23
+
24
+ const iconAccTemplate = (name, pathData, ltr, accData, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
25
+ import { ${accData.key} } from "../generated/i18n/i18n-defaults.js";
26
+
27
+ const name = "${name}";
28
+ const pathData = "${pathData}";
29
+ const ltr = ${ltr};
30
+ const accData = ${accData.key};
31
+ const collection = "${collection}";
32
+ const packageName = "${packageName}";
33
+
34
+ registerIcon(name, { pathData, ltr, accData, collection, packageName });
35
+
36
+ export default "${collection}/${name}";
37
+ export { pathData, ltr, accData };`;
38
+
39
+
40
+
41
+ const collectionTemplate = (name, versions, fullName) => `import { isLegacyThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
42
+ import { pathData as pathData${versions[0]}, ltr, accData } from "./${versions[0]}/${name}.js";
43
+ import { pathData as pathData${versions[1]} } from "./${versions[1]}/${name}.js";
44
+
45
+ const pathData = isLegacyThemeFamily() ? pathData${versions[0]} : pathData${versions[1]};
46
+
47
+ export default "${fullName}";
48
+ export { pathData, ltr, accData };`;
49
+
50
+
51
+ const typeDefinitionTemplate = (name, accData, collection) => `declare const pathData: string;
52
+ declare const ltr: boolean;
53
+ declare const accData: ${accData ? '{ key: string; defaultText: string; }' : null}
54
+ declare const _default: "${collection}/${name}";
55
+
56
+ export default _default;
57
+ export { pathData, ltr, accData };`
58
+
59
+ const collectionTypeDefinitionTemplate = (name, accData) => `declare const pathData: string;
60
+ declare const ltr: boolean;
61
+ declare const accData: ${accData ? '{ key: string; defaultText: string; }' : null}
62
+ declare const _default: "${name}";
63
+
64
+ export default _default;
65
+ export { pathData, ltr, accData };`
66
+
67
+
68
+ const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
69
+ <path d="${pathData}"/>
70
+ </svg>`;
71
+
72
+ const createIcons = async (file) => {
73
+ await fs.mkdir(destDir, { recursive: true });
74
+
75
+ const json = JSON.parse(await fs.readFile(file));
76
+
77
+ const promises = [];
78
+ for (let name in json.data) {
79
+ const iconData = json.data[name];
80
+ const pathData = iconData.path;
81
+ const ltr = !!iconData.ltr;
82
+ const acc = iconData.acc;
83
+ const packageName = json.packageName;
84
+ const collection = json.collection;
85
+
86
+ const content = acc ? iconAccTemplate(name, pathData, ltr, acc, collection, packageName) : iconTemplate(name, pathData, ltr, collection, packageName);
87
+
88
+ promises.push(fs.writeFile(path.join(destDir, `${name}.js`), content));
89
+ promises.push(fs.writeFile(path.join(destDir, `${name}.svg`), svgTemplate(pathData)));
90
+ promises.push(fs.writeFile(path.join(destDir, `${name}.d.ts`), typeDefinitionTemplate(name, acc, collection)));
91
+
92
+ // For versioned icons collections, the script creates top level (unversioned) module that internally imports the versioned ones.
93
+ // For example, the top level "@ui5/ui5-webcomponents-icons/dist/accept.js" imports:
94
+ // - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
95
+ // - "@ui5/ui5-webcomponents-icons/dist/v4/accept.js"
96
+
97
+ if (json.version) {
98
+ // The exported value from the top level (unversioned) icon module depends on whether the collection is the default,
99
+ // to add or not the collection name to the exported value:
100
+ // For the default collection (SAPIcons) we export just the icon name - "export default { 'accept' }"
101
+ // For non-default collections (SAPTNTIcons and SAPBSIcons) we export the full name - "export default { 'tnt/actor' }"
102
+ const effectiveName = isDefaultCollection(collection) ? name : getUnversionedFullIconName(name, collection);
103
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name, json.versions, effectiveName)));
104
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.d.ts`), collectionTypeDefinitionTemplate(effectiveName, acc)));
105
+ }
106
+ }
107
+
108
+ return Promise.all(promises);
109
+ };
110
+
111
+ const isDefaultCollection = collectionName => collectionName === "SAP-icons-v4" || collectionName === "SAP-icons-v5";
112
+ const getUnversionedFullIconName = (name, collection) => `${getUnversionedCollectionName(collection)}/${name}`;
113
+ const getUnversionedCollectionName = collectionName => CollectionVersionedToUnversionedMap[collectionName] || collectionName;
114
+
115
+ const CollectionVersionedToUnversionedMap = {
116
+ "tnt-v2": "tnt",
117
+ "tnt-v3": "tnt",
118
+ "business-suite-v1": "business-suite",
119
+ "business-suite-v2": "business-suite",
120
+ };
121
+
122
+ createIcons(srcFile).then(() => {
123
+ console.log("Icons created.");
124
+ });
@@ -1,87 +1,90 @@
1
- const fs = require("fs");
1
+ const fs = require("fs").promises;
2
2
  const path = require("path");
3
- const mkdirp = require("mkdirp");
4
3
 
5
4
  if (process.argv.length < 7) {
6
- return;
5
+ throw new Error("Not enough arguments");
7
6
  }
8
7
 
9
- const ORIGINAL_TEXTS = {
10
- UnableToLoad: "UnableToLoad",
11
- UnableToUpload: "UnableToUpload",
12
- NoActivities: "NoActivities",
13
- BeforeSearch: "BeforeSearch",
14
- NoSearchResults: "NoSearchResults",
15
- NoEntries: "NoEntries",
16
- NoData: "NoData",
17
- NoNotifications: "NoNotifications",
18
- BalloonSky: "BalloonSky",
19
- SuccessScreen: "SuccessScreen",
20
- NoMail: "NoMail",
21
- NoSavedItems: "NoSavedItems",
22
- NoTasks: "NoTasks"
23
- };
24
-
25
- const FALLBACK_TEXTS = {
26
- ReloadScreen: ORIGINAL_TEXTS.UnableToLoad,
27
- Connection: ORIGINAL_TEXTS.UnableToLoad,
28
- ErrorScreen: ORIGINAL_TEXTS.UnableToUpload,
29
- EmptyCalendar: ORIGINAL_TEXTS.NoActivities,
30
- SearchEarth: ORIGINAL_TEXTS.BeforeSearch,
31
- SearchFolder: ORIGINAL_TEXTS.NoSearchResults,
32
- EmptyList: ORIGINAL_TEXTS.NoEntries,
33
- Tent: ORIGINAL_TEXTS.NoData,
34
- SleepingBell: ORIGINAL_TEXTS.NoNotifications,
35
- SimpleBalloon: ORIGINAL_TEXTS.BalloonSky,
36
- SimpleBell: ORIGINAL_TEXTS.NoNotifications,
37
- SimpleCalendar: ORIGINAL_TEXTS.NoActivities,
38
- SimpleCheckMark: ORIGINAL_TEXTS.SuccessScreen,
39
- SimpleConnection: ORIGINAL_TEXTS.UnableToLoad,
40
- SimpleEmptyDoc: ORIGINAL_TEXTS.NoData,
41
- SimpleEmptyList: ORIGINAL_TEXTS.NoEntries,
42
- SimpleError: ORIGINAL_TEXTS.UnableToUpload,
43
- SimpleMagnifier: ORIGINAL_TEXTS.BeforeSearch,
44
- SimpleMail: ORIGINAL_TEXTS.NoMail,
45
- SimpleNoSavedItems: ORIGINAL_TEXTS.NoSavedItems,
46
- SimpleNotFoundMagnifier: ORIGINAL_TEXTS.NoSearchResults,
47
- SimpleReload: ORIGINAL_TEXTS.UnableToLoad,
48
- SimpleTask: ORIGINAL_TEXTS.NoTasks,
49
- SuccessBalloon: ORIGINAL_TEXTS.BalloonSky,
50
- SuccessCheckMark: ORIGINAL_TEXTS.SuccessScreen,
51
- SuccessHighFive: ORIGINAL_TEXTS.BalloonSky
52
- };
53
-
54
- const srcPath = process.argv[2];
55
- const defaultText = process.argv[3] === "true";
56
- const illustrationsPrefix = process.argv[4];
57
- const illustrationSet = process.argv[5];
58
- const destPath = process.argv[6];
59
- const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
8
+ const generate = async () => {
9
+
10
+ const ORIGINAL_TEXTS = {
11
+ UnableToLoad: "UnableToLoad",
12
+ UnableToUpload: "UnableToUpload",
13
+ NoActivities: "NoActivities",
14
+ BeforeSearch: "BeforeSearch",
15
+ NoSearchResults: "NoSearchResults",
16
+ NoEntries: "NoEntries",
17
+ NoData: "NoData",
18
+ NoNotifications: "NoNotifications",
19
+ BalloonSky: "BalloonSky",
20
+ SuccessScreen: "SuccessScreen",
21
+ NoMail: "NoMail",
22
+ NoSavedItems: "NoSavedItems",
23
+ NoTasks: "NoTasks"
24
+ };
25
+
26
+ const FALLBACK_TEXTS = {
27
+ ReloadScreen: ORIGINAL_TEXTS.UnableToLoad,
28
+ Connection: ORIGINAL_TEXTS.UnableToLoad,
29
+ ErrorScreen: ORIGINAL_TEXTS.UnableToUpload,
30
+ EmptyCalendar: ORIGINAL_TEXTS.NoActivities,
31
+ SearchEarth: ORIGINAL_TEXTS.BeforeSearch,
32
+ SearchFolder: ORIGINAL_TEXTS.NoSearchResults,
33
+ EmptyList: ORIGINAL_TEXTS.NoEntries,
34
+ Tent: ORIGINAL_TEXTS.NoData,
35
+ SleepingBell: ORIGINAL_TEXTS.NoNotifications,
36
+ SimpleBalloon: ORIGINAL_TEXTS.BalloonSky,
37
+ SimpleBell: ORIGINAL_TEXTS.NoNotifications,
38
+ SimpleCalendar: ORIGINAL_TEXTS.NoActivities,
39
+ SimpleCheckMark: ORIGINAL_TEXTS.SuccessScreen,
40
+ SimpleConnection: ORIGINAL_TEXTS.UnableToLoad,
41
+ SimpleEmptyDoc: ORIGINAL_TEXTS.NoData,
42
+ SimpleEmptyList: ORIGINAL_TEXTS.NoEntries,
43
+ SimpleError: ORIGINAL_TEXTS.UnableToUpload,
44
+ SimpleMagnifier: ORIGINAL_TEXTS.BeforeSearch,
45
+ SimpleMail: ORIGINAL_TEXTS.NoMail,
46
+ SimpleNoSavedItems: ORIGINAL_TEXTS.NoSavedItems,
47
+ SimpleNotFoundMagnifier: ORIGINAL_TEXTS.NoSearchResults,
48
+ SimpleReload: ORIGINAL_TEXTS.UnableToLoad,
49
+ SimpleTask: ORIGINAL_TEXTS.NoTasks,
50
+ SuccessBalloon: ORIGINAL_TEXTS.BalloonSky,
51
+ SuccessCheckMark: ORIGINAL_TEXTS.SuccessScreen,
52
+ SuccessHighFive: ORIGINAL_TEXTS.BalloonSky
53
+ };
54
+
55
+ const srcPath = process.argv[2];
56
+ const defaultText = process.argv[3] === "true";
57
+ const illustrationsPrefix = process.argv[4];
58
+ const illustrationSet = process.argv[5];
59
+ const destPath = process.argv[6];
60
+ const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
60
61
  // collect each illustration name because each one should have Sample.js file
61
- const fileNames = new Set();
62
-
63
- const svgImportTemplate = svgContent => { return `export default \`${svgContent}\`;`};
64
- const svgToJs = fileName => {
65
- const svg = fs.readFileSync(path.join(srcPath, fileName), { encoding: "utf-8" });
66
- const fileContent = svgImportTemplate(svg);
67
- fileName = fileName.replace(/\.svg$/, ".js");
68
-
69
- fs.writeFileSync(path.join(destPath, fileName), fileContent);
70
- };
71
- const illustrationImportTemplate = illustrationName => {
72
- let illustrationNameForTranslation = illustrationName;
73
-
74
- if (defaultText) {
75
- if (FALLBACK_TEXTS[illustrationNameForTranslation]) {
76
- illustrationNameForTranslation = FALLBACK_TEXTS[illustrationNameForTranslation];
77
- } else if (illustrationName.indexOf("_v") !== -1) {
78
- illustrationNameForTranslation = illustrationNameForTranslation.substr(0, illustrationNameForTranslation.indexOf('_v'));
62
+ const fileNames = new Set();
63
+
64
+ const svgImportTemplate = svgContent => {
65
+ return `export default \`${svgContent}\`;`
66
+ };
67
+ const svgToJs = async fileName => {
68
+ const svg = await fs.readFile(path.join(srcPath, fileName), {encoding: "utf-8"});
69
+ const fileContent = svgImportTemplate(svg);
70
+ fileName = fileName.replace(/\.svg$/, ".js");
71
+
72
+ return fs.writeFile(path.join(destPath, fileName), fileContent);
73
+ };
74
+ const illustrationImportTemplate = illustrationName => {
75
+ let illustrationNameForTranslation = illustrationName;
76
+
77
+ if (defaultText) {
78
+ if (FALLBACK_TEXTS[illustrationNameForTranslation]) {
79
+ illustrationNameForTranslation = FALLBACK_TEXTS[illustrationNameForTranslation];
80
+ } else if (illustrationName.indexOf("_v") !== -1) {
81
+ illustrationNameForTranslation = illustrationNameForTranslation.substr(0, illustrationNameForTranslation.indexOf('_v'));
82
+ }
79
83
  }
80
- }
81
84
 
82
- const illustrationNameUpperCase = illustrationNameForTranslation.toUpperCase();
83
-
84
- return defaultText ? `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
85
+ const illustrationNameUpperCase = illustrationNameForTranslation.toUpperCase();
86
+
87
+ return defaultText ? `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
85
88
  import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
86
89
  import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
87
90
  import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
@@ -109,7 +112,7 @@ export {
109
112
  sceneSvg,
110
113
  spotSvg,
111
114
  };` :
112
- `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
115
+ `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
113
116
  import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
114
117
  import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
115
118
  import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
@@ -129,22 +132,30 @@ export {
129
132
  sceneSvg,
130
133
  spotSvg,
131
134
  };`
132
- };
135
+ };
136
+
137
+ await fs.mkdir(destPath, { recursive: true });
133
138
 
134
- mkdirp.sync(destPath);
139
+ const illustrationFileNames = await fs.readdir(path.normalize(srcPath));
135
140
 
136
- const illustrationFileNames = fs.readdirSync(path.normalize(srcPath));
141
+ // convert SVG to JS imports
142
+ const promises = [];
143
+ illustrationFileNames.forEach(illustration => {
144
+ if (fileNamePattern.test(illustration)) {
145
+ let [fileName, illustrationName] = illustration.match(fileNamePattern);
137
146
 
138
- // convert SVG to JS imports
139
- illustrationFileNames.forEach(illustration => {
140
- if (fileNamePattern.test(illustration)) {
141
- let [fileName, illustrationName] = illustration.match(fileNamePattern);
147
+ promises.push(svgToJs(fileName));
148
+ fileNames.add(illustrationName);
149
+ }
150
+ });
142
151
 
143
- svgToJs(fileName);
144
- fileNames.add(illustrationName);
152
+ for (let illustrationName of fileNames) {
153
+ promises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
145
154
  }
146
- });
147
155
 
148
- for (let illustrationName of fileNames) {
149
- fs.writeFileSync(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName));
150
- }
156
+ return Promise.all(promises);
157
+ };
158
+
159
+ generate().then(() => {
160
+ console.log("Illustrations generated.");
161
+ });