@ui5/webcomponents-tools 0.0.0-0f0e49a22 → 0.0.0-10f3c0dc7

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 (129) hide show
  1. package/CHANGELOG.md +2100 -0
  2. package/LICENSE.txt +201 -0
  3. package/README.md +7 -9
  4. package/assets-meta.js +14 -11
  5. package/bin/dev.js +10 -4
  6. package/bin/ui5nps.js +301 -0
  7. package/components-package/eslint.js +60 -30
  8. package/components-package/nps.js +125 -81
  9. package/components-package/postcss.components.js +1 -21
  10. package/components-package/postcss.themes.js +1 -36
  11. package/components-package/vite.config.js +7 -11
  12. package/components-package/wdio.js +421 -401
  13. package/icons-collection/nps.js +31 -20
  14. package/lib/amd-to-es6/index.js +109 -0
  15. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  16. package/lib/cem/cem.js +16 -0
  17. package/lib/cem/custom-elements-manifest.config.mjs +614 -0
  18. package/lib/cem/event.mjs +168 -0
  19. package/lib/cem/merge.mjs +220 -0
  20. package/lib/cem/patch/@custom-elements-manifest/analyzer/cli.js +128 -0
  21. package/lib/cem/patch/@custom-elements-manifest/analyzer/package.json +59 -0
  22. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/browser-entrypoint.js +23 -0
  23. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/create.js +117 -0
  24. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/arrow-function.js +26 -0
  25. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/class-jsdoc.js +157 -0
  26. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/classes.js +20 -0
  27. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createArrowFunction.js +17 -0
  28. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createAttribute.js +24 -0
  29. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js +301 -0
  30. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClassField.js +26 -0
  31. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createFunctionLike.js +73 -0
  32. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createMixin.js +33 -0
  33. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createVariable.js +22 -0
  34. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/handlers.js +338 -0
  35. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/custom-elements-define-calls.js +90 -0
  36. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/exports.js +156 -0
  37. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/function-like.js +24 -0
  38. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/mixins.js +29 -0
  39. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/reexported-wrapped-mixin-exports.js +84 -0
  40. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/variables.js +34 -0
  41. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/collect-phase/collect-imports.js +101 -0
  42. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/catalyst.js +11 -0
  43. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/controller.js +34 -0
  44. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/catalyst.js +11 -0
  45. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/controller.js +34 -0
  46. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/attr.js +53 -0
  47. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/custom-element-decorator.js +36 -0
  48. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/fast/fast.js +7 -0
  49. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js +13 -0
  50. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/member-denylist.js +21 -0
  51. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/method-denylist.js +20 -0
  52. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/property-decorator.js +94 -0
  53. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/static-properties.js +121 -0
  54. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/utils.js +66 -0
  55. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/stencil/stencil.js +129 -0
  56. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/index.js +80 -0
  57. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/cleanup-classes.js +25 -0
  58. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/field-denylist.js +22 -0
  59. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/method-denylist.js +25 -0
  60. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/apply-inheritance.js +78 -0
  61. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/is-custom-element.js +34 -0
  62. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/link-class-to-tagname.js +27 -0
  63. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/remove-unexported-declarations.js +23 -0
  64. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/resolve-initializers.js +52 -0
  65. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/ast-helpers.js +186 -0
  66. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js +164 -0
  67. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/exports.js +44 -0
  68. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/find-external-manifests.js +67 -0
  69. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/imports.js +25 -0
  70. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/index.js +71 -0
  71. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/jsdoc.js +19 -0
  72. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/manifest-helpers.js +194 -0
  73. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/mixins.js +112 -0
  74. package/lib/cem/schema-internal.json +1462 -0
  75. package/lib/cem/schema.json +1138 -0
  76. package/lib/cem/types-internal.d.ts +838 -0
  77. package/lib/cem/types.d.ts +766 -0
  78. package/lib/cem/utils.mjs +433 -0
  79. package/lib/cem/validate.js +81 -0
  80. package/lib/chokidar/chokidar.js +28 -0
  81. package/lib/copy-and-watch/index.js +110 -97
  82. package/lib/copy-list/index.js +18 -10
  83. package/lib/create-icons/index.js +46 -34
  84. package/lib/create-illustrations/index.js +130 -45
  85. package/lib/create-new-component/{tsFileContentTemplate.js → Component.js} +15 -21
  86. package/lib/create-new-component/ComponentTemplate.js +12 -0
  87. package/lib/create-new-component/index.js +16 -22
  88. package/lib/css-processors/css-processor-components.mjs +103 -0
  89. package/lib/css-processors/css-processor-themes.mjs +226 -0
  90. package/lib/css-processors/merge-light-dark.mjs +131 -0
  91. package/lib/css-processors/postcss-plugin.mjs +153 -0
  92. package/lib/css-processors/scope-variables.mjs +74 -0
  93. package/lib/css-processors/shared.mjs +47 -0
  94. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  95. package/lib/dev-server/{dev-server.js → dev-server.mjs} +26 -14
  96. package/lib/dev-server/virtual-index-html-plugin.js +24 -20
  97. package/lib/eslint/eslint.js +44 -0
  98. package/lib/generate-js-imports/illustrations.js +79 -64
  99. package/lib/generate-json-imports/i18n.js +63 -68
  100. package/lib/generate-json-imports/themes.js +38 -43
  101. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +12 -7
  102. package/lib/hbs2ui5/index.js +3 -3
  103. package/lib/i18n/defaults.js +17 -9
  104. package/lib/i18n/toJSON.js +40 -12
  105. package/lib/icons-hash/icons-hash.mjs +149 -0
  106. package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
  107. package/lib/remove-dev-mode/remove-dev-mode.mjs +51 -0
  108. package/lib/rimraf/rimraf.js +31 -0
  109. package/lib/scoping/get-all-tags.js +10 -3
  110. package/lib/scoping/lint-src.js +8 -7
  111. package/lib/scoping/scope-test-pages.js +2 -1
  112. package/lib/test-runner/test-runner.js +56 -48
  113. package/lib/vite-bundler/vite-bundler.mjs +35 -0
  114. package/package.json +29 -26
  115. package/tsconfig.json +18 -0
  116. package/components-package/wdio.sync.js +0 -368
  117. package/lib/create-new-component/jsFileContentTemplate.js +0 -73
  118. package/lib/esm-abs-to-rel/index.js +0 -58
  119. package/lib/generate-custom-elements-manifest/index.js +0 -327
  120. package/lib/jsdoc/config.json +0 -29
  121. package/lib/jsdoc/configTypescript.json +0 -29
  122. package/lib/jsdoc/plugin.js +0 -2468
  123. package/lib/jsdoc/preprocess.js +0 -146
  124. package/lib/jsdoc/template/publish.js +0 -4120
  125. package/lib/postcss-css-to-esm/index.js +0 -90
  126. package/lib/postcss-css-to-json/index.js +0 -47
  127. package/lib/postcss-new-files/index.js +0 -36
  128. package/lib/postcss-p/postcss-p.mjs +0 -14
  129. package/lib/replace-global-core/index.js +0 -25
