@ui5/webcomponents-tools 0.0.0-deac3098a → 0.0.0-df5b4199a

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 (142) hide show
  1. package/CHANGELOG.md +2155 -0
  2. package/LICENSE.txt +201 -0
  3. package/README.md +7 -10
  4. package/assets-meta.js +12 -11
  5. package/bin/dev.js +3 -6
  6. package/bin/ui5nps.js +265 -0
  7. package/components-package/eslint.js +66 -2
  8. package/components-package/nps.js +140 -80
  9. package/components-package/postcss.components.js +1 -21
  10. package/components-package/postcss.themes.js +1 -26
  11. package/components-package/vite.config.js +9 -0
  12. package/components-package/wdio.js +69 -17
  13. package/icons-collection/nps.js +32 -24
  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 +546 -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 +29 -0
  80. package/lib/copy-and-watch/index.js +128 -97
  81. package/lib/copy-list/index.js +26 -20
  82. package/lib/create-icons/index.js +131 -72
  83. package/lib/create-illustrations/index.js +169 -114
  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 +62 -101
  87. package/lib/css-processors/css-processor-components.mjs +92 -0
  88. package/lib/css-processors/css-processor-themes.mjs +118 -0
  89. package/lib/css-processors/scope-variables.mjs +57 -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 +42 -0
  95. package/lib/generate-js-imports/illustrations.js +85 -0
  96. package/lib/generate-json-imports/i18n.js +70 -70
  97. package/lib/generate-json-imports/themes.js +47 -49
  98. package/lib/hbs2lit/src/compiler.js +17 -6
  99. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  100. package/lib/hbs2lit/src/litVisitor2.js +85 -22
  101. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  102. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +39 -6
  103. package/lib/hbs2ui5/index.js +57 -24
  104. package/lib/i18n/defaults.js +74 -60
  105. package/lib/i18n/toJSON.js +22 -18
  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 +11 -11
  111. package/lib/scoping/lint-src.js +8 -7
  112. package/lib/scoping/scope-test-pages.js +2 -1
  113. package/lib/test-runner/test-runner.js +79 -0
  114. package/package.json +47 -44
  115. package/tsconfig.json +18 -0
  116. package/components-package/rollup-plugins/empty-module.js +0 -15
  117. package/components-package/rollup.js +0 -239
  118. package/components-package/wdio.sync.js +0 -360
  119. package/lib/documentation/index.js +0 -165
  120. package/lib/documentation/templates/api-component-since.js +0 -3
  121. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  122. package/lib/documentation/templates/api-events-section.js +0 -35
  123. package/lib/documentation/templates/api-methods-section.js +0 -26
  124. package/lib/documentation/templates/api-properties-section.js +0 -42
  125. package/lib/documentation/templates/api-slots-section.js +0 -28
  126. package/lib/documentation/templates/template.js +0 -39
  127. package/lib/esm-abs-to-rel/index.js +0 -54
  128. package/lib/hash/config.js +0 -10
  129. package/lib/hash/generate.js +0 -19
  130. package/lib/hash/upToDate.js +0 -31
  131. package/lib/jsdoc/config.json +0 -29
  132. package/lib/jsdoc/plugin.js +0 -2436
  133. package/lib/jsdoc/template/publish.js +0 -4112
  134. package/lib/polyfill-placeholder/index.js +0 -5
  135. package/lib/postcss-css-to-esm/index.js +0 -45
  136. package/lib/postcss-css-to-json/index.js +0 -36
  137. package/lib/postcss-new-files/index.js +0 -36
  138. package/lib/postcss-p/postcss-p.mjs +0 -11
  139. package/lib/replace-global-core/index.js +0 -20
  140. package/lib/serve/index.js +0 -46
  141. package/lib/serve/serve.json +0 -3
  142. package/package-lock.json +0 -48
@@ -1,122 +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', 'silent'].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
- options.silent || console.log('[COPY]'.yellow, from, 'to'.yellow, to);
68
- };
69
- const remove = from => {
70
- const to = findTarget(from);
71
- fs.unlinkSync(to);
72
- options.silent || 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 => {
114
- options.silent || console.log('[WATCH]'.yellow, s);
115
- }))
116
- .on('add', copy)
117
- .on('addDir', copy)
118
- .on('change', copy)
119
- .on('unlink', remove)
120
- .on('unlinkDir', remove)
121
- .on('error', e => console.log('[ERROR]'.red, e));
149
+ if (require.main === module) {
150
+ copyAndWatchFn(process.argv)
122
151
  }
