@ui5/webcomponents-tools 0.0.0-dff5837d7 → 0.0.0-e03cd01f3

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 (160) hide show
  1. package/CHANGELOG.md +2415 -0
  2. package/LICENSE.txt +201 -0
  3. package/README.md +7 -10
  4. package/assets-meta.js +23 -5
  5. package/bin/dev.js +8 -6
  6. package/bin/ui5nps.js +274 -0
  7. package/components-package/eslint.js +66 -2
  8. package/components-package/nps.js +147 -49
  9. package/components-package/postcss.components.js +1 -21
  10. package/components-package/postcss.themes.js +1 -23
  11. package/components-package/vite.config.js +9 -0
  12. package/components-package/wdio.js +118 -41
  13. package/icons-collection/nps.js +64 -12
  14. package/lib/amd-to-es6/index.js +107 -0
  15. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  16. package/lib/cem/cem.js +12 -0
  17. package/lib/cem/custom-elements-manifest.config.mjs +550 -0
  18. package/lib/cem/event.mjs +168 -0
  19. package/lib/cem/patch/@custom-elements-manifest/analyzer/cli.js +128 -0
  20. package/lib/cem/patch/@custom-elements-manifest/analyzer/package.json +59 -0
  21. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/browser-entrypoint.js +23 -0
  22. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/create.js +117 -0
  23. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/arrow-function.js +26 -0
  24. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/class-jsdoc.js +157 -0
  25. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/classes.js +20 -0
  26. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createArrowFunction.js +17 -0
  27. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createAttribute.js +24 -0
  28. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js +301 -0
  29. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClassField.js +26 -0
  30. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createFunctionLike.js +73 -0
  31. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createMixin.js +33 -0
  32. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createVariable.js +22 -0
  33. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/handlers.js +338 -0
  34. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/custom-elements-define-calls.js +90 -0
  35. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/exports.js +156 -0
  36. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/function-like.js +24 -0
  37. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/mixins.js +29 -0
  38. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/reexported-wrapped-mixin-exports.js +84 -0
  39. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/variables.js +34 -0
  40. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/collect-phase/collect-imports.js +101 -0
  41. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/catalyst.js +11 -0
  42. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/controller.js +34 -0
  43. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/catalyst.js +11 -0
  44. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/controller.js +34 -0
  45. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/attr.js +53 -0
  46. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/custom-element-decorator.js +36 -0
  47. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/fast/fast.js +7 -0
  48. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js +13 -0
  49. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/member-denylist.js +21 -0
  50. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/method-denylist.js +20 -0
  51. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/property-decorator.js +94 -0
  52. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/static-properties.js +121 -0
  53. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/utils.js +66 -0
  54. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/stencil/stencil.js +129 -0
  55. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/index.js +80 -0
  56. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/cleanup-classes.js +25 -0
  57. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/field-denylist.js +22 -0
  58. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/method-denylist.js +25 -0
  59. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/apply-inheritance.js +78 -0
  60. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/is-custom-element.js +34 -0
  61. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/link-class-to-tagname.js +27 -0
  62. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/remove-unexported-declarations.js +23 -0
  63. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/resolve-initializers.js +52 -0
  64. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/ast-helpers.js +186 -0
  65. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js +164 -0
  66. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/exports.js +44 -0
  67. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/find-external-manifests.js +67 -0
  68. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/imports.js +25 -0
  69. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/index.js +71 -0
  70. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/jsdoc.js +19 -0
  71. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/manifest-helpers.js +194 -0
  72. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/mixins.js +112 -0
  73. package/lib/cem/schema-internal.json +1422 -0
  74. package/lib/cem/schema.json +1098 -0
  75. package/lib/cem/types-internal.d.ts +808 -0
  76. package/lib/cem/types.d.ts +736 -0
  77. package/lib/cem/utils.mjs +423 -0
  78. package/lib/cem/validate.js +76 -0
  79. package/lib/chokidar/chokidar.js +28 -0
  80. package/lib/copy-and-watch/index.js +128 -95
  81. package/lib/copy-list/index.js +34 -0
  82. package/lib/create-icons/index.js +131 -54
  83. package/lib/create-illustrations/index.js +204 -0
  84. package/lib/create-new-component/Component.js +74 -0
  85. package/lib/create-new-component/ComponentTemplate.js +12 -0
  86. package/lib/create-new-component/index.js +66 -93
  87. package/lib/css-processors/css-processor-components.mjs +92 -0
  88. package/lib/css-processors/css-processor-themes.mjs +102 -0
  89. package/lib/css-processors/scope-variables.mjs +49 -0
  90. package/lib/css-processors/shared.mjs +46 -0
  91. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  92. package/lib/dev-server/dev-server.mjs +78 -0
  93. package/lib/dev-server/virtual-index-html-plugin.js +56 -0
  94. package/lib/eslint/eslint.js +44 -0
  95. package/lib/generate-js-imports/illustrations.js +85 -0
  96. package/lib/generate-json-imports/i18n.js +73 -38
  97. package/lib/generate-json-imports/themes.js +58 -20
  98. package/lib/hbs2lit/src/compiler.js +24 -4
  99. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  100. package/lib/hbs2lit/src/litVisitor2.js +125 -26
  101. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  102. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +40 -7
  103. package/lib/hbs2ui5/index.js +68 -19
  104. package/lib/i18n/defaults.js +74 -60
  105. package/lib/i18n/toJSON.js +46 -19
  106. package/lib/icons-hash/icons-hash.mjs +149 -0
  107. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  108. package/lib/remove-dev-mode/remove-dev-mode.mjs +51 -0
  109. package/lib/rimraf/rimraf.js +31 -0
  110. package/lib/scoping/get-all-tags.js +44 -0
  111. package/lib/scoping/lint-src.js +32 -0
  112. package/lib/scoping/missing-dependencies.js +65 -0
  113. package/lib/scoping/report-tags-usage.js +28 -0
  114. package/lib/scoping/scope-test-pages.js +41 -0
  115. package/lib/test-runner/test-runner.js +79 -0
  116. package/lib/vite-bundler/vite-bundler.mjs +35 -0
  117. package/package.json +62 -58
  118. package/tsconfig.json +18 -0
  119. package/bin/init-ui5-package.js +0 -3
  120. package/components-package/rollup.js +0 -134
  121. package/components-package/serve.json +0 -3
  122. package/lib/documentation/index.js +0 -143
  123. package/lib/documentation/templates/api-component-since.js +0 -3
  124. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  125. package/lib/documentation/templates/api-events-section.js +0 -35
  126. package/lib/documentation/templates/api-methods-section.js +0 -26
  127. package/lib/documentation/templates/api-properties-section.js +0 -40
  128. package/lib/documentation/templates/api-slots-section.js +0 -28
  129. package/lib/documentation/templates/template.js +0 -38
  130. package/lib/init-package/index.js +0 -112
  131. package/lib/init-package/resources/.eslintignore +0 -3
  132. package/lib/init-package/resources/bundle.es5.js +0 -25
  133. package/lib/init-package/resources/bundle.esm.js +0 -34
  134. package/lib/init-package/resources/config/.eslintrc.js +0 -1
  135. package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
  136. package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
  137. package/lib/init-package/resources/config/rollup.config.js +0 -1
  138. package/lib/init-package/resources/config/wdio.conf.js +0 -1
  139. package/lib/init-package/resources/package-scripts.js +0 -11
  140. package/lib/init-package/resources/src/Assets.js +0 -5
  141. package/lib/init-package/resources/src/Demo.hbs +0 -1
  142. package/lib/init-package/resources/src/Demo.js +0 -56
  143. package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
  144. package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
  145. package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
  146. package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
  147. package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
  148. package/lib/init-package/resources/src/themes/Demo.css +0 -11
  149. package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
  150. package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
  151. package/lib/init-package/resources/src/themes/sap_belize_hcw/parameters-bundle.css +0 -3
  152. package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  153. package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
  154. package/lib/init-package/resources/test/pages/index.html +0 -51
  155. package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
  156. package/lib/jsdoc/config.json +0 -29
  157. package/lib/jsdoc/plugin.js +0 -2407
  158. package/lib/jsdoc/template/publish.js +0 -4092
  159. package/lib/postcss-css-to-esm/index.js +0 -42
  160. package/lib/postcss-css-to-json/index.js +0 -27
