@ui5/webcomponents-tools 0.0.0-b053ad005 → 0.0.0-b0b835975

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 (68) hide show
  1. package/CHANGELOG.md +609 -0
  2. package/README.md +5 -6
  3. package/assets-meta.js +10 -3
  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 +18 -15
  8. package/components-package/postcss.themes.js +21 -17
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +400 -353
  11. package/components-package/wdio.sync.js +26 -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 +118 -38
  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/custom-hot-update-plugin.js +39 -0
  21. package/lib/dev-server/dev-server.js +66 -0
  22. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  23. package/lib/esm-abs-to-rel/index.js +13 -9
  24. package/lib/generate-custom-elements-manifest/index.js +327 -0
  25. package/lib/generate-js-imports/illustrations.js +83 -0
  26. package/lib/generate-json-imports/i18n.js +38 -31
  27. package/lib/generate-json-imports/themes.js +31 -24
  28. package/lib/hbs2lit/src/compiler.js +24 -4
  29. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  30. package/lib/hbs2lit/src/litVisitor2.js +85 -22
  31. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  32. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
  33. package/lib/hbs2ui5/index.js +56 -23
  34. package/lib/i18n/defaults.js +65 -57
  35. package/lib/i18n/toJSON.js +12 -11
  36. package/lib/jsdoc/configTypescript.json +29 -0
  37. package/lib/jsdoc/plugin.js +41 -0
  38. package/lib/jsdoc/preprocess.js +146 -0
  39. package/lib/jsdoc/template/publish.js +21 -2
  40. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  41. package/lib/postcss-css-to-esm/index.js +52 -7
  42. package/lib/postcss-css-to-json/index.js +13 -2
  43. package/lib/postcss-p/postcss-p.mjs +14 -0
  44. package/lib/postcss-scope-vars/index.js +24 -0
  45. package/lib/replace-global-core/index.js +13 -8
  46. package/lib/scoping/get-all-tags.js +1 -8
  47. package/lib/scoping/missing-dependencies.js +65 -0
  48. package/lib/scoping/report-tags-usage.js +28 -0
  49. package/lib/scoping/scope-test-pages.js +1 -1
  50. package/lib/test-runner/test-runner.js +71 -0
  51. package/package.json +29 -29
  52. package/components-package/rollup-plugins/empty-module.js +0 -15
  53. package/components-package/rollup.js +0 -237
  54. package/lib/documentation/index.js +0 -165
  55. package/lib/documentation/templates/api-component-since.js +0 -3
  56. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  57. package/lib/documentation/templates/api-events-section.js +0 -35
  58. package/lib/documentation/templates/api-methods-section.js +0 -26
  59. package/lib/documentation/templates/api-properties-section.js +0 -40
  60. package/lib/documentation/templates/api-slots-section.js +0 -28
  61. package/lib/documentation/templates/template.js +0 -38
  62. package/lib/hash/config.js +0 -10
  63. package/lib/hash/generate.js +0 -19
  64. package/lib/hash/upToDate.js +0 -31
  65. package/lib/polyfill-placeholder/index.js +0 -5
  66. package/lib/serve/index.js +0 -46
  67. package/lib/serve/serve.json +0 -3
  68. 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
  }],
@@ -168,6 +176,21 @@ exports.config = {
168
176
  }, this);
169
177
  }, true);
170
178
 
