@ui5/webcomponents-tools 0.0.0-b4cbc43ba → 0.0.0-b804b8982

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 (101) hide show
  1. package/CHANGELOG.md +1833 -0
  2. package/README.md +6 -9
  3. package/assets-meta.js +22 -6
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +66 -2
  6. package/components-package/nps.js +118 -55
  7. package/components-package/postcss.components.js +1 -21
  8. package/components-package/postcss.themes.js +1 -23
  9. package/components-package/vite.config.js +9 -0
  10. package/components-package/wdio.js +108 -37
  11. package/icons-collection/nps.js +54 -11
  12. package/lib/amd-to-es6/index.js +102 -0
  13. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  14. package/lib/cem/custom-elements-manifest.config.mjs +547 -0
  15. package/lib/cem/event.mjs +168 -0
  16. package/lib/cem/schema-internal.json +1422 -0
  17. package/lib/cem/schema.json +1098 -0
  18. package/lib/cem/types-internal.d.ts +808 -0
  19. package/lib/cem/types.d.ts +736 -0
  20. package/lib/cem/utils.mjs +423 -0
  21. package/lib/cem/validate.js +67 -0
  22. package/lib/copy-and-watch/index.js +30 -5
  23. package/lib/copy-list/index.js +28 -0
  24. package/lib/create-icons/index.js +127 -56
  25. package/lib/create-illustrations/index.js +182 -0
  26. package/lib/create-new-component/Component.js +74 -0
  27. package/lib/create-new-component/ComponentTemplate.js +12 -0
  28. package/lib/create-new-component/index.js +64 -97
  29. package/lib/css-processors/css-processor-components.mjs +77 -0
  30. package/lib/css-processors/css-processor-themes.mjs +74 -0
  31. package/lib/css-processors/scope-variables.mjs +49 -0
  32. package/lib/css-processors/shared.mjs +56 -0
  33. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  34. package/lib/dev-server/dev-server.mjs +66 -0
  35. package/lib/dev-server/virtual-index-html-plugin.js +56 -0
  36. package/lib/generate-js-imports/illustrations.js +86 -0
  37. package/lib/generate-json-imports/i18n.js +66 -37
  38. package/lib/generate-json-imports/themes.js +55 -34
  39. package/lib/hbs2lit/src/compiler.js +24 -4
  40. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  41. package/lib/hbs2lit/src/litVisitor2.js +113 -25
  42. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  43. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +40 -14
  44. package/lib/hbs2ui5/index.js +57 -24
  45. package/lib/i18n/defaults.js +66 -57
  46. package/lib/i18n/toJSON.js +13 -12
  47. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  48. package/lib/remove-dev-mode/remove-dev-mode.mjs +37 -0
  49. package/lib/scoping/get-all-tags.js +11 -11
  50. package/lib/scoping/lint-src.js +9 -8
  51. package/lib/scoping/missing-dependencies.js +65 -0
  52. package/lib/scoping/report-tags-usage.js +28 -0
  53. package/lib/scoping/scope-test-pages.js +2 -1
  54. package/lib/test-runner/test-runner.js +71 -0
  55. package/package.json +55 -53
  56. package/tsconfig.json +18 -0
  57. package/bin/init-ui5-package.js +0 -3
  58. package/components-package/rollup.js +0 -147
  59. package/components-package/serve.json +0 -3
  60. package/lib/documentation/index.js +0 -155
  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 -40
  66. package/lib/documentation/templates/api-slots-section.js +0 -28
  67. package/lib/documentation/templates/template.js +0 -38
  68. package/lib/init-package/index.js +0 -123
  69. package/lib/init-package/resources/.eslintignore +0 -3
  70. package/lib/init-package/resources/bundle.es5.js +0 -25
  71. package/lib/init-package/resources/bundle.esm.js +0 -31
  72. package/lib/init-package/resources/config/.eslintrc.js +0 -1
  73. package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
  74. package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
  75. package/lib/init-package/resources/config/rollup.config.js +0 -1
  76. package/lib/init-package/resources/config/wdio.conf.js +0 -1
  77. package/lib/init-package/resources/package-scripts.js +0 -11
  78. package/lib/init-package/resources/src/Assets.js +0 -5
  79. package/lib/init-package/resources/src/MyFirstComponent.hbs +0 -1
  80. package/lib/init-package/resources/src/MyFirstComponent.js +0 -56
  81. package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
  82. package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
  83. package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
  84. package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
  85. package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
  86. package/lib/init-package/resources/src/themes/MyFirstComponent.css +0 -11
  87. package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
  88. package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
  89. package/lib/init-package/resources/src/themes/sap_belize_hcw/parameters-bundle.css +0 -3
  90. package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  91. package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
  92. package/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css +0 -3
  93. package/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css +0 -3
  94. package/lib/init-package/resources/test/pages/index.html +0 -56
  95. package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
  96. package/lib/jsdoc/config.json +0 -29
  97. package/lib/jsdoc/plugin.js +0 -2407
  98. package/lib/jsdoc/template/publish.js +0 -4092
  99. package/lib/postcss-css-to-esm/index.js +0 -42
  100. package/lib/postcss-css-to-json/index.js +0 -27
  101. package/package-lock.json +0 -48
