@rspress/plugin-typedoc 2.0.10 → 2.0.12
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/index.js +74 -0
- package/package.json +7 -14
- package/dist/es/index.js +0 -132
- /package/dist/{types/index.d.ts → index.d.ts} +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { cwd } from "node:process";
|
|
3
|
+
import { Application } from "typedoc";
|
|
4
|
+
import { load } from "typedoc-plugin-markdown";
|
|
5
|
+
import promises from "node:fs/promises";
|
|
6
|
+
async function generateMetaJson(absoluteApiDir) {
|
|
7
|
+
const metaJsonPath = node_path.join(absoluteApiDir, '_meta.json');
|
|
8
|
+
if (await promises.access(metaJsonPath).then(()=>true).catch(()=>false)) return;
|
|
9
|
+
const files = await promises.readdir(absoluteApiDir);
|
|
10
|
+
const filePaths = files.map((file)=>node_path.join(absoluteApiDir, file));
|
|
11
|
+
const stats = await Promise.all(filePaths.map((fp)=>promises.stat(fp)));
|
|
12
|
+
const dirs = stats.map((stat, index)=>stat.isDirectory() ? files[index] : null).filter(Boolean);
|
|
13
|
+
const meta = dirs.map((dir)=>({
|
|
14
|
+
type: 'dir',
|
|
15
|
+
label: dir.slice(0, 1).toUpperCase() + dir.slice(1),
|
|
16
|
+
name: dir
|
|
17
|
+
}));
|
|
18
|
+
await promises.writeFile(metaJsonPath, JSON.stringify([
|
|
19
|
+
'index',
|
|
20
|
+
...meta
|
|
21
|
+
], null, 2));
|
|
22
|
+
}
|
|
23
|
+
async function patchGeneratedApiDocs(absoluteApiDir) {
|
|
24
|
+
await generateMetaJson(absoluteApiDir);
|
|
25
|
+
}
|
|
26
|
+
function pluginTypeDoc(options) {
|
|
27
|
+
const { entryPoints: userEntryPoints = [], outDir = "api", setup = ()=>{} } = options;
|
|
28
|
+
const entryPoints = userEntryPoints.map((entryPath)=>{
|
|
29
|
+
if (!node_path.isAbsolute(entryPath)) return entryPath;
|
|
30
|
+
const cwdPosix = cwd().replace(/\\/g, '/');
|
|
31
|
+
const entryPosix = entryPath.replace(/\\/g, '/');
|
|
32
|
+
return node_path.posix.relative(cwdPosix, entryPosix);
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
name: '@rspress/plugin-typedoc',
|
|
36
|
+
async config (config) {
|
|
37
|
+
let app = await Application.bootstrapWithPlugins({
|
|
38
|
+
name: config.title,
|
|
39
|
+
entryPoints,
|
|
40
|
+
disableSources: true,
|
|
41
|
+
router: 'kind',
|
|
42
|
+
readme: 'none',
|
|
43
|
+
githubPages: false,
|
|
44
|
+
requiredToBeDocumented: [
|
|
45
|
+
'Class',
|
|
46
|
+
'Function',
|
|
47
|
+
'Interface'
|
|
48
|
+
],
|
|
49
|
+
plugin: [
|
|
50
|
+
load
|
|
51
|
+
],
|
|
52
|
+
entryFileName: 'index',
|
|
53
|
+
hidePageHeader: true,
|
|
54
|
+
hideBreadcrumbs: true,
|
|
55
|
+
pageTitleTemplates: {
|
|
56
|
+
module: '{kind}: {name}'
|
|
57
|
+
},
|
|
58
|
+
cleanOutputDir: false
|
|
59
|
+
});
|
|
60
|
+
app = await setup(app) || app;
|
|
61
|
+
const project = await app.convert();
|
|
62
|
+
if (project) {
|
|
63
|
+
const absoluteApiDir = node_path.join(config.root, outDir);
|
|
64
|
+
await app.outputs.writeOutput({
|
|
65
|
+
name: 'markdown',
|
|
66
|
+
path: absoluteApiDir
|
|
67
|
+
}, project);
|
|
68
|
+
await patchGeneratedApiDocs(absoluteApiDir);
|
|
69
|
+
}
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export { pluginTypeDoc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-typedoc",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "A plugin for rspress to integrate typedoc",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -9,21 +9,14 @@
|
|
|
9
9
|
"directory": "packages/plugin-typedoc"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"sideEffects": [
|
|
13
|
-
"*.css",
|
|
14
|
-
"*.less",
|
|
15
|
-
"*.sass",
|
|
16
|
-
"*.scss"
|
|
17
|
-
],
|
|
18
12
|
"type": "module",
|
|
19
13
|
"exports": {
|
|
20
14
|
".": {
|
|
21
|
-
"types": "./dist/
|
|
22
|
-
"import": "./dist/
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
23
17
|
}
|
|
24
18
|
},
|
|
25
|
-
"
|
|
26
|
-
"types": "./dist/types/index.d.ts",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
27
20
|
"files": [
|
|
28
21
|
"dist"
|
|
29
22
|
],
|
|
@@ -33,13 +26,13 @@
|
|
|
33
26
|
},
|
|
34
27
|
"devDependencies": {
|
|
35
28
|
"@microsoft/api-extractor": "^7.57.7",
|
|
36
|
-
"@rslib/core": "0.21.
|
|
29
|
+
"@rslib/core": "0.21.5",
|
|
37
30
|
"@types/node": "^22.8.1",
|
|
38
31
|
"@types/react": "^19.2.14",
|
|
39
32
|
"@types/react-dom": "^19.2.3",
|
|
40
|
-
"react": "^19.2.
|
|
33
|
+
"react": "^19.2.6",
|
|
41
34
|
"rsbuild-plugin-publint": "^0.3.4",
|
|
42
|
-
"typescript": "^
|
|
35
|
+
"typescript": "^6.0.3",
|
|
43
36
|
"@rspress/config": "1.0.0"
|
|
44
37
|
},
|
|
45
38
|
"peerDependencies": {
|
package/dist/es/index.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { cwd } from "process";
|
|
3
|
-
import { Application } from "typedoc";
|
|
4
|
-
import { load } from "typedoc-plugin-markdown";
|
|
5
|
-
import promises from "fs/promises";
|
|
6
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
7
|
-
try {
|
|
8
|
-
var info = gen[key](arg);
|
|
9
|
-
var value = info.value;
|
|
10
|
-
} catch (error) {
|
|
11
|
-
reject(error);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (info.done) resolve(value);
|
|
15
|
-
else Promise.resolve(value).then(_next, _throw);
|
|
16
|
-
}
|
|
17
|
-
function _async_to_generator(fn) {
|
|
18
|
-
return function() {
|
|
19
|
-
var self = this, args = arguments;
|
|
20
|
-
return new Promise(function(resolve, reject) {
|
|
21
|
-
var gen = fn.apply(self, args);
|
|
22
|
-
function _next(value) {
|
|
23
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
24
|
-
}
|
|
25
|
-
function _throw(err) {
|
|
26
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
27
|
-
}
|
|
28
|
-
_next(void 0);
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function generateMetaJson(absoluteApiDir) {
|
|
33
|
-
return _async_to_generator(function*() {
|
|
34
|
-
const metaJsonPath = path.join(absoluteApiDir, '_meta.json');
|
|
35
|
-
if (yield promises.access(metaJsonPath).then(()=>true).catch(()=>false)) return;
|
|
36
|
-
const files = yield promises.readdir(absoluteApiDir);
|
|
37
|
-
const filePaths = files.map((file)=>path.join(absoluteApiDir, file));
|
|
38
|
-
const stats = yield Promise.all(filePaths.map((fp)=>promises.stat(fp)));
|
|
39
|
-
const dirs = stats.map((stat, index)=>stat.isDirectory() ? files[index] : null).filter(Boolean);
|
|
40
|
-
const meta = dirs.map((dir)=>({
|
|
41
|
-
type: 'dir',
|
|
42
|
-
label: dir.slice(0, 1).toUpperCase() + dir.slice(1),
|
|
43
|
-
name: dir
|
|
44
|
-
}));
|
|
45
|
-
yield promises.writeFile(metaJsonPath, JSON.stringify([
|
|
46
|
-
'index',
|
|
47
|
-
...meta
|
|
48
|
-
], null, 2));
|
|
49
|
-
})();
|
|
50
|
-
}
|
|
51
|
-
function patchGeneratedApiDocs(absoluteApiDir) {
|
|
52
|
-
return _async_to_generator(function*() {
|
|
53
|
-
yield generateMetaJson(absoluteApiDir);
|
|
54
|
-
})();
|
|
55
|
-
}
|
|
56
|
-
function src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
57
|
-
try {
|
|
58
|
-
var info = gen[key](arg);
|
|
59
|
-
var value = info.value;
|
|
60
|
-
} catch (error) {
|
|
61
|
-
reject(error);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (info.done) resolve(value);
|
|
65
|
-
else Promise.resolve(value).then(_next, _throw);
|
|
66
|
-
}
|
|
67
|
-
function src_async_to_generator(fn) {
|
|
68
|
-
return function() {
|
|
69
|
-
var self = this, args = arguments;
|
|
70
|
-
return new Promise(function(resolve, reject) {
|
|
71
|
-
var gen = fn.apply(self, args);
|
|
72
|
-
function _next(value) {
|
|
73
|
-
src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
74
|
-
}
|
|
75
|
-
function _throw(err) {
|
|
76
|
-
src_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
77
|
-
}
|
|
78
|
-
_next(void 0);
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function pluginTypeDoc(options) {
|
|
83
|
-
const { entryPoints: userEntryPoints = [], outDir = "api", setup = ()=>{} } = options;
|
|
84
|
-
const entryPoints = userEntryPoints.map((entryPath)=>{
|
|
85
|
-
if (!path.isAbsolute(entryPath)) return entryPath;
|
|
86
|
-
const cwdPosix = cwd().replace(/\\/g, '/');
|
|
87
|
-
const entryPosix = entryPath.replace(/\\/g, '/');
|
|
88
|
-
return path.posix.relative(cwdPosix, entryPosix);
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
name: '@rspress/plugin-typedoc',
|
|
92
|
-
config (config) {
|
|
93
|
-
return src_async_to_generator(function*() {
|
|
94
|
-
let app = yield Application.bootstrapWithPlugins({
|
|
95
|
-
name: config.title,
|
|
96
|
-
entryPoints,
|
|
97
|
-
disableSources: true,
|
|
98
|
-
router: 'kind',
|
|
99
|
-
readme: 'none',
|
|
100
|
-
githubPages: false,
|
|
101
|
-
requiredToBeDocumented: [
|
|
102
|
-
'Class',
|
|
103
|
-
'Function',
|
|
104
|
-
'Interface'
|
|
105
|
-
],
|
|
106
|
-
plugin: [
|
|
107
|
-
load
|
|
108
|
-
],
|
|
109
|
-
entryFileName: 'index',
|
|
110
|
-
hidePageHeader: true,
|
|
111
|
-
hideBreadcrumbs: true,
|
|
112
|
-
pageTitleTemplates: {
|
|
113
|
-
module: '{kind}: {name}'
|
|
114
|
-
},
|
|
115
|
-
cleanOutputDir: false
|
|
116
|
-
});
|
|
117
|
-
app = (yield setup(app)) || app;
|
|
118
|
-
const project = yield app.convert();
|
|
119
|
-
if (project) {
|
|
120
|
-
const absoluteApiDir = path.join(config.root, outDir);
|
|
121
|
-
yield app.outputs.writeOutput({
|
|
122
|
-
name: 'markdown',
|
|
123
|
-
path: absoluteApiDir
|
|
124
|
-
}, project);
|
|
125
|
-
yield patchGeneratedApiDocs(absoluteApiDir);
|
|
126
|
-
}
|
|
127
|
-
return config;
|
|
128
|
-
})();
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
export { pluginTypeDoc };
|
|
File without changes
|