@versatiles/release-tool 1.0.2 → 1.0.3
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/dist/lib/typedoc.js +125 -38
- package/package.json +1 -1
package/dist/lib/typedoc.js
CHANGED
|
@@ -17,14 +17,53 @@ function* documentProject(project) {
|
|
|
17
17
|
throw new Error('No TypeScript code to document found! Is this a lib?');
|
|
18
18
|
}
|
|
19
19
|
for (const group of project.groups) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
yield '\n# ' + group.title;
|
|
21
|
+
for (const declaration of group.children) {
|
|
22
|
+
switch (declaration.kind) {
|
|
23
|
+
case ReflectionKind.Class:
|
|
24
|
+
yield* documentClass(declaration);
|
|
25
|
+
break;
|
|
26
|
+
case ReflectionKind.Function:
|
|
27
|
+
yield* documentMethod(declaration, 2);
|
|
28
|
+
break;
|
|
29
|
+
case ReflectionKind.Interface:
|
|
30
|
+
yield* documentInterface(declaration);
|
|
31
|
+
break;
|
|
32
|
+
case ReflectionKind.TypeAlias:
|
|
33
|
+
yield* documentType(declaration);
|
|
34
|
+
break;
|
|
35
|
+
case ReflectionKind.Variable:
|
|
36
|
+
yield* documentVariable(declaration);
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
throw new Error('implement ' + declaration.kind);
|
|
40
|
+
}
|
|
22
41
|
}
|
|
23
42
|
}
|
|
24
43
|
}
|
|
25
|
-
function*
|
|
26
|
-
|
|
27
|
-
yield
|
|
44
|
+
function* documentInterface(declaration) {
|
|
45
|
+
yield `\n## Interface: \`${declaration.name}\`<a id="${createAnchorId(declaration)}"></a>`;
|
|
46
|
+
yield '\n```typescript';
|
|
47
|
+
yield 'interface {';
|
|
48
|
+
for (const child of declaration.children ?? []) {
|
|
49
|
+
if (child.kind !== ReflectionKind.Property)
|
|
50
|
+
throw Error('should be a property inside an interface');
|
|
51
|
+
if (child.type == null)
|
|
52
|
+
throw Error('should have a type');
|
|
53
|
+
const name = child.name + (child.flags.isOptional ? '?' : '');
|
|
54
|
+
yield ` ${name}: ${formatTypeDeclaration(child.type)};`;
|
|
55
|
+
}
|
|
56
|
+
yield '}';
|
|
57
|
+
yield '```';
|
|
58
|
+
}
|
|
59
|
+
function* documentType(declaration) {
|
|
60
|
+
yield `\n## Type: \`${declaration.name}\`<a id="${createAnchorId(declaration)}"></a>`;
|
|
61
|
+
if (declaration.type) {
|
|
62
|
+
yield `\n**Type:** <code>${formatTypeDeclaration(declaration.type)}</code>`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function* documentClass(declaration) {
|
|
66
|
+
yield `\n## Class: \`${declaration.name}\`<a id="${createAnchorId(declaration)}"></a>`;
|
|
28
67
|
yield* documentSummaryBlock(declaration);
|
|
29
68
|
for (const group of declaration.groups ?? []) {
|
|
30
69
|
const publicMembers = group.children.filter(member => !member.flags.isPrivate && !member.flags.isProtected);
|
|
@@ -36,30 +75,29 @@ function* documentDeclaration(declaration) {
|
|
|
36
75
|
case 'Constructors':
|
|
37
76
|
if (publicMembers.length !== 1)
|
|
38
77
|
throw Error('publicMembers.length !== 1');
|
|
39
|
-
yield* documentMethod(publicMembers[0], true);
|
|
78
|
+
yield* documentMethod(publicMembers[0], 3, true);
|
|
79
|
+
continue;
|
|
80
|
+
case 'Accessors':
|
|
81
|
+
yield '\n### Accessors';
|
|
82
|
+
for (const member of publicMembers)
|
|
83
|
+
yield documentAccessor(member);
|
|
40
84
|
continue;
|
|
41
85
|
case 'Properties':
|
|
42
|
-
|
|
43
|
-
//yield '**Properties**';
|
|
86
|
+
yield '\n### Properties';
|
|
44
87
|
for (const member of publicMembers)
|
|
45
88
|
yield documentProperty(member);
|
|
46
89
|
continue;
|
|
47
90
|
case 'Methods':
|
|
48
|
-
//yield '';
|
|
49
|
-
//yield '**Methods**';
|
|
50
91
|
for (const member of publicMembers)
|
|
51
|
-
yield* documentMethod(member);
|
|
92
|
+
yield* documentMethod(member, 3);
|
|
52
93
|
continue;
|
|
53
94
|
default:
|
|
54
95
|
console.log(group);
|
|
55
96
|
throw Error('Unknown group title');
|
|
56
97
|
}
|
|
57
98
|
}
|
|
58
|
-
if (declaration.type) {
|
|
59
|
-
yield `\n**Type:** <code>${formatTypeDeclaration(declaration.type)}</code>`;
|
|
60
|
-
}
|
|
61
99
|
}
|
|
62
|
-
function* documentMethod(method, isConstructor = false) {
|
|
100
|
+
function* documentMethod(method, depth, isConstructor = false) {
|
|
63
101
|
if (method.signatures?.length !== 1)
|
|
64
102
|
throw Error('should be 1');
|
|
65
103
|
const [signature] = method.signatures;
|
|
@@ -67,8 +105,7 @@ function* documentMethod(method, isConstructor = false) {
|
|
|
67
105
|
const parameters = formatMethodParameters(signature.parameters ?? []);
|
|
68
106
|
const returnType = signature.type;
|
|
69
107
|
const methodType = isConstructor ? 'Constructor' : 'Method';
|
|
70
|
-
yield
|
|
71
|
-
yield '';
|
|
108
|
+
yield `\n${'#'.repeat(depth)} ${methodType}: \`${methodName}(${parameters})\``;
|
|
72
109
|
yield* documentSummaryBlock(signature);
|
|
73
110
|
if (signature.parameters && signature.parameters.length > 0) {
|
|
74
111
|
yield '';
|
|
@@ -77,16 +114,15 @@ function* documentMethod(method, isConstructor = false) {
|
|
|
77
114
|
yield documentProperty(parameter);
|
|
78
115
|
}
|
|
79
116
|
}
|
|
80
|
-
if (returnType) {
|
|
81
|
-
yield
|
|
82
|
-
yield `**Returns:** <code>${formatTypeDeclaration(returnType)}</code>`;
|
|
117
|
+
if (returnType && !isConstructor) {
|
|
118
|
+
yield `\n**Returns:** <code>${formatTypeDeclaration(returnType)}</code>`;
|
|
83
119
|
}
|
|
84
120
|
}
|
|
85
121
|
function formatMethodParameters(parameters) {
|
|
86
122
|
return parameters.map(param => param.name).join(', ');
|
|
87
123
|
}
|
|
88
124
|
// Helper Functions
|
|
89
|
-
function
|
|
125
|
+
function getDeclarationKindName(kind) {
|
|
90
126
|
switch (kind) {
|
|
91
127
|
case ReflectionKind.Class: return 'Class';
|
|
92
128
|
case ReflectionKind.Function: return 'Function';
|
|
@@ -101,13 +137,27 @@ function documentProperty(ref) {
|
|
|
101
137
|
if (ref.flags.isOptional)
|
|
102
138
|
line += ' (optional)';
|
|
103
139
|
const summary = extractSummary(ref.comment);
|
|
104
|
-
if (summary)
|
|
140
|
+
if (summary != null)
|
|
141
|
+
line += ' \n ' + summary;
|
|
142
|
+
return line;
|
|
143
|
+
}
|
|
144
|
+
function* documentVariable(ref) {
|
|
145
|
+
const prefix = ref.flags.isConst ? 'const' : 'let';
|
|
146
|
+
yield `\n## \`${prefix} ${ref.name}\``;
|
|
147
|
+
const summary = extractSummary(ref.comment);
|
|
148
|
+
if (summary != null)
|
|
149
|
+
yield summary;
|
|
150
|
+
}
|
|
151
|
+
function documentAccessor(ref) {
|
|
152
|
+
let line = ` - <code>${ref.name}${resolveTypeDeclaration(ref.type)}</code>`;
|
|
153
|
+
const summary = extractSummary(ref.comment);
|
|
154
|
+
if (summary != null)
|
|
105
155
|
line += ' \n ' + summary;
|
|
106
156
|
return line;
|
|
107
157
|
}
|
|
108
158
|
function extractSummary(comment) {
|
|
109
159
|
if (!comment)
|
|
110
|
-
return
|
|
160
|
+
return null;
|
|
111
161
|
return comment.summary.map(line => line.text).join('');
|
|
112
162
|
}
|
|
113
163
|
function* documentSummaryBlock(ref) {
|
|
@@ -126,10 +176,16 @@ function* documentSummaryBlock(ref) {
|
|
|
126
176
|
return;
|
|
127
177
|
}
|
|
128
178
|
}
|
|
129
|
-
|
|
179
|
+
const sourceLink = createSourceLink(ref);
|
|
180
|
+
if (sourceLink != null)
|
|
181
|
+
yield sourceLink;
|
|
130
182
|
return;
|
|
131
183
|
function formatComment(comment) {
|
|
132
|
-
|
|
184
|
+
let summary = extractSummary(comment) ?? '';
|
|
185
|
+
const link = createSourceLink(ref);
|
|
186
|
+
if (link != null)
|
|
187
|
+
summary += ' ' + link;
|
|
188
|
+
return summary.replace(/\n/m, ' \n') + '\n';
|
|
133
189
|
}
|
|
134
190
|
}
|
|
135
191
|
function resolveTypeDeclaration(someType) {
|
|
@@ -156,36 +212,67 @@ function formatTypeDeclaration(someType) {
|
|
|
156
212
|
+ '>';
|
|
157
213
|
return result;
|
|
158
214
|
case 'reflection':
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
.map(p => {
|
|
167
|
-
return p.name + (p.type ? ': ' + getTypeRec(p.type) : '');
|
|
168
|
-
}).join(', ');
|
|
169
|
-
return `(${parameters}) => ${type}`;
|
|
215
|
+
switch (some.declaration.kind) {
|
|
216
|
+
case ReflectionKind.TypeLiteral: return decodeReflectionTypeLiteral(some.declaration);
|
|
217
|
+
default:
|
|
218
|
+
console.log('declarationKindName', getDeclarationKindName(some.declaration.kind));
|
|
219
|
+
console.dir(some, { depth: 4 });
|
|
220
|
+
throw Error();
|
|
221
|
+
}
|
|
170
222
|
case 'tuple':
|
|
171
223
|
return `[${some.elements.map(getTypeRec).join(', ')}]`;
|
|
172
224
|
case 'union':
|
|
173
225
|
return some.types.map(getTypeRec).join(' | ');
|
|
226
|
+
case 'array':
|
|
227
|
+
return getTypeRec(some.elementType) + '[]';
|
|
174
228
|
default:
|
|
175
229
|
console.log(some);
|
|
176
230
|
throw Error(some.type);
|
|
177
231
|
}
|
|
232
|
+
function decodeReflectionTypeLiteral(ref) {
|
|
233
|
+
try {
|
|
234
|
+
if (ref.variant !== 'declaration')
|
|
235
|
+
throw Error();
|
|
236
|
+
if (ref.groups && !ref.signatures) {
|
|
237
|
+
if (!Array.isArray(ref.groups))
|
|
238
|
+
throw Error();
|
|
239
|
+
if (ref.groups.length !== 1)
|
|
240
|
+
throw Error();
|
|
241
|
+
const [group] = ref.groups;
|
|
242
|
+
if (group.title !== 'Properties')
|
|
243
|
+
throw Error();
|
|
244
|
+
const properties = group.children.map(r => r.escapedName + ':?');
|
|
245
|
+
return `{${properties.join(', ')}}`;
|
|
246
|
+
}
|
|
247
|
+
if (!ref.groups && ref.signatures) {
|
|
248
|
+
if (ref.signatures.length !== 1)
|
|
249
|
+
throw Error('ref.signatures.length !== 1');
|
|
250
|
+
const [signature] = ref.signatures;
|
|
251
|
+
const returnType = signature.type ? getTypeRec(signature.type) : 'void';
|
|
252
|
+
const parameters = (signature.parameters ?? [])
|
|
253
|
+
.map(p => {
|
|
254
|
+
return p.name + (p.type ? ': ' + getTypeRec(p.type) : '');
|
|
255
|
+
}).join(', ');
|
|
256
|
+
return `(${parameters}) => ${returnType}`;
|
|
257
|
+
}
|
|
258
|
+
throw Error();
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
console.dir(ref, { depth: 3 });
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
178
265
|
}
|
|
179
266
|
}
|
|
180
267
|
function createSourceLink(reference) {
|
|
181
268
|
if (!reference.sources || reference.sources.length < 1)
|
|
182
|
-
return
|
|
269
|
+
return null;
|
|
183
270
|
if (reference.sources.length > 1)
|
|
184
271
|
throw Error('ref.sources.length > 1');
|
|
185
272
|
const [source] = reference.sources;
|
|
186
273
|
return `<sup><a href="${source.url}">[src]</a></sup>`;
|
|
187
274
|
}
|
|
188
275
|
function createAnchorId(reference) {
|
|
189
|
-
return `${
|
|
276
|
+
return `${getDeclarationKindName(reference.kind)}_${reference.name}`.toLowerCase();
|
|
190
277
|
}
|
|
191
278
|
//# sourceMappingURL=typedoc.js.map
|