152
+
153
+ exports._ui5mainFn = copyAndWatchFn;
@@ -1,28 +1,34 @@
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
- const fileList = process.argv[2];
6
- const dest = process.argv[3];
7
- const src = "../../node_modules/@openui5/sap.ui.core/src/";
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);
8
10
 
9
- const filesToCopy = fs.readFileSync(fileList).toString();
10
- // console.log(filesToCopy);
11
+ // Support full-line comments starting with # in the used-modules.txt file
12
+ const shouldCopy = file => file.length && !file.startsWith("#");
11
13
 
12
- // Support full-line comments starting with # in the used-modules.txt file
13
- const shouldCopy = file => file.length && !file.startsWith("#");
14
+ const trimFile = file => file.trim();
14
15
 
15
- const trimFile = file => file.trim();
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);
16
19
 
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);
20
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
21
+ return fs.copyFile(srcPath, destPath);
22
+ });
20
23
 
21
- await mkdirp(path.dirname(destPath));
22
- fs.copyFile(srcPath, destPath, (err) => {
23
- if (err) {
24
- throw err;
25
- }
26
- console.log(`${destPath} created.`);
24
+ return Promise.all(promises).then(() => {
25
+ console.log("Files copied.");
27
26
  });
28
- });
27
+ };
28
+
29
+
30
+ if (require.main === module) {
31
+ generate(process.argv)
32
+ }
33
+
34
+ exports._ui5mainFn = generate;
@@ -1,72 +1,131 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const mkdirp = require("mkdirp");
4
-
5
- const collectionName = process.argv[2] || "SAP-icons";
6
- const collectionVersion = process.argv[3];
7
- const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
8
- const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
9
-
10
- mkdirp.sync(destDir);
11
-
12
- const iconTemplate = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
13
-
14
- const name = "${name}";
15
- const pathData = "${pathData}";
16
- const ltr = ${ltr};
17
- const collection = "${collection}";
18
- const packageName = "${packageName}";
19
-
20
- registerIcon(name, { pathData, ltr, collection, packageName });
21
-
22
- export default { pathData };`;
23
-
24
-
25
- const iconAccTemplate = (name, pathData, ltr, accData, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
26
- import { ${accData.key} } from "../generated/i18n/i18n-defaults.js";
27
-
28
- const name = "${name}";
29
- const pathData = "${pathData}";
30
- const ltr = ${ltr};
31
- const accData = ${accData.key};
32
- const collection = "${collection}";
33
- const packageName = "${packageName}";
34
-
35
- registerIcon(name, { pathData, ltr, accData, collection, packageName });
36
-
37
- export default { pathData, accData };`;
38
-
39
-
40
-
41
- const collectionTemplate = (name) => `import { isThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
42
- import pathDataV4 from "./v5/${name}.js";
43
- import pathDataV5 from "./v4/${name}.js";
44
- const pathData = isThemeFamily("sap_horizon") ? pathDataV5 : pathDataV4;
45
- export default { pathData };`;
46
-
47
-
48
- const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
49
- <path d="${pathData}"/>
50
- </svg>`;
51
-
52
- const createIcons = (file) => {
53
- const json = JSON.parse(fs.readFileSync(file));
54
-
55
- for (let name in json.data) {
56
- const iconData = json.data[name];
57
- const pathData = iconData.path;
58
- const ltr = !!iconData.ltr;
59
- const acc = iconData.acc;
60
-
61
- const content = acc ? iconAccTemplate(name, pathData, ltr, acc, json.collection, json.packageName) : iconTemplate(name, pathData, ltr, json.collection, json.packageName);
62
-
63
- fs.writeFileSync(path.join(destDir, `${name}.js`), content);
64
- fs.writeFileSync(path.join(destDir, `${name}.svg`), svgTemplate(pathData));
65
-
66
- if (json.version) {
67
- fs.writeFileSync(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name));
68
- }
69
- }
70
- };
71
-
72
- createIcons(srcFile);
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const 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;