179
+ browser.addCommand("isFocusedDeepElement", function (element) {
180
+ return browser.execute(function (elem, element, done) {
181
+ let activeElement = document.activeElement;
182
+
183
+ while (activeElement.shadowRoot) {
184
+ if (activeElement.shadowRoot.activeElement) {
185
+ activeElement = activeElement.shadowRoot.activeElement;
186
+ } else {
187
+ break;
188
+ }
189
+ }
190
+ done(element === activeElement);
191
+ }, this, element);
192
+ }, true);
193
+
171
194
  browser.addCommand("setProperty", function(property, value) {
172
195
  return browser.execute((elem, property, value) => {
173
196
  return elem[property] = value;
@@ -223,6 +246,7 @@ exports.config = {
223
246
  "isExisting",
224
247
  "isFocused",
225
248
  "isFocusedDeep", // custom
249
+ "isFocusedDeepElement", // custom
226
250
  "shadow$",
227
251
  "shadow$$",
228
252
  ];
@@ -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 { isTheme } 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 = isTheme("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,44 +1,113 @@
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 collection = process.argv[7];
61
+ const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
15
62
  // collect each illustration name because each one should have Sample.js file
16
- const fileNames = new Set();
63
+ const fileNames = new Set();
17
64
 
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");
65
+ try {
66
+ await fs.access(srcPath);
67
+ } catch (error) {
68
+ console.log(`The path ${srcPath} does not exist.`);
69
+ return Promise.resolve(null);
70
+ }
23
71
 
24
- fs.writeFileSync(path.join(destPath, fileName), fileContent);
25
- };
26
- const illustrationImportTemplate = illustrationName => {
27
- const illustationNameUpperCase = illustrationName.toUpperCase();
72
+ console.log(`Generating illustrations from ${srcPath} to ${destPath}`)
73
+
74
+ const svgImportTemplate = svgContent => {
75
+ return `export default \`${svgContent}\`;`
76
+ };
77
+ const svgToJs = async fileName => {
78
+ const svg = await fs.readFile(path.join(srcPath, fileName), {encoding: "utf-8"});
79
+ const fileContent = svgImportTemplate(svg);
80
+ fileName = fileName.replace(/\.svg$/, ".js");
81
+
82
+ return fs.writeFile(path.join(destPath, fileName), fileContent);
83
+ };
84
+ const illustrationImportTemplate = illustrationName => {
85
+ let illustrationNameForTranslation = illustrationName;
28
86
 
29
- return defaultText ? `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
87
+ if (defaultText) {
88
+ if (FALLBACK_TEXTS[illustrationNameForTranslation]) {
89
+ illustrationNameForTranslation = FALLBACK_TEXTS[illustrationNameForTranslation];
90
+ } else if (illustrationName.indexOf("_v") !== -1) {
91
+ illustrationNameForTranslation = illustrationNameForTranslation.substr(0, illustrationNameForTranslation.indexOf('_v'));
92
+ }
93
+ }
94
+
95
+ const illustrationNameUpperCase = illustrationNameForTranslation.toUpperCase();
96
+
97
+ return defaultText ? `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
30
98
  import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
31
99
  import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
32
100
  import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
33
101
  import {
34
- IM_TITLE_${illustationNameUpperCase},
35
- IM_SUBTITLE_${illustationNameUpperCase},
102
+ IM_TITLE_${illustrationNameUpperCase},
103
+ IM_SUBTITLE_${illustrationNameUpperCase},
36
104
  } from "../generated/i18n/i18n-defaults.js";
37
105
 
38
106
  const name = "${illustrationName}";
39
107
  const set = "${illustrationSet}";
40
- const title = IM_TITLE_${illustationNameUpperCase};
41
- const subtitle = IM_SUBTITLE_${illustationNameUpperCase};
108
+ const collection = "${collection}";
109
+ const title = IM_TITLE_${illustrationNameUpperCase};
110
+ const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};
42
111
 
43
112
  registerIllustration(name, {
44
113
  dialogSvg,
@@ -47,6 +116,7 @@ registerIllustration(name, {
47
116
  title,
48
117
  subtitle,
49
118
  set,
119
+ collection,
50
120
  });
51
121
 
52
122
  export {
@@ -54,19 +124,21 @@ export {
54
124
  sceneSvg,
55
125
  spotSvg,
56
126
  };` :
57
- `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
127
+ `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
58
128
  import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
59
129
  import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
60
130
  import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
61
131
 
62
132
  const name = "${illustrationName}";
63
133
  const set = "${illustrationSet}";
134
+ const collection = "${collection}";
64
135
 
65
136
  registerIllustration(name, {
66
137
  dialogSvg,
67
138
  sceneSvg,
68
139
  spotSvg,
69
140
  set,
141
+ collection,
70
142
  });
71
143
 
72
144
  export {
@@ -74,22 +146,30 @@ export {
74
146
  sceneSvg,
75
147
  spotSvg,
76
148
  };`
77
- };
149
+ };
78
150
 
79
- mkdirp.sync(destPath);
151
+ await fs.mkdir(destPath, { recursive: true });
80
152
 
81
- const illustrationFileNames = fs.readdirSync(path.normalize(srcPath));
153
+ const illustrationFileNames = await fs.readdir(path.normalize(srcPath));
82
154
 
83
- // convert SVG to JS imports
84
- illustrationFileNames.forEach(illustration => {
85
- if (fileNamePattern.test(illustration)) {
86
- let [fileName, illustrationName] = illustration.match(fileNamePattern);
155
+ // convert SVG to JS imports
156
+ const promises = [];
157
+ illustrationFileNames.forEach(illustration => {
158
+ if (fileNamePattern.test(illustration)) {
159
+ let [fileName, illustrationName] = illustration.match(fileNamePattern);
87
160
 
88
- svgToJs(fileName);
89
- fileNames.add(illustrationName);
161
+ promises.push(svgToJs(fileName));
162
+ fileNames.add(illustrationName);
163
+ }
164
+ });
165
+
166
+ for (let illustrationName of fileNames) {
167
+ promises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
90
168
  }
91
- });
92
169
 
93
- for (let illustrationName of fileNames) {
94
- fs.writeFileSync(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName));
95
- }
170
+ return Promise.all(promises);
171
+ };
172
+
173
+ generate().then(() => {
174
+ console.log("Illustrations generated.");
175
+ });