@@ -1,120 +1,153 @@
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
 
10
- const args = process.argv.slice(2);
11
- const options = {};
33
+ const copyAndWatchFn = async (argv) => {
34
+ const args = argv.slice(2);
35
+ const options = {};
12
36
 
13
- ['watch', 'clean', 'skip-initial-copy', 'safe'].forEach(key => {
14
- const index = args.indexOf(`--${key}`);
15
- if (index >= 0) {
16
- options[key] = true;
17
- args.splice(index, 1);
37
+ ['watch', 'clean', 'skip-initial-copy', 'safe', 'silent'].forEach(key => {
38
+ const index = args.indexOf(`--${key}`);
39
+ if (index >= 0) {
40
+ options[key] = true;
41
+ args.splice(index, 1);
42
+ }
43
+ });
44
+
45
+ if (args.length < 2) {
46
+ console.error('Not enough arguments: copy-and-watch [options] <sources> <target>');
47
+ process.exit(1);
18
48
  }
19
- });
20
49
 
21
- if (args.length < 2) {
22
- console.error('Not enough arguments: copy-and-watch [options] <sources> <target>'.red);
23
- process.exit(1);
24
- }
50
+ if (options['skip-initial-copy'] && !options['watch']) {
51
+ console.error('--skip-initial-copy argument is meant to be used with --watch, otherwise no files will be copied');
52
+ process.exit(1);
53
+ }
25
54
 
26
- if (options['skip-initial-copy'] && !options['watch']) {
27
- console.error('--skip-initial-copy argument is meant to be used with --watch, otherwise no files will be copied'.red);
28
- process.exit(1);
29
- }
55
+ const target = args.pop();
56
+ const sources = args;
57
+ const parents = [...new Set(sources.map(globParent))];
30
58
 
31
- const target = args.pop();
32
- const sources = args;
33
- const parents = [...new Set(sources.map(globParent))];
34
-
35
- const findTarget = from => {
36
- const parent = parents
37
- .filter(p => from.indexOf(p) >= 0)
38
- .sort()
39
- .reverse()[0];
40
- return path.join(target, path.relative(parent, from));
41
- };
42
- const createDirIfNotExist = to => {
43
- 'use strict';
44
-
45
- const dirs = [];
46
- let dir = path.dirname(to);
47
-
48
- while (dir !== path.dirname(dir)) {
49
- dirs.unshift(dir);
50
- dir = path.dirname(dir);
51
- }
59
+ const findTarget = from => {
60
+ const parent = parents
61
+ .filter(p => from.indexOf(p) >= 0)
62
+ .sort()
63
+ .reverse()[0];
64
+ return path.join(target, path.relative(parent, from));
65
+ };
66
+ const createDirIfNotExist = to => {
67
+ 'use strict';
52
68
 
53
- dirs.forEach(dir => {
54
- if (!fs.existsSync(dir)) {
55
- fs.mkdirSync(dir);
69
+ const dirs = [];
70
+ let dir = path.dirname(to);
71
+
72
+ while (dir !== path.dirname(dir)) {
73
+ dirs.unshift(dir);
74
+ dir = path.dirname(dir);
56
75
  }
57
- });
58
- };
59
- const copy = from => {
60
- const to = findTarget(from);
61
- createDirIfNotExist(to);
62
- const stats = fs.statSync(from);
63
- if (stats.isDirectory()) {
64
- return;
65
- }
66
- fs.writeFileSync(to, fs.readFileSync(from));
67
- console.log('[COPY]'.yellow, from, 'to'.yellow, to);
68
- };
69
- const remove = from => {
70
- const to = findTarget(from);
71
- fs.unlinkSync(to);
72
- console.log('[DELETE]'.yellow, to);
73
- };
74
- const rimraf = dir => {
75
- if (fs.existsSync(dir)) {
76
- fs.readdirSync(dir).forEach(entry => {
77
- const entryPath = path.join(dir, entry);
78
- if (fs.lstatSync(entryPath).isDirectory()) {
79
- rimraf(entryPath);
80
- } else {
81
- fs.unlinkSync(entryPath);
76
+
77
+ dirs.forEach(dir => {
78
+ if (!fs.existsSync(dir)) {
79
+ fs.mkdirSync(dir);
82
80
  }
83
81
  });
84
- fs.rmdirSync(dir);
82
+ };
83
+ const copy = from => {
84
+ const to = findTarget(from);
85
+ createDirIfNotExist(to);
86
+ const stats = fs.statSync(from);
87
+ if (stats.isDirectory()) {
88
+ return;
89
+ }
90
+ fs.writeFileSync(to, fs.readFileSync(from));
91
+ options.silent || console.log('[COPY]', from, 'to', to);
92
+ };
93
+ const remove = from => {
94
+ const to = findTarget(from);
95
+ fs.unlinkSync(to);
96
+ options.silent || console.log('[DELETE]', to);
97
+ };
98
+ const rimraf = dir => {
99
+ if (fs.existsSync(dir)) {
100
+ fs.readdirSync(dir).forEach(entry => {
101
+ const entryPath = path.join(dir, entry);
102
+ if (fs.lstatSync(entryPath).isDirectory()) {
103
+ rimraf(entryPath);
104
+ } else {
105
+ fs.unlinkSync(entryPath);
106
+ }
107
+ });
108
+ fs.rmdirSync(dir);
109
+ }
110
+ };
111
+
112
+ // clean
113
+ if (options.clean) {
114
+ rimraf(target);
85
115
  }
86
- };
87
116
 
88
- // clean
89
- if (options.clean) {
90
- rimraf(target);
91
- }
117
+ // initial copy
118
+ if (!options['skip-initial-copy']) {
119
+ sources.forEach(s => glob.sync(s).forEach(copy));
120
+ }
92
121
 
93
- // initial copy
94
- if (!options['skip-initial-copy']) {
95
- sources.forEach(s => glob.sync(s).forEach(copy));
96
- }
122
+ // watch
123
+ if (options.watch) {
124
+ const chokidarOptions = {
125
+ ignoreInitial: true
126
+ };
97
127
 
98
- // watch
99
- if (options.watch) {
100
- const chokidarOptions = {
101
- ignoreInitial: true
102
- };
128
+ if (options.safe) {
129
+ chokidarOptions.awaitWriteFinish = {
130
+ stabilityThreshold: 500,
131
+ pollInterval: 100
132
+ };
133
+ }
103
134
 
104
- if (options.safe) {
105
- chokidarOptions.awaitWriteFinish = {
106
- stabilityThreshold: 500,
107
- pollInterval: 100
108
- };
135
+ chokidar
136
+ .watch(sources, chokidarOptions)
137
+ .on('ready', () => sources.forEach(s => {
138
+ options.silent || console.log('[WATCH]', s);
139
+ }))
140
+ .on('add', copy)
141
+ .on('addDir', copy)
142
+ .on('change', copy)
143
+ .on('unlink', remove)
144
+ .on('unlinkDir', remove)
145
+ .on('error', e => console.log('[ERROR]', e));
109
146
  }
147
+ }
110
148
 
111
- chokidar
112
- .watch(sources, chokidarOptions)
113
- .on('ready', () => sources.forEach(s => console.log('[WATCH]'.yellow, s)))
114
- .on('add', copy)
115
- .on('addDir', copy)
116
- .on('change', copy)
117
- .on('unlink', remove)
118
- .on('unlinkDir', remove)
119
- .on('error', e => console.log('[ERROR]'.red, e));
149
+ if (require.main === module) {
150
+ copyAndWatchFn(process.argv)
120
151
  }
152
+
153
+ exports._ui5mainFn = copyAndWatchFn;
@@ -0,0 +1,34 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const generate = async (argv) => {
5
+ const fileList = argv[2];
6
+ const dest = argv[3];
7
+ const src = "@openui5/sap.ui.core/src/";
8
+ const filesToCopy = (await fs.readFile(fileList)).toString();
9
+ // console.log(filesToCopy);
10
+
11
+ // Support full-line comments starting with # in the used-modules.txt file
12
+ const shouldCopy = file => file.length && !file.startsWith("#");
13
+
14
+ const trimFile = file => file.trim();
15
+
16
+ const promises = filesToCopy.split("\n").map(trimFile).filter(shouldCopy).map(async moduleName => {
17
+ const srcPath = require.resolve(path.join(src, moduleName), { paths: [process.cwd()] });
18
+ const destPath = path.join(dest, moduleName);
19
+
20
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
21
+ return fs.copyFile(srcPath, destPath);
22
+ });
23
+
24
+ return Promise.all(promises).then(() => {
25
+ console.log("Files copied.");
26
+ });
27
+ };
28
+
29
+
30
+ if (require.main === module) {
31
+ generate(process.argv)
32
+ }
33
+
34
+ exports._ui5mainFn = generate;
@@ -1,54 +1,131 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const mkdirp = require("mkdirp");
4
-
5
- const srcDir = `src/icon-collections/`;
6
- const destDir = `dist/icons/`;
7
-
8
- mkdirp.sync(destDir);
9
-
10
- const template = (name, pathData, ltr) => `import { registerIcon } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js";
11
-
12
- const name = "${name}";
13
- const pathData = "${pathData}";
14
- const ltr = ${ltr};
15
-
16
- registerIcon(name, { pathData, ltr});
17
-
18
- export default { pathData };`;
19
-
20
- const accTemplate = (name, pathData, ltr, accData) => `import { registerIcon } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js";
21
- import { ${accData.key} } from "../generated/i18n/i18n-defaults.js";
22
-
23
- const name = "${name}";
24
- const pathData = "${pathData}";
25
- const ltr = ${ltr};
26
- const accData = ${accData.key};
27
-
28
- registerIcon(name, { pathData, ltr, accData });
29
-
30
- export default { pathData, accData };`;
31
-
32
-
33
- const createIcons = (file) => {
34
- const json = JSON.parse(fs.readFileSync(file));
35
-
36
- for (let name in json.data) {
37
- const iconData = json.data[name];
38
- const pathData = iconData.path;
39
- const ltr = !!iconData.ltr;
40
- const acc = iconData.acc;
41
-
42
- const content = acc ? accTemplate(name, pathData, ltr, acc) : template(name, pathData, ltr);
43
-
44
- fs.writeFileSync(path.join(destDir, `${name}.js`), content);
45
- }
46
-
47
- };
48
-
49
- fs.readdirSync(srcDir).forEach(collectionFile => {
50
- createIcons(path.join(srcDir, collectionFile));
51
- });
52
-
53
-
54
-
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const iconTemplate = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
5
+
6
+ const name = "${name}";
7
+ const pathData = "${pathData}";
8
+ const ltr = ${ltr};
9
+ const accData = null;
10
+ const collection = "${collection}";
11
+ const packageName = "${packageName}";
12
+
13
+ registerIcon(name, { pathData, ltr, collection, packageName });
14
+
15
+ export default "${collection}/${name}";
16
+ export { pathData, ltr, accData };`;
17
+
18
+
19
+ const iconAccTemplate = (name, pathData, ltr, accData, collection, packageName, versioned) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
20
+ import { ${accData.key} } from "${versioned ? "../" : "./"}generated/i18n/i18n-defaults.js";
21
+
22
+ const name = "${name}";
23
+ const pathData = "${pathData}";
24
+ const ltr = ${ltr};
25
+ const accData = ${accData.key};
26
+ const collection = "${collection}";
27
+ const packageName = "${packageName}";
28
+
29
+ registerIcon(name, { pathData, ltr, accData, collection, packageName });
30
+
31
+ export default "${collection}/${name}";
32
+ export { pathData, ltr, accData };`;
33
+
34
+
35
+
36
+ const collectionTemplate = (name, versions, fullName) => `import { isLegacyThemeFamilyAsync } from "@ui5/webcomponents-base/dist/config/Theme.js";
37
+ import { pathData as pathData${versions[0]}, ltr, accData } from "./${versions[0]}/${name}.js";
38
+ import { pathData as pathData${versions[1]} } from "./${versions[1]}/${name}.js";
39
+
40
+ const getPathData = async() => {
41
+ return await isLegacyThemeFamilyAsync() ? pathDatav4 : pathDatav5;
42
+ };
43
+
44
+ export default "${fullName}";
45
+ export { getPathData, ltr, accData };`;
46
+
47
+
48
+ const typeDefinitionTemplate = (name, accData, collection) => `declare const pathData: string;
49
+ declare const ltr: boolean;
50
+ declare const accData: ${accData ? '{ key: string; defaultText: string; }' : null}
51
+ declare const _default: "${collection}/${name}";
52
+
53
+ export default _default;
54
+ export { pathData, ltr, accData };`
55
+
56
+ const collectionTypeDefinitionTemplate = (name, accData) => `declare const getPathData: () => Promise<string>;
57
+ declare const ltr: boolean;
58
+ declare const accData: ${accData ? '{ key: string; defaultText: string; }' : null}
59
+ declare const _default: "${name}";
60
+
61
+ export default _default;
62
+ export { getPathData, ltr, accData };`
63
+
64
+
65
+ const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
66
+ <path d="${pathData}"/>
67
+ </svg>`;
68
+
69
+ const createIcons = async (argv) => {
70
+ const collectionName = argv[2] || "SAP-icons-v4";
71
+ const collectionVersion = argv[3];
72
+ const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
73
+ const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
74
+ await fs.mkdir(destDir, { recursive: true });
75
+
76
+ const json = JSON.parse(await fs.readFile(srcFile));
77
+
78
+ const promises = [];
79
+ for (let name in json.data) {
80
+ const iconData = json.data[name];
81
+ const pathData = iconData.path;
82
+ const ltr = !!iconData.ltr;
83
+ const acc = iconData.acc;
84
+ const packageName = json.packageName;
85
+ const collection = json.collection;
86
+ const versioned = json.version;
87
+
88
+ const content = acc ? iconAccTemplate(name, pathData, ltr, acc, collection, packageName, versioned) : iconTemplate(name, pathData, ltr, collection, packageName);
89
+
90
+ promises.push(fs.writeFile(path.join(destDir, `${name}.js`), content));
91
+ promises.push(fs.writeFile(path.join(destDir, `${name}.svg`), svgTemplate(pathData)));
92
+ promises.push(fs.writeFile(path.join(destDir, `${name}.d.ts`), typeDefinitionTemplate(name, acc, collection)));
93
+
94
+ // For versioned icons collections, the script creates top level (unversioned) module that internally imports the versioned ones.
95
+ // For example, the top level "@ui5/ui5-webcomponents-icons/dist/accept.js" imports:
96
+ // - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
97
+ // - "@ui5/ui5-webcomponents-icons/dist/v4/accept.js"
98
+
99
+ if (versioned) {
100
+ // The exported value from the top level (unversioned) icon module depends on whether the collection is the default,
101
+ // to add or not the collection name to the exported value:
102
+ // For the default collection (SAPIcons) we export just the icon name - "export default { 'accept' }"
103
+ // For non-default collections (SAPTNTIcons and SAPBSIcons) we export the full name - "export default { 'tnt/actor' }"
104
+ const effectiveName = isDefaultCollection(collection) ? name : getUnversionedFullIconName(name, collection);
105
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name, json.versions, effectiveName)));
106
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.d.ts`), collectionTypeDefinitionTemplate(effectiveName, acc)));
107
+ }
108
+ }
109
+
110
+ return Promise.all(promises)
111
+ .then(() => {
112
+ console.log("Icons created.");
113
+ });
114
+ };
115
+
116
+ const isDefaultCollection = collectionName => collectionName === "SAP-icons-v4" || collectionName === "SAP-icons-v5";
117
+ const getUnversionedFullIconName = (name, collection) => `${getUnversionedCollectionName(collection)}/${name}`;
118
+ const getUnversionedCollectionName = collectionName => CollectionVersionedToUnversionedMap[collectionName] || collectionName;
119
+
120
+ const CollectionVersionedToUnversionedMap = {
121
+ "tnt-v2": "tnt",
122
+ "tnt-v3": "tnt",
123
+ "business-suite-v1": "business-suite",
124
+ "business-suite-v2": "business-suite",
125
+ };
126
+
127
+ if (require.main === module) {
128
+ createIcons(process.argv)
129
+ }
130
+
131
+ exports._ui5mainFn = createIcons;
@@ -0,0 +1,204 @@
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const generate = async (argv) => {
5
+ if (argv.length < 7) {
6
+ throw new Error("Not enough arguments");
7
+ }
8
+
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
+ NoDimensionsSet: "NoDimensionsSet",
24
+ AddPeople: "AddPeople",
25
+ AddColumn: "AddColumn",
26
+ SortColumn: "SortColumn",
27
+ FilterTable: "FilterTable",
28
+ ResizeColumn: "ResizeColumn",
29
+ GroupTable: "GroupTable",
30
+ UploadCollection: "UploadCollection"
31
+ };
32
+
33
+ const FALLBACK_TEXTS = {
34
+ ReloadScreen: ORIGINAL_TEXTS.UnableToLoad,
35
+ Connection: ORIGINAL_TEXTS.UnableToLoad,
36
+ ErrorScreen: ORIGINAL_TEXTS.UnableToUpload,
37
+ EmptyCalendar: ORIGINAL_TEXTS.NoActivities,
38
+ SearchEarth: ORIGINAL_TEXTS.BeforeSearch,
39
+ SearchFolder: ORIGINAL_TEXTS.NoSearchResults,
40
+ EmptyList: ORIGINAL_TEXTS.NoEntries,
41
+ Tent: ORIGINAL_TEXTS.NoData,
42
+ SleepingBell: ORIGINAL_TEXTS.NoNotifications,
43
+ SimpleBalloon: ORIGINAL_TEXTS.BalloonSky,
44
+ SimpleBell: ORIGINAL_TEXTS.NoNotifications,
45
+ SimpleCalendar: ORIGINAL_TEXTS.NoActivities,
46
+ SimpleCheckMark: ORIGINAL_TEXTS.SuccessScreen,
47
+ SimpleConnection: ORIGINAL_TEXTS.UnableToLoad,
48
+ SimpleEmptyDoc: ORIGINAL_TEXTS.NoData,
49
+ SimpleEmptyList: ORIGINAL_TEXTS.NoEntries,
50
+ SimpleError: ORIGINAL_TEXTS.UnableToUpload,
51
+ SimpleMagnifier: ORIGINAL_TEXTS.BeforeSearch,
52
+ SimpleMail: ORIGINAL_TEXTS.NoMail,
53
+ SimpleNoSavedItems: ORIGINAL_TEXTS.NoSavedItems,
54
+ SimpleNotFoundMagnifier: ORIGINAL_TEXTS.NoSearchResults,
55
+ SimpleReload: ORIGINAL_TEXTS.UnableToLoad,
56
+ SimpleTask: ORIGINAL_TEXTS.NoTasks,
57
+ NoChartData: ORIGINAL_TEXTS.NoDimensionsSet,
58
+ AddingColumns: ORIGINAL_TEXTS.AddColumn,
59
+ SortingColumns: ORIGINAL_TEXTS.SortColumn,
60
+ FilteringColumns: ORIGINAL_TEXTS.FilterTable,
61
+ ResizingColumns: ORIGINAL_TEXTS.ResizeColumn,
62
+ GroupingColumns: ORIGINAL_TEXTS.GroupTable,
63
+ AddPeopleToCalendar: ORIGINAL_TEXTS.AddPeople,
64
+ DragFilesToUpload: ORIGINAL_TEXTS.UploadCollection,
65
+ KeyTask: ORIGINAL_TEXTS.SuccessScreen,
66
+ ReceiveAppreciation: ORIGINAL_TEXTS.BalloonSky,
67
+ SuccessBalloon: ORIGINAL_TEXTS.BalloonSky,
68
+ SuccessCheckMark: ORIGINAL_TEXTS.SuccessScreen,
69
+ SuccessHighFive: ORIGINAL_TEXTS.BalloonSky
70
+ };
71
+
72
+ const srcPath = argv[2];
73
+ const defaultText = argv[3] === "true";
74
+ const illustrationsPrefix = argv[4];
75
+ const illustrationSet = argv[5];
76
+ const destPath = argv[6];
77
+ const collection = argv[7];
78
+ const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
79
+ // collect each illustration name because each one should have Sample.js file
80
+ const fileNames = new Set();
81
+
82
+ let dotIllustrationNames = [];
83
+
84
+ try {
85
+ await fs.access(srcPath);
86
+ } catch (error) {
87
+ console.log(`The path ${srcPath} does not exist.`);
88
+ return Promise.resolve(null);
89
+ }
90
+
91
+ console.log(`Generating illustrations from ${srcPath} to ${destPath}`)
92
+
93
+ const svgImportTemplate = svgContent => {
94
+ return `export default \`${svgContent}\`;`
95
+ };
96
+ const svgToJs = async fileName => {
97
+ const svg = await fs.readFile(path.join(srcPath, fileName), { encoding: "utf-8" });
98
+ const fileContent = svgImportTemplate(svg);
99
+ const fileNameSplitArr = fileName.split('-');
100
+ fileName = fileName.replace(/\.svg$/, ".js");
101
+
102
+ if (fileNameSplitArr[1] === 'Dot') {
103
+ // we keep the Dot illustration names to import them later. If no Dot is present, Spot will be used
104
+ dotIllustrationNames.push(fileNameSplitArr[2].split('.')[0]);
105
+ }
106
+
107
+ return fs.writeFile(path.join(destPath, fileName), fileContent);
108
+ };
109
+ const illustrationImportTemplate = illustrationName => {
110
+ let illustrationNameForTranslation = illustrationName;
111
+
112
+ if (defaultText) {
113
+ if (FALLBACK_TEXTS[illustrationNameForTranslation]) {
114
+ illustrationNameForTranslation = FALLBACK_TEXTS[illustrationNameForTranslation];
115
+ } else if (illustrationName.indexOf("_v") !== -1) {
116
+ illustrationNameForTranslation = illustrationNameForTranslation.substr(0, illustrationNameForTranslation.indexOf('_v'));
117
+ }
118
+ }
119
+
120
+ const illustrationNameUpperCase = illustrationNameForTranslation.toUpperCase();
121
+ // If no Dot is present, Spot will be imported as Dot
122
+ const hasDot = dotIllustrationNames.indexOf(illustrationName) !== -1 ? 'Dot' : 'Spot';
123
+
124
+ return `import { unsafeRegisterIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
125
+ import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
126
+ import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
127
+ import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
128
+ import dotSvg from "./${illustrationsPrefix}-${hasDot}-${illustrationName}.js";${defaultText ? `import {
129
+ IM_TITLE_${illustrationNameUpperCase},
130
+ IM_SUBTITLE_${illustrationNameUpperCase},
131
+ } from "../generated/i18n/i18n-defaults.js";` : ``}
132
+
133
+ const name = "${illustrationName}";
134
+ const set = "${illustrationSet}";
135
+ const collection = "${collection}";${defaultText ? `
136
+ const title = IM_TITLE_${illustrationNameUpperCase};
137
+ const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};` : ``}
138
+
139
+ unsafeRegisterIllustration(name, {
140
+ dialogSvg,
141
+ sceneSvg,
142
+ spotSvg,
143
+ dotSvg,${defaultText ? `
144
+ title,
145
+ subtitle,` : ``}
146
+ set,
147
+ collection,
148
+ });
149
+
150
+ export default "${illustrationSet === "fiori" ? "" : `${illustrationSet}/`}${illustrationName}";
151
+ export {
152
+ dialogSvg,
153
+ sceneSvg,
154
+ spotSvg,
155
+ dotSvg,
156
+ };`
157
+ };
158
+
159
+ const illustrationTypeDefinition = illustrationName => {
160
+ return `declare const dialogSvg: string;
161
+ declare const sceneSvg: string;
162
+ declare const spotSvg: string;
163
+ declare const dotSvg: string;
164
+ declare const _default: "${illustrationSet === "fiori" ? "" : `${illustrationSet}/`}${illustrationName}";
165
+
166
+ export default _default;
167
+ export { dialogSvg, sceneSvg, spotSvg, dotSvg };`
168
+ };
169
+
170
+ await fs.mkdir(destPath, { recursive: true });
171
+
172
+ const illustrationFileNames = await fs.readdir(path.normalize(srcPath));
173
+
174
+ // convert SVG to JS imports
175
+ const promises = [];
176
+ illustrationFileNames.forEach(illustration => {
177
+ if (fileNamePattern.test(illustration)) {
178
+ let [fileName, illustrationName] = illustration.match(fileNamePattern);
179
+
180
+ promises.push(svgToJs(fileName));
181
+ fileNames.add(illustrationName);
182
+ }
183
+ });
184
+
185
+ return Promise.all(promises)
186
+ .then(() => {
187
+ const nestedPromises = [];
188
+ for (let illustrationName of fileNames) {
189
+ nestedPromises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
190
+ nestedPromises.push(fs.writeFile(path.join(destPath, `${illustrationName}.d.ts`), illustrationTypeDefinition(illustrationName)));
191
+ }
192
+
193
+ return Promise.all(nestedPromises);
194
+ })
195
+ .then(() => {
196
+ console.log("Illustrations generated.");
197
+ });
198
+ };
199
+
200
+ if (require.main === module) {
201
+ generate(process.argv)
202
+ }
203
+
204
+ exports._ui5mainFn = generate;