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