openapi-jsonrpc-jsdoc 1.5.6 → 1.6.0
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/index.mjs +50 -3
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
|
+
import { stripTypeScriptTypes } from 'node:module';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { glob } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
1
5
|
import jsdoc from 'jsdoc-api';
|
|
2
6
|
|
|
7
|
+
async function collectJsdocDocuments(options) {
|
|
8
|
+
const allFiles = [];
|
|
9
|
+
for (const pattern of options.files || []) {
|
|
10
|
+
for await (const file of glob(pattern)) {
|
|
11
|
+
allFiles.push(file);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { files: _f, package: _p, cache: _c, ...baseOptions } = options;
|
|
16
|
+
|
|
17
|
+
const allResults = [];
|
|
18
|
+
|
|
19
|
+
if (!options.cache && options.package) {
|
|
20
|
+
try {
|
|
21
|
+
const pkg = JSON.parse(readFileSync(options.package, options.encoding || 'utf8'));
|
|
22
|
+
allResults.push({
|
|
23
|
+
kind: 'package',
|
|
24
|
+
name: pkg.name,
|
|
25
|
+
version: pkg.version,
|
|
26
|
+
description: pkg.description,
|
|
27
|
+
});
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (const file of allFiles) {
|
|
32
|
+
const raw = readFileSync(file, options.encoding || 'utf8');
|
|
33
|
+
const source = /\.tsx?$/.test(file) ? stripTypeScriptTypes(raw) : raw;
|
|
34
|
+
const results = await jsdoc.explain({ ...baseOptions, source });
|
|
35
|
+
|
|
36
|
+
const basenameNoExt = path.basename(file, path.extname(file));
|
|
37
|
+
const dirname = path.dirname(file);
|
|
38
|
+
for (const item of results) {
|
|
39
|
+
if (item.meta) {
|
|
40
|
+
item.meta.filename = basenameNoExt;
|
|
41
|
+
item.meta.path = dirname;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
allResults.push(...results);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return allResults;
|
|
48
|
+
}
|
|
49
|
+
|
|
3
50
|
function extractName(name) {
|
|
4
51
|
try {
|
|
5
52
|
return name.match(/\.(.+)/i)[1]; //eslint-disable-line
|
|
@@ -200,9 +247,9 @@ export default async function openapiJsonrpcJsdoc({
|
|
|
200
247
|
}
|
|
201
248
|
let documents;
|
|
202
249
|
if (options.cache) {
|
|
203
|
-
documents = await
|
|
250
|
+
documents = await collectJsdocDocuments(options);
|
|
204
251
|
} else {
|
|
205
|
-
const allData = await
|
|
252
|
+
const allData = await collectJsdocDocuments(options);
|
|
206
253
|
documents = allData.filter(item => item.kind !== 'package');
|
|
207
254
|
const package_ = allData.find(item => item.kind === 'package');
|
|
208
255
|
info.version = package_.version;
|
|
@@ -276,7 +323,7 @@ export default async function openapiJsonrpcJsdoc({
|
|
|
276
323
|
continue prepare;
|
|
277
324
|
}
|
|
278
325
|
const {filename} = module.meta;
|
|
279
|
-
const apiName = filename.replace(/\.
|
|
326
|
+
const apiName = path.parse(filename).name || filename.replace(/\.[^.]+$/, '');
|
|
280
327
|
|
|
281
328
|
let resultValues;
|
|
282
329
|
switch (module.returns?.[0]?.description) {
|