@@ -0,0 +1,547 @@
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
+ getExperimentalStatus,
8
+ getSinceStatus,
9
+ getPrivacyStatus,
10
+ getReference,
11
+ validateJSDocComment,
12
+ findDecorator,
13
+ findAllDecorators,
14
+ hasTag,
15
+ findTag,
16
+ findAllTags,
17
+ getTypeRefs,
18
+ normalizeDescription,
19
+ formatArrays,
20
+ isClass,
21
+ normalizeTagType,
22
+ logDocumentationError,
23
+ displayDocumentationErrors,
24
+ toKebabCase
25
+ } from "./utils.mjs";
26
+ import { generateCustomData } from "cem-plugin-vs-code-custom-data-generator";
27
+ import { customElementJetBrainsPlugin } from "custom-element-jet-brains-integration";
28
+
29
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
30
+ const devMode = process.env.UI5_CEM_MODE === "dev";
31
+
32
+ const extractClassNodeJSDoc = node => {
33
+ const fileContent = node.getFullText();
34
+ const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
35
+ let allJSDocs = [...fileContent.matchAll(allJSDocsRegExp)];
36
+ allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
37
+
38
+ // Find where the class is defined in the original file
39
+ const tsClassDefinitionRegExp = new RegExp(`^\\s*(abstract\\s*)?class [\\w\\d_]+`, "gm");
40
+ let tsClassDefinitionMatch = fileContent.match(tsClassDefinitionRegExp);
41
+ if (!tsClassDefinitionMatch) {
42
+ return; // no class defined in this .ts file
43
+ }
44
+ const tsClassDefinition = tsClassDefinitionMatch[0];
45
+ const tsClassDefinitionIndex = fileContent.indexOf(tsClassDefinition);
46
+
47
+ return allJSDocs.find(JSDoc => {
48
+ return isClass(JSDoc) && (fileContent.indexOf(JSDoc) < tsClassDefinitionIndex)
49
+ });
50
+ }
51
+
52
+ function processClass(ts, classNode, moduleDoc) {
53
+ const className = classNode?.name?.text;
54
+ const currClass = moduleDoc?.declarations?.find(declaration => declaration?.name === className);
55
+ const currClassJSdoc = extractClassNodeJSDoc(classNode);
56
+
57
+ if (!currClassJSdoc) return;
58
+
59
+ const customElementDecorator = findDecorator(classNode, "customElement");
60
+ const classParsedJsDoc = parse(currClassJSdoc, { spacing: 'preserve' })[0];
61
+
62
+ validateJSDocComment("class", classParsedJsDoc, classNode.name?.text, moduleDoc);
63
+
64
+ const decoratorArg = customElementDecorator?.expression?.arguments[0];
65
+ currClass.tagName = decoratorArg?.text || (decoratorArg?.properties.find(property => property.name.text === "tag")?.initializer?.text);
66
+ currClass.customElement = !!customElementDecorator || className === "UI5Element" || undefined;
67
+ currClass.kind = "class";
68
+ currClass.deprecated = getDeprecatedStatus(classParsedJsDoc);
69
+ currClass._ui5experimental = getExperimentalStatus(classParsedJsDoc);
70
+ currClass._ui5since = getSinceStatus(classParsedJsDoc);
71
+ currClass._ui5privacy = getPrivacyStatus(classParsedJsDoc);
72
+ currClass._ui5abstract = hasTag(classParsedJsDoc, "abstract") ? true : undefined;
73
+ currClass.description = normalizeDescription(classParsedJsDoc.description || findTag(classParsedJsDoc, "class")?.description);
74
+ currClass._ui5implements = findAllTags(classParsedJsDoc, "implements")
75
+ .map(tag => {
76
+ const correctInterfaceDescription = classNode?.heritageClauses?.some(heritageClause => {
77
+ return heritageClause?.types?.some(type => type.expression?.text === normalizeTagType(tag.type));
78
+ });
79
+
80
+ if (!correctInterfaceDescription) {
81
+ logDocumentationError(moduleDoc.path, `@interface {${tag.type}} tag is used, but the class doesn't implement the corresponding interface`)
82
+ }
83
+
84
+ return getReference(ts, normalizeTagType(tag.type), classNode, moduleDoc.path)
85
+ })
86
+ .filter(Boolean);
87
+
88
+
89
+ if (hasTag(classParsedJsDoc, "extends")) {
90
+ const superclassTag = findTag(classParsedJsDoc, "extends");
91
+ currClass.superclass = getReference(ts, superclassTag.name, classNode, moduleDoc.path);
92
+
93
+ if (classNode?.heritageClauses?.[0]?.types?.[0]?.expression?.text !== superclassTag.name) {
94
+ logDocumentationError(moduleDoc.path, `@extends ${superclassTag.name} is used, but the class doesn't extend the corresponding superclass`)
95
+ }
96
+
97
+ if (currClass.superclass?.name === "UI5Element") {
98
+ currClass.customElement = true;
99
+ }
100
+ }
101
+
102
+ if (!currClass._ui5implements.length) delete currClass._ui5implements;
103
+
104
+ // Slots
105
+
106
+ // Slots without accessort (defined in class comment)
107
+ if (hasTag(classParsedJsDoc, "slot") && currClass.slots) {
108
+ const slotTags = findAllTags(classParsedJsDoc, "slot");
109
+
110
+ currClass.slots.forEach(slot => {
111
+ const tag = slotTags.find(tag => tag.name === slot.name);
112
+
113
+ const typeRefs = (normalizeTagType(tag.type)
114
+ ?.replaceAll(/Array<|>|\[\]/g, "")
115
+ ?.split("|")
116
+ ?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path)).filter(Boolean));
117
+
118
+ slot._ui5privacy = "public";
119
+ slot._ui5type = { text: formatArrays(normalizeTagType(tag.type)) };
120
+ slot.description = normalizeDescription(tag.description)
121
+
122
+ if (typeRefs && typeRefs.length) {
123
+ slot._ui5type.references = typeRefs;
124
+ }
125
+
126
+ delete slot.type
127
+ })
128
+ }
129
+
130
+ // Events
131
+ currClass.events = findAllDecorators(classNode, ["event", "eventStrict"])
132
+ ?.map(event => processEvent(ts, event, classNode, moduleDoc));
133
+
134
+ // TODO: remove after changing Button's click to custom event.
135
+ // Currently, the Button emits a native click that doesn't need and doesn't have an event decorator,
136
+ // so we add it manually to the events array.
137
+ if (currClass.tagName === "ui5-button") {
138
+ currClass.events.push({
139
+ "name": "click",
140
+ "_ui5privacy": "public",
141
+ "type": {
142
+ "text": "Event"
143
+ },
144
+ "description": "Fired when the component is activated either with a\nmouse/tap or by using the Enter or Space key.\n\n**Note:** The event will not be fired if the `disabled`\nproperty is set to `true`.",
145
+ "_ui5Cancelable": false,
146
+ "_ui5allowPreventDefault": false,
147
+ "_ui5Bubbles": true
148
+ });
149
+ }
150
+
151
+ const filename = classNode.getSourceFile().fileName;
152
+ const sourceFile = typeProgram.getSourceFile(filename);
153
+ const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
154
+
155
+ // Slots (with accessor), methods and fields
156
+ for (let i = 0; i < (currClass.members?.length || 0); i++) {
157
+ const member = currClass.members[i];
158
+ const classNodeMember = classNode.members?.find(nodeMember => nodeMember.name?.text === member?.name && nodeMember.jsDoc?.[0]);
159
+ const classNodeMemberJSdoc = classNodeMember?.jsDoc?.[0];
160
+
161
+ if (!classNodeMember || !classNodeMemberJSdoc) continue;
162
+
163
+ const memberParsedJsDoc = parse(classNodeMemberJSdoc?.getText())[0];
164
+
165
+ member._ui5since = getSinceStatus(memberParsedJsDoc);
166
+ member.deprecated === "true" && (member.deprecated = true)
167
+
168
+ // Slots with accessors are treated like fields by the tool, so we have to convert them into slots.
169
+ if (member.kind === "field") {
170
+ const slotDecorator = findDecorator(classNodeMember, "slot");
171
+ validateJSDocComment(slotDecorator ? "slot" : (member.readonly ? "getter" : "field"), memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
172
+
173
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member)
174
+ ?.map(e => getReference(ts, e, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
175
+
176
+ if (member.type?.text) {
177
+ member.type.text = formatArrays(member.type.text);
178
+ }
179
+
180
+ if (member.type && typeRefs.length) {
181
+ member.type.references = typeRefs;
182
+ }
183
+
184
+ if (slotDecorator) {
185
+ if (!currClass.slots) currClass.slots = [];
186
+
187
+ const slot = currClass.members.splice(i, 1)[0];
188
+ const defaultProperty = slotDecorator.expression?.arguments?.[0]?.properties?.find(property => property.name.text === "default");
189
+
190
+ // name of the default slot declared with decorator will be overriden so we to provide it's accessor name
191
+ if (defaultProperty && defaultProperty.initializer?.kind === ts.SyntaxKind.TrueKeyword) {
192
+ slot._ui5propertyName = slot.name;
193
+ slot.name = "default";
194
+ }
195
+
196
+ // Slots don't have type, privacy and kind, so we have do convert them and to clean unused props
197
+ member._ui5type = member.type;
198
+ member._ui5privacy = member.privacy;
199
+ delete member.type;
200
+ delete member.privacy;
201
+ delete slot.kind;
202
+
203
+ currClass.slots.push(slot);
204
+ i--;
205
+ } else {
206
+ const propertyDecorator = findDecorator(classNodeMember, "property");
207
+
208
+ if (propertyDecorator) {
209
+ member._ui5noAttribute = propertyDecorator?.expression?.arguments[0]?.properties?.find(property => property.name.text === "noAttribute")?.initializer?.kind === ts.SyntaxKind.TrueKeyword || undefined;
210
+ }
211
+
212
+ if (currClass.customElement && member.privacy === "public") {
213
+ const tsProgramMember = tsProgramClassNode.members.find(m => ts.isPropertyDeclaration(m) && m.name?.text === member.name);
214
+ const attributeValue = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramMember), tsProgramMember);
215
+
216
+ if (attributeValue === "boolean" && member.default === "true") {
217
+ logDocumentationError(moduleDoc.path, `Boolean properties must be initialzed to false. [${member.name}] property of class [${className}] is intialized to \`true\``)
218
+ }
219
+
220
+ if (!member.type) {
221
+ logDocumentationError(moduleDoc.path, `Public properties must have type. The type of [${member.name}] property is not determinated automatically. Please check it.`)
222
+ }
223
+
224
+ currClass.attributes.push({
225
+ description: member.description,
226
+ name: toKebabCase(member.name),
227
+ default: member.default,
228
+ fieldName: member.name,
229
+ type: { text: attributeValue },
230
+ deprecated: member.deprecated
231
+ })
232
+ }
233
+
234
+ if (hasTag(memberParsedJsDoc, "formProperty")) {
235
+ member._ui5formProperty = true;
236
+ }
237
+
238
+ const formEventsTag = findTag(memberParsedJsDoc, "formEvents");
239
+ if (formEventsTag) {
240
+ const tagValue = formEventsTag.description ? `${formEventsTag.name} ${formEventsTag.description}` : formEventsTag.name;
241
+ member._ui5formEvents = tagValue.trim().replaceAll(/\s+/g, ",");
242
+ }
243
+
244
+ const defaultTag = findTag(memberParsedJsDoc, "default");
245
+ if (defaultTag) {
246
+ const tagValue = defaultTag.source?.[0]?.tokens?.name || defaultTag.source?.[0]?.tokens?.description || defaultTag.source?.[0]?.tokens?.type || "";
247
+ member.default = tagValue;
248
+ }
249
+
250
+ if (member.privacy === "public" && !member.default) {
251
+ logDocumentationError(moduleDoc.path, `Missing default value for '${member.name}'.`)
252
+ }
253
+
254
+ // Getters are treated as fields so they should not have return, instead of return they should have default value defined with @default
255
+ if (member.readonly) {
256
+ if (member.privacy === "public" && !member.type) {
257
+ logDocumentationError(moduleDoc.path, `Missing return type for read-only field '${member.name}'.`)
258
+ }
259
+
260
+ delete member.return;
261
+ }
262
+ }
263
+ } else if (member.kind === "method") {
264
+ validateJSDocComment("method", memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
265
+
266
+ member.parameters?.forEach(param => {
267
+ // Treat every parameter that has respective @param tag as public
268
+ param._ui5privacy = findAllTags(memberParsedJsDoc, "param").some(tag => tag.name === param.name) ? "public" : "private";
269
+ if (param._ui5privacy === "public") {
270
+ const paramNode = classNodeMember.parameters?.find(parameter => parameter.name?.text === param.name);
271
+ let type;
272
+
273
+ if (param.optional) {
274
+ const filename = classNode.getSourceFile().fileName;
275
+
276
+ const sourceFile = typeProgram.getSourceFile(filename);
277
+ const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
278
+ const tsProgramMember = tsProgramClassNode.members.find(m => ts.isMethodDeclaration(m) && m.name?.text === member.name);
279
+ const tsProgramParameter = tsProgramMember.parameters.find(p => ts.isParameter(p) && p.name?.text === param.name);
280
+
281
+ if (tsProgramParameter) {
282
+ const typeName = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramParameter), tsProgramParameter);
283
+
284
+ if (!param.type) {
285
+ param.type = {};
286
+ param.type.text = typeName;
287
+ }
288
+
289
+ type = typeName.replaceAll(/Array<|>|\[\]/g, "")
290
+ ?.split("|");
291
+ }
292
+ }
293
+
294
+ const typeRefs = ((type || getTypeRefs(ts, (type || paramNode), param))
295
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
296
+
297
+ if (typeRefs.length) {
298
+ param.type.references = typeRefs;
299
+ }
300
+ }
301
+ });
302
+
303
+ if (member.return) {
304
+ const returnTag = findTag(memberParsedJsDoc, "returns");
305
+ member.return.description = returnTag?.description ? `${returnTag.name} ${returnTag.description}` : returnTag?.name;
306
+ member.return.type.text = formatArrays(classNodeMember?.type?.getFullText?.()?.trim());
307
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member.return)
308
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
309
+
310
+ if (typeRefs.length) {
311
+ member.return.type.references = typeRefs;
312
+ }
313
+
314
+ if (member.privacy === "public" && !member.return.type.text) {
315
+ logDocumentationError(moduleDoc.path, `Missing return type for function '${member.name}'.`)
316
+ }
317
+ } else if (member.privacy === "public") {
318
+ logDocumentationError(moduleDoc.path, `Missing return type for function '${member.name}'.`)
319
+ }
320
+ }
321
+ }
322
+ }
323
+
324
+ function processInterface(ts, interfaceNode, moduleDoc) {
325
+ const interfaceJSdoc = interfaceNode?.jsDoc?.[0];
326
+ const interfaceName = interfaceNode?.name?.text;
327
+
328
+ if (!interfaceJSdoc) return;
329
+
330
+ const interfaceParsedJsDoc = parse(interfaceJSdoc?.getText(), { spacing: 'preserve' })[0];
331
+
332
+ validateJSDocComment("interface", interfaceParsedJsDoc, interfaceNode.name?.text, moduleDoc);
333
+
334
+ moduleDoc.declarations.push({
335
+ kind: "interface",
336
+ name: interfaceName,
337
+ description: normalizeDescription(interfaceParsedJsDoc?.description),
338
+ _ui5experimental: getExperimentalStatus(interfaceParsedJsDoc),
339
+ _ui5privacy: getPrivacyStatus(interfaceParsedJsDoc),
340
+ _ui5since: getSinceStatus(interfaceParsedJsDoc),
341
+ deprecated: getDeprecatedStatus(interfaceParsedJsDoc),
342
+ });
343
+ }
344
+
345
+ function processEnum(ts, enumNode, moduleDoc) {
346
+ const enumJSdoc = enumNode?.jsDoc?.[0];
347
+ const enumName = enumNode?.name?.text;
348
+
349
+ if (!enumJSdoc) return;
350
+
351
+ const enumParsedJsDoc = parse(enumJSdoc?.getText(), { spacing: 'preserve' })[0];
352
+
353
+ validateJSDocComment("enum", enumParsedJsDoc, enumNode.name?.text, moduleDoc);
354
+
355
+ const result = {
356
+ kind: "enum",
357
+ name: enumName,
358
+ description: normalizeDescription(enumJSdoc?.comment),
359
+ _ui5experimental: getExperimentalStatus(enumParsedJsDoc),
360
+ _ui5privacy: getPrivacyStatus(enumParsedJsDoc),
361
+ _ui5since: getSinceStatus(enumParsedJsDoc),
362
+ deprecated: getDeprecatedStatus(enumParsedJsDoc) || undefined,
363
+ members: (enumNode?.members || []).map(member => {
364
+ const memberJSdoc = member?.jsDoc?.[0];
365
+
366
+ if (!memberJSdoc) return;
367
+
368
+ const memberParsedJsDoc = parse(memberJSdoc?.getText())[0];
369
+
370
+ validateJSDocComment("enum", memberParsedJsDoc, member.name?.text, moduleDoc);
371
+
372
+ return {
373
+ kind: "field",
374
+ static: true,
375
+ privacy: getPrivacyStatus(memberParsedJsDoc),
376
+ _ui5since: getSinceStatus(memberParsedJsDoc),
377
+ description: memberJSdoc?.comment,
378
+ default: member.initializer?.text,
379
+ deprecated: getDeprecatedStatus(memberParsedJsDoc),
380
+ name: member.name?.text,
381
+ readonly: true,
382
+ };
383
+ }).filter(Boolean),
384
+ };
385
+
386
+ moduleDoc.declarations.push(result);
387
+ }
388
+
389
+ const processPublicAPI = object => {
390
+ if (!object) {
391
+ return true;
392
+ }
393
+ const keys = Object.keys(object);
394
+ if (!keys.includes("privacy") && !keys.includes("_ui5privacy")) {
395
+ return true;
396
+ }
397
+ for (const key of keys) {
398
+ if ((key === "privacy" && object[key] !== "public") || (key === "_ui5privacy" && object[key] !== "public")) {
399
+ return true;
400
+ } else if (typeof object[key] === "object") {
401
+ if (key === "cssParts" || key === "attributes" || key === "_ui5implements") {
402
+ continue;
403
+ }
404
+
405
+ if (Array.isArray(object[key])) {
406
+ for (let i = 0; i < object[key].length; i++) {
407
+ const shouldRemove = processPublicAPI(object[key][i]);
408
+ if (shouldRemove) {
409
+ object[key].splice(i, 1);
410
+ i--;
411
+ }
412
+ }
413
+ if (object[key].length === 0) {
414
+ delete object[key];
415
+ }
416
+ }
417
+ }
418
+ }
419
+ return false;
420
+ };
421
+
422
+ let typeChecker;
423
+ let typeProgram;
424
+
425
+ export default {
426
+ globs: ["src/!(*generated)/*.ts", "src/!(*bundle)*.ts"],
427
+ outdir: 'dist',
428
+ overrideModuleCreation: ({ ts, globs }) => {
429
+ typeProgram = ts.createProgram(globs, {
430
+ noEmitOnError: false,
431
+ allowJs: true,
432
+ experimentalDecorators: true,
433
+ target: 99,
434
+ downlevelIteration: true,
435
+ module: 99,
436
+ strictNullChecks: true,
437
+ moduleResolution: 2,
438
+ esModuleInterop: true,
439
+ noEmit: true,
440
+ pretty: true,
441
+ allowSyntheticDefaultImports: true,
442
+ allowUnreachableCode: true,
443
+ allowUnusedLabels: true,
444
+ skipLibCheck: true,
445
+ });
446
+ typeChecker = typeProgram.getTypeChecker();
447
+
448
+ return globs.map((glob) => {
449
+ const fullPath = path.resolve(process.cwd(), glob);
450
+ const source = fs.readFileSync(fullPath).toString();
451
+
452
+ return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
453
+ });
454
+ },
455
+ plugins: [
456
+ {
457
+ name: 'my-plugin',
458
+ analyzePhase({ ts, node, moduleDoc }) {
459
+ switch (true) {
460
+ case ts.isClassDeclaration(node):
461
+ processClass(ts, node, moduleDoc);
462
+ break;
463
+ case ts.isEnumDeclaration(node):
464
+ processEnum(ts, node, moduleDoc);
465
+ break;
466
+ case ts.isInterfaceDeclaration(node):
467
+ processInterface(ts, node, moduleDoc);
468
+ break;
469
+ }
470
+ },
471
+ moduleLinkPhase({ moduleDoc }) {
472
+ moduleDoc.path = moduleDoc.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
473
+
474
+ moduleDoc.exports = moduleDoc.exports.
475
+ filter(e => !(e.kind === "custom-element-definition" && !moduleDoc.declarations?.find(d => d.name === e.name)?.tagName))
476
+
477
+ moduleDoc.exports.forEach(e => {
478
+ const classNode = moduleDoc.declarations.find(c => c.name === e.declaration.name);
479
+
480
+ if (e.declaration && e.declaration.module) {
481
+ e.declaration.module = e.declaration.module.replace(/^src/, "dist").replace(/\.ts$/, ".js");
482
+ }
483
+
484
+ if (classNode?.customElement && classNode.tagName && e.kind !== "custom-element-definition") {
485
+ moduleDoc.exports.push({
486
+ kind: "custom-element-definition",
487
+ name: classNode.tagName,
488
+ declaration: {
489
+ name: e.declaration.name,
490
+ module: e.declaration.module
491
+ }
492
+ })
493
+ }
494
+ })
495
+ },
496
+ packageLinkPhase({ customElementsManifest }) {
497
+ customElementsManifest.modules.forEach(moduleDoc => {
498
+ for (let i = 0; i < moduleDoc.declarations.length; i++) {
499
+ const shouldRemove = processPublicAPI(moduleDoc.declarations[i]) || ["function", "variable"].includes(moduleDoc.declarations[i].kind)
500
+ if (shouldRemove) {
501
+ moduleDoc.declarations.splice(i, 1);
502
+ i--;
503
+ }
504
+ }
505
+
506
+ const typeReferences = new Set();
507
+ const registerTypeReference = reference => typeReferences.add(JSON.stringify(reference))
508
+
509
+ moduleDoc.declarations.forEach(declaration => {
510
+ ["events", "slots", "members"].forEach(memberType => {
511
+ declaration[memberType]?.forEach(member => {
512
+ if (member.type?.references) {
513
+ member.type.references.forEach(registerTypeReference)
514
+ } else if (member._ui5type?.references) {
515
+ member._ui5type.references.forEach(registerTypeReference)
516
+ } else if (member.kind === "method") {
517
+ member.return?.type?.references?.forEach(registerTypeReference)
518
+
519
+ member.parameters?.forEach(parameter => {
520
+ parameter.type?.references?.forEach(registerTypeReference)
521
+ })
522
+ }
523
+ })
524
+ })
525
+ });
526
+
527
+ typeReferences.forEach(reference => {
528
+ reference = JSON.parse(reference);
529
+ if (reference.package === packageJSON?.name && reference.module === moduleDoc.path) {
530
+ const hasExport = moduleDoc.exports.some(e => e.declaration?.name === reference.name && e.declaration?.module === reference.module)
531
+
532
+ if (!hasExport) {
533
+ logDocumentationError(moduleDoc.path?.replace(/^dist/, "src").replace(/\.js$/, ".ts"), `Type '${reference.name}' is used to describe a public API but is not exported.`,)
534
+ }
535
+ }
536
+ })
537
+ });
538
+
539
+ if (devMode) {
540
+ displayDocumentationErrors();
541
+ }
542
+ }
543
+ },
544
+ generateCustomData({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false }),
545
+ customElementJetBrainsPlugin({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false })
546
+ ],
547
+ };