@ui5/webcomponents-tools 0.0.0-35e2c9666 → 0.0.0-38861c872

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 (78) hide show
  1. package/CHANGELOG.md +715 -0
  2. package/README.md +6 -6
  3. package/assets-meta.js +16 -7
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +36 -0
  6. package/components-package/nps.js +105 -69
  7. package/components-package/postcss.components.js +1 -21
  8. package/components-package/postcss.themes.js +1 -26
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +405 -369
  11. package/components-package/wdio.sync.js +10 -2
  12. package/icons-collection/nps.js +13 -14
  13. package/lib/cem/custom-elements-manifest.config.mjs +463 -0
  14. package/lib/cem/event.mjs +114 -0
  15. package/lib/cem/schema-internal.json +1354 -0
  16. package/lib/cem/schema.json +1098 -0
  17. package/lib/cem/types-internal.d.ts +1032 -0
  18. package/lib/cem/types.d.ts +871 -0
  19. package/lib/cem/utils.mjs +355 -0
  20. package/lib/cem/validate.js +63 -0
  21. package/lib/copy-and-watch/index.js +24 -1
  22. package/lib/copy-list/index.js +17 -17
  23. package/lib/create-icons/index.js +124 -72
  24. package/lib/create-illustrations/index.js +128 -113
  25. package/lib/create-new-component/index.js +71 -104
  26. package/lib/create-new-component/jsFileContentTemplate.js +73 -0
  27. package/lib/create-new-component/tsFileContentTemplate.js +71 -0
  28. package/lib/css-processors/css-processor-components.mjs +77 -0
  29. package/lib/css-processors/css-processor-themes.mjs +79 -0
  30. package/lib/css-processors/scope-variables.mjs +46 -0
  31. package/lib/css-processors/shared.mjs +76 -0
  32. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  33. package/lib/dev-server/dev-server.js +66 -0
  34. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  35. package/lib/esm-abs-to-rel/index.js +17 -10
  36. package/lib/generate-custom-elements-manifest/index.js +327 -0
  37. package/lib/generate-js-imports/illustrations.js +86 -0
  38. package/lib/generate-json-imports/i18n.js +43 -31
  39. package/lib/generate-json-imports/themes.js +36 -24
  40. package/lib/hbs2lit/src/compiler.js +24 -4
  41. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  42. package/lib/hbs2lit/src/litVisitor2.js +85 -22
  43. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  44. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
  45. package/lib/hbs2ui5/index.js +56 -23
  46. package/lib/i18n/defaults.js +65 -57
  47. package/lib/i18n/toJSON.js +12 -11
  48. package/lib/jsdoc/configTypescript.json +29 -0
  49. package/lib/jsdoc/plugin.js +32 -0
  50. package/lib/jsdoc/preprocess.js +146 -0
  51. package/lib/jsdoc/template/publish.js +9 -1
  52. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  53. package/lib/replace-global-core/index.js +13 -8
  54. package/lib/scoping/get-all-tags.js +2 -9
  55. package/lib/scoping/scope-test-pages.js +2 -1
  56. package/lib/test-runner/test-runner.js +71 -0
  57. package/package.json +28 -29
  58. package/components-package/rollup-plugins/empty-module.js +0 -15
  59. package/components-package/rollup.js +0 -239
  60. package/lib/documentation/index.js +0 -165
  61. package/lib/documentation/templates/api-component-since.js +0 -3
  62. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  63. package/lib/documentation/templates/api-events-section.js +0 -35
  64. package/lib/documentation/templates/api-methods-section.js +0 -26
  65. package/lib/documentation/templates/api-properties-section.js +0 -42
  66. package/lib/documentation/templates/api-slots-section.js +0 -28
  67. package/lib/documentation/templates/template.js +0 -39
  68. package/lib/hash/config.js +0 -10
  69. package/lib/hash/generate.js +0 -19
  70. package/lib/hash/upToDate.js +0 -31
  71. package/lib/polyfill-placeholder/index.js +0 -5
  72. package/lib/postcss-css-to-esm/index.js +0 -45
  73. package/lib/postcss-css-to-json/index.js +0 -36
  74. package/lib/postcss-new-files/index.js +0 -36
  75. package/lib/postcss-p/postcss-p.mjs +0 -11
  76. package/lib/serve/index.js +0 -46
  77. package/lib/serve/serve.json +0 -3
  78. package/package-lock.json +0 -48
