@ui5/webcomponents-tools 0.0.0-fb61e9889 → 0.0.0-fc993d8cd

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 +357 -0
  2. package/README.md +5 -6
  3. package/assets-meta.js +6 -1
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +34 -0
  6. package/components-package/nps.js +86 -57
  7. package/components-package/postcss.components.js +13 -13
  8. package/components-package/postcss.themes.js +19 -16
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +393 -353
  11. package/components-package/wdio.sync.js +17 -1
  12. package/icons-collection/nps.js +46 -15
  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 -58
  16. package/lib/create-illustrations/index.js +107 -41
  17. package/lib/create-new-component/index.js +105 -108
  18. package/lib/create-new-component/jsFileContentTemplate.js +77 -0
  19. package/lib/create-new-component/tsFileContentTemplate.js +84 -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 +20 -3
  28. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  29. package/lib/hbs2lit/src/litVisitor2.js +56 -10
  30. package/lib/hbs2ui5/index.js +37 -21
  31. package/lib/i18n/defaults.js +65 -57
  32. package/lib/i18n/toJSON.js +12 -11
  33. package/lib/jsdoc/configTypescript.json +29 -0
  34. package/lib/jsdoc/plugin.js +41 -0
  35. package/lib/jsdoc/preprocess.js +146 -0
  36. package/lib/jsdoc/template/publish.js +21 -2
  37. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  38. package/lib/postcss-css-to-esm/index.js +53 -8
  39. package/lib/postcss-css-to-json/index.js +18 -2
  40. package/lib/postcss-p/postcss-p.mjs +14 -0
  41. package/lib/replace-global-core/index.js +13 -8
  42. package/lib/scoping/get-all-tags.js +1 -8
  43. package/lib/scoping/missing-dependencies.js +65 -0
  44. package/lib/scoping/report-tags-usage.js +28 -0
  45. package/lib/scoping/scope-test-pages.js +1 -1
  46. package/lib/test-runner/test-runner.js +71 -0
  47. package/package.json +28 -28
  48. package/components-package/rollup-plugins/empty-module.js +0 -15
  49. package/components-package/rollup.js +0 -237
  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 -40
  56. package/lib/documentation/templates/api-slots-section.js +0 -28
  57. package/lib/documentation/templates/template.js +0 -38
  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,7 +50,7 @@ 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': {
@@ -168,6 +168,21 @@ exports.config = {
168
168
  }, this);
169
169
  }, true);
170
170
 