@@ -1,11 +1,10 @@
1
1
  const fs = require("fs").promises;
2
2
  const path = require("path");
3
3
 
4
- if (process.argv.length < 7) {
5
- throw new Error("Not enough arguments");
6
- }
7
-
8
- const generate = async () => {
4
+ const generate = async (argv) => {
5
+ if (argv.length < 7) {
6
+ throw new Error("Not enough arguments");
7
+ }
9
8
 
10
9
  const ORIGINAL_TEXTS = {
11
10
  UnableToLoad: "UnableToLoad",
@@ -20,7 +19,15 @@ const generate = async () => {
20
19
  SuccessScreen: "SuccessScreen",
21
20
  NoMail: "NoMail",
22
21
  NoSavedItems: "NoSavedItems",
23
- NoTasks: "NoTasks"
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"
24
31
  };
25
32
 
26
33
  const FALLBACK_TEXTS = {
@@ -47,28 +54,79 @@ const generate = async () => {
47
54
  SimpleNotFoundMagnifier: ORIGINAL_TEXTS.NoSearchResults,
48
55
  SimpleReload: ORIGINAL_TEXTS.UnableToLoad,
49
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,
50
67
  SuccessBalloon: ORIGINAL_TEXTS.BalloonSky,
51
68
  SuccessCheckMark: ORIGINAL_TEXTS.SuccessScreen,
52
69
  SuccessHighFive: ORIGINAL_TEXTS.BalloonSky
53
70
  };
54
71
 
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];
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];
60
78
  const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
61
- // collect each illustration name because each one should have Sample.js file
79
+ // collect each illustration name because each one should have Sample.js file
62
80
  const fileNames = new Set();
63
81
 
82
+ let dotIllustrationNames = [];
83
+ let v5IllustrationNames = new Set();
84
+
85
+ try {
86
+ await fs.access(srcPath);
87
+ } catch (error) {
88
+ if (process.env.UI5_VERBOSE === "true") {
89
+ console.log(`The path ${srcPath} does not exist.`);
90
+ }
91
+ return Promise.resolve(null);
92
+ }
93
+
94
+ // For V4 TNT illustrations, check which ones have V5 versions available
95
+ // so we only register V5 loaders for illustrations that actually exist
96
+ if (collection === "V4" && illustrationSet === "tnt") {
97
+ const v5Path = srcPath.replace("/illustrations/", "/illustrations-v5/");
98
+ try {
99
+ const v5Files = await fs.readdir(path.normalize(v5Path));
100
+ const v5Pattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
101
+ v5Files.forEach(file => {
102
+ const match = file.match(v5Pattern);
103
+ if (match) {
104
+ v5IllustrationNames.add(match[1]);
105
+ }
106
+ });
107
+ } catch (error) {
108
+ // V5 path doesn't exist, no V5 illustrations available
109
+ }
110
+ }
111
+
112
+ if (process.env.UI5_VERBOSE === "true") {
113
+ console.log(`Generating illustrations from ${srcPath} to ${destPath}`);
114
+ }
115
+
64
116
  const svgImportTemplate = svgContent => {
65
117
  return `export default \`${svgContent}\`;`
66
118
  };
67
119
  const svgToJs = async fileName => {
68
- const svg = await fs.readFile(path.join(srcPath, fileName), {encoding: "utf-8"});
120
+ const svg = await fs.readFile(path.join(srcPath, fileName), { encoding: "utf-8" });
69
121
  const fileContent = svgImportTemplate(svg);
122
+ const fileNameSplitArr = fileName.split('-');
70
123
  fileName = fileName.replace(/\.svg$/, ".js");
71
124
 
125
+ if (fileNameSplitArr[1] === 'Dot') {
126
+ // we keep the Dot illustration names to import them later. If no Dot is present, Spot will be used
127
+ dotIllustrationNames.push(fileNameSplitArr[2].split('.')[0]);
128
+ }
129
+
72
130
  return fs.writeFile(path.join(destPath, fileName), fileContent);
73
131
  };
74
132
  const illustrationImportTemplate = illustrationName => {
@@ -83,55 +141,70 @@ const generate = async () => {
83
141
  }
84
142
 
85
143
  const illustrationNameUpperCase = illustrationNameForTranslation.toUpperCase();
144
+ // If no Dot is present, Spot will be imported as Dot
145
+ const hasDot = dotIllustrationNames.indexOf(illustrationName) !== -1 ? 'Dot' : 'Spot';
146
+
147
+ // For V4 TNT illustrations that have V5 versions, register loaders for V5 and V5/HC
148
+ // so that when the illustration is imported directly (e.g., "@ui5/webcomponents-fiori/dist/illustrations/tnt/NoApplications.js")
149
+ // and Horizon themes are used, the correct V5 illustration is loaded dynamically.
150
+ // Note: Only TNT set has V5 illustrations, and not all TNT illustrations have V5 versions.
151
+ // The dynamic imports ensure that V5 SVGs are loaded lazily only when actually needed.
152
+ const hasV5Version = v5IllustrationNames.has(illustrationName);
153
+ const v5LoaderRegistration = collection === "V4" && illustrationSet === "tnt" && hasV5Version ? `
154
+ import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
155
+
156
+ registerIllustrationLoader("${illustrationSet}/V5/${illustrationName}", async function loadIllustrationV5() {
157
+ return (await import("../../illustrations-v5/${illustrationSet}/${illustrationName}.js")).default;
158
+ });
159
+ registerIllustrationLoader("${illustrationSet}/V5/HC/${illustrationName}", async function loadIllustrationV5HC() {
160
+ return (await import("../../illustrations-v5/${illustrationSet}/hc/${illustrationName}.js")).default;
161
+ });
162
+ ` : '';
86
163
 
87
- return defaultText ? `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
164
+ return `import { unsafeRegisterIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
88
165
  import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
89
166
  import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
90
167
  import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
91
- import {
168
+ import dotSvg from "./${illustrationsPrefix}-${hasDot}-${illustrationName}.js";${defaultText ? `import {
92
169
  IM_TITLE_${illustrationNameUpperCase},
93
170
  IM_SUBTITLE_${illustrationNameUpperCase},
94
- } from "../generated/i18n/i18n-defaults.js";
171
+ } from "../generated/i18n/i18n-defaults.js";` : ``}${v5LoaderRegistration}
95
172
 
96
173
  const name = "${illustrationName}";
97
174
  const set = "${illustrationSet}";
175
+ const collection = "${collection}";${defaultText ? `
98
176
  const title = IM_TITLE_${illustrationNameUpperCase};
99
- const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};
177
+ const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};` : ``}
100
178
 
101
- registerIllustration(name, {
179
+ unsafeRegisterIllustration(name, {
102
180
  dialogSvg,
103
181
  sceneSvg,
104
182
  spotSvg,
183
+ dotSvg,${defaultText ? `
105
184
  title,
106
- subtitle,
185
+ subtitle,` : ``}
107
186
  set,
187
+ collection,
108
188
  });
109
189
 
190
+ export default "${illustrationSet === "fiori" ? "" : `${illustrationSet}/`}${illustrationName}";
110
191
  export {
111
192
  dialogSvg,
112
193
  sceneSvg,
113
194
  spotSvg,
114
- };` :
115
- `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
116
- import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
117
- import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
118
- import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
119
-
120
- const name = "${illustrationName}";
121
- const set = "${illustrationSet}";
195
+ dotSvg,
196
+ };`
197
+ };
122
198
 
123
- registerIllustration(name, {
124
- dialogSvg,
125
- sceneSvg,
126
- spotSvg,
127
- set,
128
- });
199
+ const illustrationTypeDefinition = illustrationName => {
200
+ return `declare const dialogSvg: string;
201
+ declare const sceneSvg: string;
202
+ declare const spotSvg: string;
203
+ declare const dotSvg: string;
204
+ declare const _default: "${illustrationSet === "fiori" ? "" : `${illustrationSet}/`}${illustrationName}";
129
205
 
130
- export {
131
- dialogSvg,
132
- sceneSvg,
133
- spotSvg,
134
- };`
206
+ export default _default;
207
+ export { dialogSvg, sceneSvg, spotSvg, dotSvg };`
135
208
  };
136
209
 
137
210
  await fs.mkdir(destPath, { recursive: true });
@@ -149,13 +222,25 @@ export {
149
222
  }
150
223
  });
151
224
 
152
- for (let illustrationName of fileNames) {
153
- promises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
154
- }
225
+ return Promise.all(promises)
226
+ .then(() => {
227
+ const nestedPromises = [];
228
+ for (let illustrationName of fileNames) {
229
+ nestedPromises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
230
+ nestedPromises.push(fs.writeFile(path.join(destPath, `${illustrationName}.d.ts`), illustrationTypeDefinition(illustrationName)));
231
+ }
155
232
 
156
- return Promise.all(promises);
233
+ return Promise.all(nestedPromises);
234
+ })
235
+ .then(() => {
236
+ if (process.env.UI5_VERBOSE === "true") {
237
+ console.log("Illustrations generated.");
238
+ }
239
+ });
157
240
  };
158
241
 
159
- generate().then(() => {
160
- console.log("Illustrations generated.");
161
- });
242
+ if (require.main === module) {
243
+ generate(process.argv)
244
+ }
245
+
246
+ exports._ui5mainFn = generate;
@@ -1,12 +1,12 @@
1
- const tsFileContentTemplate = (componentName, tagName, library, packageName) => {
1
+ const Component = (componentName, tagName, library, packageName) => {
2
2
  return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
3
3
  import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
4
4
  import property from "@ui5/webcomponents-base/dist/decorators/property.js";
5
5
  import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
6
- import event from "@ui5/webcomponents-base/dist/decorators/event.js";
7
- import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
6
+ import event from "@ui5/webcomponents-base/dist/decorators/event-strict.js";
7
+ import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
8
8
 
9
- import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
9
+ import ${componentName}Template from "./${componentName}Template.js";
10
10
 
11
11
  // Styles
12
12
  import ${componentName}Css from "./generated/themes/${componentName}.css.js";
@@ -22,49 +22,43 @@ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
22
22
  * For the <code>${tagName}</code>
23
23
  * <h3>ES6 Module Import</h3>
24
24
  *
25
- * <code>import ${packageName}/dist/${componentName}.js";</code>
25
+ * <code>import "${packageName}/dist/${componentName}.js";</code>
26
26
  *
27
27
  * @constructor
28
- * @author SAP SE
29
- * @alias sap.ui.webc.${library}.${componentName}
30
- * @extends sap.ui.webc.base.UI5Element
31
- * @tagname ${tagName}
28
+ * @extends UI5Element
32
29
  * @public
33
30
  */
34
31
  @customElement({
35
32
  tag: "${tagName}",
36
- renderer: litRender,
33
+ renderer: jsxRenderer,
37
34
  styles: ${componentName}Css,
38
35
  template: ${componentName}Template,
39
- dependencies: [],
40
36
  })
41
37
 
42
38
  /**
43
39
  * Example custom event.
44
40
  * Please keep in mind that all public events should be documented in the API Reference as shown below.
45
41
  *
46
- * @event sap.ui.webc.${library}.${componentName}#interact
47
42
  * @public
48
43
  */
49
- @event("interact", { detail: { /* event payload ( optional ) */ } })
44
+ @event("interact")
50
45
  class ${componentName} extends UI5Element {
46
+ eventDetails!: {
47
+ "interact": void,
48
+ };
49
+
51
50
  /**
52
51
  * Defines the value of the component.
53
52
  *
54
- * @type {string}
55
- * @name sap.ui.webc.${library}.${componentName}.prototype.value
56
- * @defaultvalue ""
53
+ * @default ""
57
54
  * @public
58
55
  */
59
56
  @property()
60
- value!: string;
57
+ value?: string;
61
58
 
62
59
  /**
63
60
  * Defines the text of the component.
64
61
  *
65
- * @type {Node[]}
66
- * @name sap.ui.webc.${library}.${componentName}.prototype.default
67
- * @slot
68
62
  * @public
69
63
  */
70
64
  @slot({ type: Node, "default": true })
@@ -77,4 +71,4 @@ export default ${componentName};
77
71
  `;
78
72
  };
79
73
 
80
- module.exports = tsFileContentTemplate;
74
+ module.exports = Component;
@@ -0,0 +1,12 @@
1
+ const ComponentTemplate = (componentName) => {
2
+ return `import type ${componentName} from "./${componentName}.js";
3
+
4
+ export default function ${componentName}Template(this: ${componentName}) {
5
+ return (
6
+ <div>Hello World!</div>
7
+ );
8
+ }
9
+ `;
10
+ };
11
+
12
+ module.exports = ComponentTemplate;
@@ -1,18 +1,19 @@
1
1
  const fs = require("fs");
2
- const path = require("path");
3
2
  const prompts = require("prompts");
4
- const jsFileContentTemplate = require("./jsFileContentTemplate.js");
5
- const tsFileContentTemplate = require("./tsFileContentTemplate.js");
3
+ const Component = require("./Component.js");
4
+ const ComponentTemplate= require("./ComponentTemplate.js");
5
+ const dotenv = require('dotenv');
6
+ dotenv.config();
6
7
 
7
8
  /**
8
- * Hyphanates the given PascalCase string, f.e.:
9
- * Foo -> "my-foo" (adds preffix)
10
- * FooBar -> "foo-bar"
9
+ * Hyphanates the given PascalCase string and adds prefix, f.e.:
10
+ * Foo -> "my-foo"
11
+ * FooBar -> "my-foo-bar"
11
12
  */
12
13
  const hyphaneteComponentName = (componentName) => {
13
14
  const result = componentName.replace(/([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
14
15
 
15
- return result.includes("-") ? result : `my-${result}`;
16
+ return `${process.env.UI5_TAG_NAME_PREFIX ?? "my"}-${result}`;
16
17
  };
17
18
 
18
19
  /**
@@ -58,23 +59,17 @@ const getLibraryName = packageName => {
58
59
  return packageName.substr("webcomponents-".length);
59
60
  };
60
61
 
61
- const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
62
+ const generateFiles = (componentName, tagName, library, packageName) => {
62
63
  componentName = capitalizeFirstLetter(componentName);
63
64
  const filePaths = {
64
- "main": isTypeScript
65
- ? `./src/${componentName}.ts`
66
- : `./src/${componentName}.js`,
65
+ "main": `./src/${componentName}.ts`,
67
66
  "css": `./src/themes/${componentName}.css`,
68
- "template": `./src/${componentName}.hbs`,
67
+ "template": `./src/${componentName}${process.env.UI5_TEMPLATE_FILENAME_SUFFIX ?? "Template"}.tsx`,
69
68
  };
70
69
 
71
- const FileContentTemplate = isTypeScript
72
- ? tsFileContentTemplate(componentName, tagName, library, packageName)
73
- : jsFileContentTemplate(componentName, tagName, library, packageName);
74
-
75
- fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
70
+ fs.writeFileSync(filePaths.main, Component(componentName, tagName, library, packageName), { flag: "wx+" });
76
71
  fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
77
- fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
72
+ fs.writeFileSync(filePaths.template, ComponentTemplate(componentName), { flag: "wx+" });
78
73
 
79
74
  console.log(`Successfully generated ${filePaths.main}`);
80
75
  console.log(`Successfully generated ${filePaths.css}`);
@@ -82,8 +77,8 @@ const generateFiles = (componentName, tagName, library, packageName, isTypeScrip
82
77
 
83
78
  // Change the color of the output
84
79
  console.warn('\x1b[33m%s\x1b[0m', `
85
- Make sure to import the component in your bundle by using:
86
- import ${componentName} from "./dist/${componentName}.js";`);
80
+ Now, import the component in "src/bundle.esm.ts" via: import "./${componentName}.js";
81
+ And, add it to your HTML: <${tagName}></${tagName}>.`);
87
82
  }
88
83
 
89
84
  // Main function
@@ -112,10 +107,9 @@ const createWebComponent = async () => {
112
107
  }
113
108
  }
114
109
 
115
- const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
116
110
  const tagName = hyphaneteComponentName(componentName);
117
111
 
118
- generateFiles(componentName, tagName, library, packageName, isTypeScript);
112
+ generateFiles(componentName, tagName, library, packageName);
119
113
  };
120
114
 
121
115
  createWebComponent();
@@ -0,0 +1,103 @@
1
+ import { globby } from "globby";
2
+ import * as esbuild from 'esbuild'
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import { writeFile, mkdir } from "fs/promises";
6
+ import chokidar from "chokidar";
7
+ import scopeVariables from "./scope-variables.mjs";
8
+ import { writeFileIfChanged, getFileContent } from "./shared.mjs";
9
+ import { pathToFileURL } from "url";
10
+
11
+
12
+ const generate = async (argv) => {
13
+ const CSS_VARIABLES_TARGET = process.env.CSS_VARIABLES_TARGET === "host";
14
+ const tsMode = process.env.UI5_TS === "true";
15
+ const extension = tsMode ? ".css.ts" : ".css.js";
16
+
17
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
18
+ const basePackageJSON = (await import("@ui5/webcomponents-base/package.json", { with: { type: "json" } })).default;
19
+
20
+ const inputFilesGlob = "src/themes/*.css";
21
+ const restArgs = argv.slice(2);
22
+
23
+ let customPlugin = {
24
+ name: 'ui5-tools',
25
+ setup(build) {
26
+ build.initialOptions.write = false;
27
+
28
+ build.onEnd(result => {
29
+ result.outputFiles.forEach(async f => {
30
+ let newText
31
+
32
+ if (CSS_VARIABLES_TARGET) {
33
+ newText = f.text;
34
+ } else {
35
+ // scoping
36
+ newText = scopeVariables(f.text, basePackageJSON);
37
+ }
38
+
39
+ newText = newText.replaceAll(/\\/g, "\\\\"); // Escape backslashes as they might appear in css rules
40
+ await mkdir(path.dirname(f.path), { recursive: true });
41
+ writeFile(f.path, newText);
42
+
43
+ // JS/TS
44
+ const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
45
+ const jsContent = getFileContent(packageJSON.name, "\`" + newText + "\`", true);
46
+ writeFileIfChanged(jsPath, jsContent);
47
+ });
48
+ })
49
+ },
50
+ }
51
+
52
+ const getConfig = async () => {
53
+ const config = {
54
+ entryPoints: await globby(inputFilesGlob),
55
+ bundle: true,
56
+ minify: true,
57
+ outdir: 'dist/css',
58
+ outbase: 'src',
59
+ plugins: [
60
+ customPlugin,
61
+ ]
62
+ };
63
+ return config;
64
+ }
65
+
66
+ if (restArgs.includes("-w")) {
67
+ let ready;
68
+ let config = await getConfig();
69
+ let ctx = await esbuild.context(config);
70
+ await ctx.watch()
71
+ console.log('watching...')
72
+
73
+ // when new component css files are added, they do not trigger a build as no one directly imports them
74
+ // restart the watch mode with the new entry points if a css file is added.
75
+ const watcher = chokidar.watch(inputFilesGlob);
76
+ watcher.on("ready", () => {
77
+ ready = true; // Initial scan is over -> waiting for new files
78
+ });
79
+ watcher.on("add", async path => {
80
+ if (ready) {
81
+ // new file
82
+ ctx.dispose();
83
+ config = await getConfig();
84
+ ctx = await esbuild.context(config);
85
+ ctx.watch();
86
+ }
87
+ });
88
+ } else {
89
+ const config = await getConfig();
90
+ const result = await esbuild.build(config);
91
+ }
92
+ }
93
+
94
+ const filePath = process.argv[1];
95
+ const fileUrl = pathToFileURL(filePath).href;
96
+
97
+ if (import.meta.url === fileUrl) {
98
+ generate(process.argv)
99
+ }
100
+
101
+ export default {
102
+ _ui5mainFn: generate
103
+ }