@@ -50,13 +50,21 @@ exports.config = {
50
50
  // maxInstances can get overwritten per capability. So if you have an in-house Selenium
51
51
  // grid with only 5 firefox instances available you can make sure that not more than
52
52
  // 5 instances get started at a time.
53
- maxInstances: process.env.TRAVIS ? 1 : 5,
53
+ maxInstances: 5,
54
54
  //
55
55
  browserName: 'chrome',
56
56
  'goog:chromeOptions': {
57
57
  // to run chrome headless the following flags are required
58
58
  // (see https://developers.google.com/web/updates/2017/04/headless-chrome)
59
- args: ['--headless', '--disable-gpu'],
59
+ args: [
60
+ '--headless',
61
+ '--start-maximized',
62
+ '--no-sandbox',
63
+ '--disable-gpu',
64
+ '--disable-infobars',
65
+ '--disable-extensions',
66
+ '--disable-dev-shm-usage',
67
+ ],
60
68
  // args: ['--disable-gpu'],
61
69
  }
62
70
  }],
@@ -1,9 +1,4 @@
1
1
  const path = require("path");
2
- const resolve = require("resolve");
3
-
4
- const generateHash = resolve.sync("@ui5/webcomponents-tools/lib/hash/generate.js");
5
- const hashIsUpToDate = resolve.sync("@ui5/webcomponents-tools/lib/hash/upToDate.js");
6
- const UP_TO_DATE = `node "${hashIsUpToDate}" dist/ hash.txt && echo "Up to date."`;
7
2
 
8
3
  const LIB = path.join(__dirname, `../lib/`);
9
4
 
@@ -26,7 +21,7 @@ const copyIconAssetsCommand = (options) => {
26
21
  return {
27
22
  default: "nps copy.json-imports copy.icon-collection",
28
23
  "json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
29
- "icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" dist/generated/assets/`,
24
+ "icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" src/generated/assets/`,
30
25
  }
31
26
  }
32
27
 