171
+ browser.addCommand("isFocusedDeepElement", function (element) {
172
+ return browser.execute(function (elem, element, done) {
173
+ let activeElement = document.activeElement;
174
+
175
+ while (activeElement.shadowRoot) {
176
+ if (activeElement.shadowRoot.activeElement) {
177
+ activeElement = activeElement.shadowRoot.activeElement;
178
+ } else {
179
+ break;
180
+ }
181
+ }
182
+ done(element === activeElement);
183
+ }, this, element);
184
+ }, true);
185
+
171
186
  browser.addCommand("setProperty", function(property, value) {
172
187
  return browser.execute((elem, property, value) => {
173
188
  return elem[property] = value;
@@ -223,6 +238,7 @@ exports.config = {
223
238
  "isExisting",
224
239
  "isFocused",
225
240
  "isFocusedDeep", // custom
241
+ "isFocusedDeepElement", // custom
226
242
  "shadow$",
227
243
  "shadow$$",
228
244
  ];
@@ -1,35 +1,66 @@
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
 
10
- const getScripts = (options) => {
5
+ const createIconImportsCommand = (options) => {
6
+ if (!options.versions) {
7
+ return `node "${LIB}/create-icons/index.js" "${options.collectionName}"`;
8
+ }
11
9
 
12
- const scripts = {
13
- clean: "rimraf dist",
14
- copy: {
10
+ const command = { default: "nps" };
11
+ options.versions.forEach((v) => {
12
+ command.default += ` build.icons.create${v}`;
13
+ command[`create${v}`] = `node "${LIB}/create-icons/index.js" "${options.collectionName}" "${v}"`;
14
+ });
15
+
16
+ return command;
17
+ }
18
+
19
+ const copyIconAssetsCommand = (options) => {
20
+ if (!options.versions) {
21
+ return {
15
22
  default: "nps copy.json-imports copy.icon-collection",
16
23
  "json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
17
- "icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" dist/generated/assets/`
18
- },
24
+ "icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" dist/generated/assets/`,
25
+ }
26
+ }
27
+
28
+ const command = {
29
+ default: "nps copy.json-imports ",
30
+ "json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
31
+ };
32
+
33
+ options.versions.forEach((v) => {
34
+ command.default += ` copy.icon-collection${v}`;
35
+ command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" dist/generated/assets/${v}/`;
36
+ });
37
+
38
+ return command;
39
+ }
40
+
41
+ const getScripts = (options) => {
42
+ const createJSImportsCmd = createIconImportsCommand(options);
43
+ const copyAssetsCmd = copyIconAssetsCommand(options);
44
+ const tsCommand = options.typescript ? "tsc" : "";
45
+ const tsCrossEnv = options.typescript ? "cross-env UI5_TS=true" : "";
46
+
47
+ const scripts = {
48
+ clean: "rimraf dist && rimraf src/generated",
49
+ copy: copyAssetsCmd,
19
50
  build: {
20
- 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`,
21
52
  i18n: {
22
53
  default: "nps build.i18n.defaultsjs build.i18n.json",
23
- 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`,
24
55
  json: `mkdirp dist/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
25
56
  },
26
57
  jsonImports: {
27
58
  default: "mkdirp dist/generated/json-imports && nps build.jsonImports.i18n",
28
59
  i18n: `node "${LIB}/generate-json-imports/i18n.js" dist/generated/assets/i18n dist/generated/json-imports`,
29
60
  },
30
- icons: `node "${LIB}/create-icons/index.js" "${options.collectionName}"`,
61
+ icons: createJSImportsCmd,
31
62
  },
32
- hash: `node "${generateHash}" dist/ hash.txt`,
63
+ typescript: tsCommand,
33
64
  };
34
65
 
35
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,58 +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 srcFile = path.normalize(`src/${collectionName}.json`);
7
- const destDir = path.normalize("dist/");
8
-
9
- mkdirp.sync(destDir);
10
-
11
- const template = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
12
-
13
- const name = "${name}";
14
- const pathData = "${pathData}";
15
- const ltr = ${ltr};
16
- const collection = "${collection}";
17
- const packageName = "${packageName}";
18
-
19
- registerIcon(name, { pathData, ltr, collection, packageName });
20
-
21
- export default { pathData };`;
22
-
23
-
24
- const accTemplate = (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 { pathData, accData };`;
37
-
38
- const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
39
- <path d="${pathData}"/>
40
- </svg>`;
41
-
42
- const createIcons = (file) => {
43
- const json = JSON.parse(fs.readFileSync(file));
44
-
45
- for (let name in json.data) {
46
- const iconData = json.data[name];
47
- const pathData = iconData.path;
48
- const ltr = !!iconData.ltr;
49
- const acc = iconData.acc;
50
-
51
- const content = acc ? accTemplate(name, pathData, ltr, acc, json.collection, json.packageName) : template(name, pathData, ltr, json.collection, json.packageName);
52
-
53
- fs.writeFileSync(path.join(destDir, `${name}.js`), content);
54
- fs.writeFileSync(path.join(destDir, `${name}.svg`), svgTemplate(pathData));
55
- }
56
- };
57
-
58
- 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,44 +1,102 @@
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 srcPath = process.argv[2];
10
- const defaultText = process.argv[3] === "true";
11
- const illustrationsPrefix = process.argv[4];
12
- const illustrationSet = process.argv[5];
13
- const destPath = process.argv[6];
14
- 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`);
15
61
  // collect each illustration name because each one should have Sample.js file
16
- const fileNames = new Set();
17
-
18
- const svgImportTemplate = svgContent => { return `export default \`${svgContent}\`;`};
19
- const svgToJs = fileName => {
20
- const svg = fs.readFileSync(path.join(srcPath, fileName), { encoding: "utf-8" });
21
- const fileContent = svgImportTemplate(svg);
22
- fileName = fileName.replace(/\.svg$/, ".js");
23
-
24
- fs.writeFileSync(path.join(destPath, fileName), fileContent);
25
- };
26
- const illustrationImportTemplate = illustrationName => {
27
- const illustationNameUpperCase = illustrationName.toUpperCase();
28
-
29
- return defaultText ? `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
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
+ }
83
+ }
84
+
85
+ const illustrationNameUpperCase = illustrationNameForTranslation.toUpperCase();
86
+
87
+ return defaultText ? `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
30
88
  import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
31
89
  import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
32
90
  import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
33
91
  import {
34
- IM_TITLE_${illustationNameUpperCase},
35
- IM_SUBTITLE_${illustationNameUpperCase},
92
+ IM_TITLE_${illustrationNameUpperCase},
93
+ IM_SUBTITLE_${illustrationNameUpperCase},
36
94
  } from "../generated/i18n/i18n-defaults.js";
37
95
 
38
96
  const name = "${illustrationName}";
39
97
  const set = "${illustrationSet}";
40
- const title = IM_TITLE_${illustationNameUpperCase};
41
- const subtitle = IM_SUBTITLE_${illustationNameUpperCase};
98
+ const title = IM_TITLE_${illustrationNameUpperCase};
99
+ const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};
42
100
 
43
101
  registerIllustration(name, {
44
102
  dialogSvg,
@@ -54,7 +112,7 @@ export {
54
112
  sceneSvg,
55
113
  spotSvg,
56
114
  };` :
57
- `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
115
+ `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
58
116
  import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
59
117
  import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
60
118
  import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
@@ -74,22 +132,30 @@ export {
74
132
  sceneSvg,
75
133
  spotSvg,
76
134
  };`
77
- };
135
+ };
136
+
137
+ await fs.mkdir(destPath, { recursive: true });
78
138
 
79
- mkdirp.sync(destPath);
139
+ const illustrationFileNames = await fs.readdir(path.normalize(srcPath));
80
140
 
81
- 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);
82
146
 
83
- // convert SVG to JS imports
84
- illustrationFileNames.forEach(illustration => {
85
- if (fileNamePattern.test(illustration)) {
86
- let [fileName, illustrationName] = illustration.match(fileNamePattern);
147
+ promises.push(svgToJs(fileName));
148
+ fileNames.add(illustrationName);
149
+ }
150
+ });
87
151
 
88
- svgToJs(fileName);
89
- fileNames.add(illustrationName);
152
+ for (let illustrationName of fileNames) {
153
+ promises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
90
154
  }
91
- });
92
155
 
93
- for (let illustrationName of fileNames) {
94
- fs.writeFileSync(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName));
95
- }
156
+ return Promise.all(promises);
157
+ };
158
+
159
+ generate().then(() => {
160
+ console.log("Illustrations generated.");
161
+ });