@@ -37,7 +32,7 @@ const copyIconAssetsCommand = (options) => {
37
32
 
38
33
  options.versions.forEach((v) => {
39
34
  command.default += ` copy.icon-collection${v}`;
40
- command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" dist/generated/assets/${v}/`;
35
+ command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
41
36
  });
42
37
 
43
38
  return command;
@@ -46,24 +41,28 @@ const copyIconAssetsCommand = (options) => {
46
41
  const getScripts = (options) => {
47
42
  const createJSImportsCmd = createIconImportsCommand(options);
48
43
  const copyAssetsCmd = copyIconAssetsCommand(options);
44
+ const tsCommand = options.typescript ? "tsc --build" : "";
45
+ const tsCrossEnv = options.typescript ? "cross-env UI5_TS=true" : "";
49
46
 
50
47
  const scripts = {
51
- clean: "rimraf dist",
48
+ clean: "rimraf dist && rimraf src/generated",
52
49
  copy: copyAssetsCmd,
50
+ generate: `${tsCrossEnv} nps clean copy build.i18n build.icons build.jsonImports copyjson`,
51
+ copyjson: "copy-and-watch \"src/generated/**/*.json\" dist/generated/",
53
52
  build: {
54
- default: `${UP_TO_DATE} || nps clean copy build.i18n build.icons build.jsonImports hash`,
53
+ default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
55
54
  i18n: {
56
55
  default: "nps build.i18n.defaultsjs build.i18n.json",
57
- defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n dist/generated/i18n`,
58
- json: `mkdirp dist/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
56
+ defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
57
+ json: `mkdirp src/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n src/generated/assets/i18n`,
59
58
  },
60
59
  jsonImports: {
61
- default: "mkdirp dist/generated/json-imports && nps build.jsonImports.i18n",
62
- i18n: `node "${LIB}/generate-json-imports/i18n.js" dist/generated/assets/i18n dist/generated/json-imports`,
60
+ default: "mkdirp src/generated/json-imports && nps build.jsonImports.i18n",
61
+ i18n: `node "${LIB}/generate-json-imports/i18n.js" src/generated/assets/i18n src/generated/json-imports`,
63
62
  },
64
63
  icons: createJSImportsCmd,
65
64
  },
66
- hash: `node "${generateHash}" dist/ hash.txt`,
65
+ typescript: tsCommand,
67
66
  };
68
67
 
69
68
  return scripts;
@@ -0,0 +1,463 @@
1
+ import { parse } from "comment-parser";
2
+ import processEvent from "./event.mjs";
3
+ import path from "path";
4
+ import fs from 'fs';
5
+ import {
6
+ getDeprecatedStatus,
7
+ getSinceStatus,
8
+ getPrivacyStatus,
9
+ getReference,
10
+ validateJSDocComment,
11
+ findDecorator,
12
+ findAllDecorators,
13
+ hasTag,
14
+ findTag,
15
+ findAllTags,
16
+ getJSDocErrors,
17
+ getTypeRefs,
18
+ normalizeDescription,
19
+ formatArrays,
20
+ isClass,
21
+ normalizeTagType
22
+ } from "./utils.mjs";
23
+
24
+ const extractClassNodeJSDoc = node => {
25
+ const fileContent = node.getFullText();
26
+ const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
27
+ let allJSDocs = [...fileContent.matchAll(allJSDocsRegExp)];
28
+ allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
29
+
30
+ // Find where the class is defined in the original file
31
+ const tsClassDefinitionRegExp = new RegExp(`^\\s*(abstract\\s*)?class [\\w\\d_]+`, "gm");
32
+ let tsClassDefinitionMatch = fileContent.match(tsClassDefinitionRegExp);
33
+ if (!tsClassDefinitionMatch) {
34
+ return; // no class defined in this .ts file
35
+ }
36
+ const tsClassDefinition = tsClassDefinitionMatch[0];
37
+ const tsClassDefinitionIndex = fileContent.indexOf(tsClassDefinition);
38
+
39
+ return allJSDocs.find(JSDoc => {
40
+ return isClass(JSDoc) && (fileContent.indexOf(JSDoc) < tsClassDefinitionIndex)
41
+ });
42
+ }
43
+
44
+ function processClass(ts, classNode, moduleDoc) {
45
+ const className = classNode?.name?.text;
46
+ const currClass = moduleDoc?.declarations?.find(declaration => declaration?.name === className);
47
+ const currClassJSdoc = extractClassNodeJSDoc(classNode);
48
+
49
+ if (!currClassJSdoc) return;
50
+
51
+ const customElementDecorator = findDecorator(classNode, "customElement");
52
+ const classParsedJsDoc = parse(currClassJSdoc, { spacing: 'preserve' })[0];
53
+
54
+ validateJSDocComment("class", classParsedJsDoc, classNode.name?.text, moduleDoc);
55
+
56
+ const decoratorArg = customElementDecorator?.expression?.arguments[0];
57
+ currClass.tagName = decoratorArg?.text || (decoratorArg?.properties.find(property => property.name.text === "tag")?.initializer?.text);
58
+ currClass.customElement = !!customElementDecorator || className === "UI5Element" || undefined;
59
+ currClass.kind = "class";
60
+ currClass.deprecated = getDeprecatedStatus(classParsedJsDoc);
61
+ currClass._ui5since = getSinceStatus(classParsedJsDoc);
62
+ currClass._ui5privacy = getPrivacyStatus(classParsedJsDoc);
63
+ currClass._ui5abstract = hasTag(classParsedJsDoc, "abstract") ? true : undefined;
64
+ currClass.description = normalizeDescription(classParsedJsDoc.description || findTag(classParsedJsDoc, "class")?.description);
65
+ currClass._ui5implements = findAllTags(classParsedJsDoc, "implements")
66
+ .map(tag => getReference(ts, normalizeTagType(tag.type), classNode, moduleDoc.path))
67
+ .filter(Boolean);
68
+
69
+
70
+ if (hasTag(classParsedJsDoc, "extends")) {
71
+ const superclassTag = findTag(classParsedJsDoc, "extends");
72
+ currClass.superclass = getReference(ts, superclassTag.name, classNode, moduleDoc.path);
73
+
74
+ if (currClass.superclass?.name === "UI5Element") {
75
+ currClass.customElement = true;
76
+ }
77
+ }
78
+
79
+ if (!currClass._ui5implements.length) delete currClass._ui5implements;
80
+
81
+ // Slots
82
+
83
+ // Slots without accessort (defined in class comment)
84
+ if (hasTag(classParsedJsDoc, "slot") && currClass.slots) {
85
+ const slotTags = findAllTags(classParsedJsDoc, "slot");
86
+
87
+ currClass.slots.forEach(slot => {
88
+ const tag = slotTags.find(tag => tag.name === slot.name);
89
+
90
+ const typeRefs = (normalizeTagType(tag.type)
91
+ ?.replaceAll(/Array<|>|\[\]/g, "")
92
+ ?.split("|")
93
+ ?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path)).filter(Boolean));
94
+
95
+ slot._ui5privacy = "public";
96
+ slot._ui5type = { text: formatArrays(normalizeTagType(tag.type)) };
97
+ slot.description = normalizeDescription(tag.description)
98
+
99
+ if (typeRefs && typeRefs.length) {
100
+ slot._ui5type.references = typeRefs;
101
+ }
102
+
103
+ delete slot.type
104
+ })
105
+ }
106
+
107
+ // Events
108
+ currClass.events = findAllDecorators(classNode, "event")
109
+ ?.map(event => processEvent(ts, event, classNode, moduleDoc));
110
+
111
+ // Slots (with accessor), methods and fields
112
+ for (let i = 0; i < (currClass.members?.length || 0); i++) {
113
+ const member = currClass.members[i];
114
+ const classNodeMember = classNode.members?.find(nodeMember => nodeMember.name?.text === member?.name && nodeMember.jsDoc?.[0]);
115
+ const classNodeMemberJSdoc = classNodeMember?.jsDoc?.[0];
116
+
117
+ if (!classNodeMember || !classNodeMemberJSdoc) continue;
118
+
119
+ const memberParsedJsDoc = parse(classNodeMemberJSdoc?.getText())[0];
120
+
121
+ member._ui5since = getSinceStatus(memberParsedJsDoc);
122
+ member.deprecated === "true" && (member.deprecated = true)
123
+
124
+ // Slots with accessors are treated like fields by the tool, so we have to convert them into slots.
125
+ if (member.kind === "field") {
126
+ const slotDecorator = findDecorator(classNodeMember, "slot");
127
+ validateJSDocComment(slotDecorator ? "slot" : (member.readonly ? "getter" : "field"), memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
128
+
129
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member)
130
+ ?.map(e => getReference(ts, e, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
131
+
132
+ if (member.type?.text) {
133
+ member.type.text = formatArrays(member.type.text);
134
+ }
135
+
136
+ if (member.type && typeRefs.length) {
137
+ member.type.references = typeRefs;
138
+ }
139
+
140
+ if (slotDecorator) {
141
+ if (!currClass.slots) currClass.slots = [];
142
+
143
+ const slot = currClass.members.splice(i, 1)[0];
144
+ const defaultProperty = slotDecorator.expression?.arguments?.[0]?.properties?.find(property => property.name.text === "default");
145
+
146
+ // name of the default slot declared with decorator will be overriden so we to provide it's accessor name
147
+ if (defaultProperty && defaultProperty.initializer?.kind === ts.SyntaxKind.TrueKeyword) {
148
+ slot._ui5propertyName = slot.name;
149
+ slot.name = "default";
150
+ }
151
+
152
+ // Slots don't have type, privacy and kind, so we have do convert them and to clean unused props
153
+ member._ui5type = member.type;
154
+ member._ui5privacy = member.privacy;
155
+ delete member.type;
156
+ delete member.privacy;
157
+ delete slot.kind;
158
+
159
+ currClass.slots.push(slot);
160
+ i--;
161
+ } else {
162
+ const propertyDecorator = findDecorator(classNodeMember, "property");
163
+
164
+ if (propertyDecorator) {
165
+ member._ui5validator = propertyDecorator?.expression?.arguments[0]?.properties?.find(property => ["validator", "type"].includes(property.name.text))?.initializer?.text || "String";
166
+ }
167
+
168
+ if (hasTag(memberParsedJsDoc, "formProperty")) {
169
+ member._ui5formProperty = true;
170
+ }
171
+
172
+ const formEventsTag = findTag(memberParsedJsDoc, "formEvents");
173
+ if (formEventsTag) {
174
+ const tagValue = formEventsTag.description ? `${formEventsTag.name} ${formEventsTag.description}` : formEventsTag.name;
175
+ member._ui5formEvents = tagValue.trim().replaceAll(/\s+/g, ",");
176
+ }
177
+
178
+ const defaultTag = findTag(memberParsedJsDoc, "default");
179
+ if (defaultTag) {
180
+ const tagValue = defaultTag.source?.[0]?.tokens?.name || defaultTag.source?.[0]?.tokens?.description || defaultTag.source?.[0]?.tokens?.type || "";
181
+ member.default = tagValue;
182
+ }
183
+
184
+ if (member.privacy === "public") {
185
+ const JSDocErrors = getJSDocErrors();
186
+
187
+ if (!member.default) {
188
+ JSDocErrors.push(
189
+ `=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Default value is missing`
190
+ );
191
+ }
192
+ }
193
+
194
+ // Getters are treated as fields so they should not have return, instead of return they should have default value defined with @default
195
+ if (member.readonly) {
196
+ if (member.privacy === "public" && !member.type) {
197
+ const JSDocErrors = getJSDocErrors();
198
+
199
+ JSDocErrors.push(
200
+ `=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Missing return type`
201
+ );
202
+ }
203
+
204
+ delete member.return;
205
+ }
206
+ }
207
+ } else if (member.kind === "method") {
208
+ validateJSDocComment("method", memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
209
+
210
+ member.parameters?.forEach(param => {
211
+ // Treat every parameter that has respective @param tag as public
212
+ param._ui5privacy = findAllTags(memberParsedJsDoc, "param").some(tag => tag.name === param.name) ? "public" : "private";
213
+ if (param._ui5privacy === "public") {
214
+ const paramNode = classNodeMember.parameters?.find(parameter => parameter.name?.text === param.name);
215
+ let type;
216
+
217
+ if (param.optional) {
218
+ const filename = classNode.getSourceFile().fileName;
219
+
220
+ const sourceFile = typeProgram.getSourceFile(filename);
221
+ const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
222
+ const tsProgramMember = tsProgramClassNode.members.find(m => ts.isMethodDeclaration(m) && m.name?.text === member.name);
223
+ const tsProgramParameter = tsProgramMember.parameters.find(p => ts.isParameter(p) && p.name?.text === param.name);
224
+
225
+ if (tsProgramParameter) {
226
+ const typeName = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramParameter), tsProgramParameter);
227
+
228
+ if (!param.type) {
229
+ param.type = {};
230
+ param.type.text = typeName;
231
+ }
232
+
233
+ type = typeName.replaceAll(/Array<|>|\[\]/g, "")
234
+ ?.split("|");
235
+ }
236
+ }
237
+
238
+ const typeRefs = ((type || getTypeRefs(ts, (type || paramNode), param))
239
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
240
+
241
+ if (typeRefs.length) {
242
+ param.type.references = typeRefs;
243
+ }
244
+ }
245
+ });
246
+
247
+ if (member.return) {
248
+ const returnTag = findTag(memberParsedJsDoc, "returns");
249
+ member.return.description = returnTag?.description ? `${returnTag.name} ${returnTag.description}` : returnTag?.name;
250
+ member.return.type.text = classNodeMember?.type?.getFullText?.()?.trim();
251
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member.return)
252
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
253
+
254
+ if (typeRefs.length) {
255
+ member.return.type.references = typeRefs;
256
+ }
257
+ }
258
+
259
+ if (member.privacy === "public" && !member.return) {
260
+ const JSDocErrors = getJSDocErrors();
261
+
262
+ JSDocErrors.push(
263
+ `=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Missing return type`
264
+ );
265
+ }
266
+ }
267
+ }
268
+ }
269
+
270
+ function processInterface(ts, interfaceNode, moduleDoc) {
271
+ const interfaceJSdoc = interfaceNode?.jsDoc?.[0];
272
+ const interfaceName = interfaceNode?.name?.text;
273
+
274
+ if (!interfaceJSdoc) return;
275
+
276
+ const interfaceParsedJsDoc = parse(interfaceJSdoc?.getText(), { spacing: 'preserve' })[0];
277
+
278
+ validateJSDocComment("interface", interfaceParsedJsDoc, interfaceNode.name?.text, moduleDoc);
279
+
280
+ moduleDoc.declarations.push({
281
+ kind: "interface",
282
+ name: interfaceName,
283
+ description: normalizeDescription(interfaceParsedJsDoc?.description),
284
+ _ui5privacy: getPrivacyStatus(interfaceParsedJsDoc),
285
+ _ui5since: getSinceStatus(interfaceParsedJsDoc),
286
+ deprecated: getDeprecatedStatus(interfaceParsedJsDoc),
287
+ });
288
+ }
289
+
290
+ function processEnum(ts, enumNode, moduleDoc) {
291
+ const enumJSdoc = enumNode?.jsDoc?.[0];
292
+ const enumName = enumNode?.name?.text;
293
+
294
+ if (!enumJSdoc) return;
295
+
296
+ const enumParsedJsDoc = parse(enumJSdoc?.getText(), { spacing: 'preserve' })[0];
297
+
298
+ validateJSDocComment("enum", enumParsedJsDoc, enumNode.name?.text, moduleDoc);
299
+
300
+ const result = {
301
+ kind: "enum",
302
+ name: enumName,
303
+ description: normalizeDescription(enumJSdoc?.comment),
304
+ _ui5privacy: getPrivacyStatus(enumParsedJsDoc),
305
+ _ui5since: getSinceStatus(enumParsedJsDoc),
306
+ deprecated: getDeprecatedStatus(enumParsedJsDoc) || undefined,
307
+ members: (enumNode?.members || []).map(member => {
308
+ const memberJSdoc = member?.jsDoc?.[0];
309
+
310
+ if (!memberJSdoc) return;
311
+
312
+ const memberParsedJsDoc = parse(memberJSdoc?.getText())[0];
313
+
314
+ validateJSDocComment("enum", memberParsedJsDoc, member.name?.text, moduleDoc);
315
+
316
+ return {
317
+ kind: "field",
318
+ static: true,
319
+ privacy: getPrivacyStatus(memberParsedJsDoc),
320
+ _ui5since: getSinceStatus(memberParsedJsDoc),
321
+ description: memberJSdoc?.comment,
322
+ default: member.initializer?.text,
323
+ deprecated: getDeprecatedStatus(memberParsedJsDoc),
324
+ name: member.name?.text,
325
+ readonly: true,
326
+ };
327
+ }).filter(Boolean),
328
+ };
329
+
330
+ moduleDoc.declarations.push(result);
331
+ }
332
+
333
+ const processPublicAPI = object => {
334
+ if (!object) {
335
+ return true;
336
+ }
337
+ const keys = Object.keys(object);
338
+ if (!keys.includes("privacy") && !keys.includes("_ui5privacy")) {
339
+ return true;
340
+ }
341
+ for (const key of keys) {
342
+ if ((key === "privacy" && object[key] !== "public") || (key === "_ui5privacy" && object[key] !== "public")) {
343
+ return true;
344
+ } else if (typeof object[key] === "object") {
345
+ if (key === "cssParts" || key === "_ui5implements") {
346
+ continue;
347
+ }
348
+
349
+ if (Array.isArray(object[key])) {
350
+ for (let i = 0; i < object[key].length; i++) {
351
+ const shouldRemove = processPublicAPI(object[key][i]);
352
+ if (shouldRemove) {
353
+ object[key].splice(i, 1);
354
+ i--;
355
+ }
356
+ }
357
+ if (object[key].length === 0) {
358
+ delete object[key];
359
+ }
360
+ }
361
+ }
362
+ }
363
+ return false;
364
+ };
365
+
366
+ let typeChecker;
367
+ let typeProgram;
368
+
369
+ export default {
370
+ globs: ["src/!(*generated)/*.ts", "src/!(*bundle)*.ts"],
371
+ outdir: 'dist',
372
+ overrideModuleCreation: ({ ts, globs }) => {
373
+ typeProgram = ts.createProgram(globs, {
374
+ noEmitOnError: false,
375
+ allowJs: true,
376
+ experimentalDecorators: true,
377
+ target: 99,
378
+ downlevelIteration: true,
379
+ module: 99,
380
+ strictNullChecks: true,
381
+ moduleResolution: 2,
382
+ esModuleInterop: true,
383
+ noEmit: true,
384
+ pretty: true,
385
+ allowSyntheticDefaultImports: true,
386
+ allowUnreachableCode: true,
387
+ allowUnusedLabels: true,
388
+ skipLibCheck: true,
389
+ });
390
+ typeChecker = typeProgram.getTypeChecker();
391
+
392
+ return globs.map((glob) => {
393
+ const fullPath = path.resolve(process.cwd(), glob);
394
+ const source = fs.readFileSync(fullPath).toString();
395
+
396
+ return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
397
+ });
398
+ },
399
+ plugins: [
400
+ {
401
+ name: 'my-plugin',
402
+ analyzePhase({ ts, node, moduleDoc }) {
403
+ switch (true) {
404
+ case ts.isClassDeclaration(node):
405
+ processClass(ts, node, moduleDoc);
406
+ break;
407
+ case ts.isEnumDeclaration(node):
408
+ processEnum(ts, node, moduleDoc);
409
+ break;
410
+ case ts.isInterfaceDeclaration(node):
411
+ processInterface(ts, node, moduleDoc);
412
+ break;
413
+ }
414
+ },
415
+ moduleLinkPhase({ moduleDoc }) {
416
+ for (let i = 0; i < moduleDoc.declarations.length; i++) {
417
+ const shouldRemove = processPublicAPI(moduleDoc.declarations[i]) || ["function", "variable"].includes(moduleDoc.declarations[i].kind)
418
+ if (shouldRemove) {
419
+ moduleDoc.declarations.splice(i, 1);
420
+ i--;
421
+ }
422
+ }
423
+
424
+ if (moduleDoc.exports) {
425
+ moduleDoc.exports = moduleDoc.exports.filter(e => !(e.kind === "custom-element-definition" && !moduleDoc.declarations?.find(d => d.name === e.name)?.tagName))
426
+ }
427
+
428
+ moduleDoc.exports?.forEach(e => {
429
+ const classNode = moduleDoc.declarations.find(c => c.name === e.declaration.name);
430
+
431
+ if (classNode?.customElement && classNode.tagName && e.kind !== "custom-element-definition") {
432
+ moduleDoc.exports.push({
433
+ kind: "custom-element-definition",
434
+ name: classNode.tagName,
435
+ declaration: {
436
+ name: e.declaration.name,
437
+ module: e.declaration.module
438
+ }
439
+ })
440
+ }
441
+ })
442
+ },
443
+ packageLinkPhase({ customElementsManifest }) {
444
+ // Uncomment and handle errors appropriately
445
+ // const JSDocErrors = getJSDocErrors();
446
+ // if (JSDocErrors.length > 0) {
447
+ // console.log(JSDocErrors.join("\n"));
448
+ // console.log(`Invalid JSDoc. ${JSDocErrors.length} were found.`);
449
+ // throw new Error(`Invalid JSDoc.`);
450
+ // }
451
+
452
+ customElementsManifest.modules?.forEach(m => {
453
+ m.path = m.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
454
+
455
+ m.exports?.forEach(e => {
456
+ if (e.declaration && e.declaration.module)
457
+ e.declaration.module = e.declaration?.module?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
458
+ });
459
+ })
460
+ }
461
+ },
462
+ ],
463
+ };
@@ -0,0 +1,114 @@
1
+ import { parse } from "comment-parser";
2
+ import {
3
+ getPrivacyStatus,
4
+ getDeprecatedStatus,
5
+ getSinceStatus,
6
+ getType,
7
+ validateJSDocComment,
8
+ hasTag,
9
+ findTag,
10
+ findAllTags,
11
+ getReference,
12
+ normalizeDescription,
13
+ normalizeTagType
14
+ } from "./utils.mjs";
15
+
16
+ const jsDocRegExp = /\/\*\*(.|\n)+?\s+\*\//;
17
+
18
+ const getParams = (ts, eventDetails, commentParams, classNode, moduleDoc) => {
19
+ return commentParams?.map(commentParam => {
20
+ const decoratorParam = eventDetails?.find(prop => prop?.name?.text === commentParam?.name);
21
+
22
+ if (!decoratorParam || !decoratorParam?.jsDoc?.[0]) {
23
+ return;
24
+ }
25
+
26
+ const decoratorParamParsedComment = parse(decoratorParam?.jsDoc?.[0]?.getText?.(), { spacing: 'preserve' })[0];
27
+
28
+ validateJSDocComment("eventParam", decoratorParamParsedComment, decoratorParam.name?.text, moduleDoc);
29
+
30
+ const { typeName, name } = getType(normalizeTagType(commentParam?.type));
31
+ let type;
32
+
33
+ if (typeName) {
34
+ type = { text: typeName };
35
+
36
+ let typeRefs = name?.split("|")
37
+ ?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path))
38
+ .filter(Boolean);
39
+
40
+ if (typeRefs?.length) {
41
+ type.references = typeRefs;
42
+ }
43
+ }
44
+
45
+ return {
46
+ type,
47
+ name: commentParam?.name,
48
+ _ui5privacy: getPrivacyStatus(decoratorParamParsedComment),
49
+ description: normalizeDescription(commentParam?.description),
50
+ _ui5since: getSinceStatus(decoratorParamParsedComment),
51
+ deprecated: getDeprecatedStatus(decoratorParamParsedComment),
52
+ };
53
+ }).filter(pair => !!pair);
54
+ };
55
+
56
+ function processEvent(ts, event, classNode, moduleDoc) {
57
+ const result = {
58
+ name: event?.expression?.arguments?.[0]?.text,
59
+ _ui5privacy: "private",
60
+ type: { text: "CustomEvent" }
61
+ };
62
+
63
+ const comment = event.getFullText?.().match(jsDocRegExp)?.[0];
64
+
65
+ if (!comment) {
66
+ return result;
67
+ }
68
+
69
+ const eventParsedComment = parse(comment, { spacing: 'preserve' })[0];
70
+
71
+ validateJSDocComment("event", eventParsedComment, event?.expression?.arguments?.[0]?.text, moduleDoc);
72
+
73
+ const deprecatedTag = findTag(eventParsedComment, "deprecated");
74
+ const privacy = findTag(eventParsedComment, ["public", "private", "protected"])?.tag || "private";
75
+ const sinceTag = findTag(eventParsedComment, "since");
76
+ const commentParams = findAllTags(eventParsedComment, "param");
77
+ const allowPreventDefault = hasTag(eventParsedComment, "allowPreventDefault") || undefined;
78
+ const description = normalizeDescription(eventParsedComment?.description);
79
+ const native = hasTag(eventParsedComment, "native");
80
+ const eventDetails = event?.expression?.arguments?.[1]?.properties?.find(prop => prop?.name?.text === "detail")?.initializer?.properties;
81
+
82
+ result.description = description;
83
+ result._ui5allowPreventDefault = allowPreventDefault;
84
+
85
+ if (native) {
86
+ result.type = { text: "Event" };
87
+ }
88
+
89
+ if (privacy) {
90
+ result._ui5privacy = privacy;
91
+ }
92
+
93
+ if (deprecatedTag?.name) {
94
+ result.deprecated = deprecatedTag.description
95
+ ? `${deprecatedTag.name} ${deprecatedTag.description}`
96
+ : deprecatedTag.name;
97
+ } else if (deprecatedTag) {
98
+ result.deprecated = true;
99
+ }
100
+
101
+ if (sinceTag?.name) {
102
+ result._ui5since = sinceTag?.description
103
+ ? `${sinceTag.name} ${sinceTag.description}`
104
+ : sinceTag.name;
105
+ }
106
+
107
+ if (commentParams && eventDetails) {
108
+ result._ui5parameters = getParams(ts, eventDetails, commentParams, classNode, moduleDoc);
109
+ }
110
+
111
+ return result;
112
+ }
113
+
114
+ export default processEvent;