vuepress-jsdoc 4.3.1 → 6.1.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/README.md +175 -96
- package/bin/vuepress-jsdoc.js +7 -4
- package/dist/cmds.d.ts +4 -2
- package/dist/cmds.js +45 -18
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +18 -5
- package/dist/index.d.ts +46 -12
- package/dist/index.js +215 -358
- package/dist/interfaces.d.ts +45 -19
- package/dist/interfaces.js +1 -2
- package/dist/lib/comment-parser.d.ts +15 -9
- package/dist/lib/comment-parser.js +46 -52
- package/dist/lib/config.d.ts +21 -0
- package/dist/lib/config.js +57 -0
- package/dist/lib/list-folder.d.ts +30 -12
- package/dist/lib/list-folder.js +105 -191
- package/dist/lib/parser.d.ts +46 -30
- package/dist/lib/parser.js +205 -247
- package/dist/lib/vue-sidebar.d.ts +61 -18
- package/dist/lib/vue-sidebar.js +111 -68
- package/dist/lib/vuepress-plugin.d.ts +48 -0
- package/dist/lib/vuepress-plugin.js +63 -0
- package/package.json +68 -115
- package/CHANGELOG.md +0 -488
- package/dist/lib/utils.d.ts +0 -19
- package/dist/lib/utils.js +0 -43
package/dist/lib/parser.js
CHANGED
|
@@ -1,265 +1,223 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1
|
+
/*
|
|
2
|
+
* @vuepress
|
|
3
|
+
* ---
|
|
4
|
+
* headline: lib/parser.ts
|
|
5
|
+
* ---
|
|
6
|
+
*/
|
|
7
|
+
import jsdoc2md from 'jsdoc-to-markdown';
|
|
8
|
+
import fs from 'node:fs/promises';
|
|
9
|
+
import nodeModule, { createRequire } from 'node:module';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { StatisticType, TYPESCRIPT_EXTENSIONS, VUE_EXTENSIONS } from '../constants.js';
|
|
13
|
+
import { parseVuepressFileHeader } from './comment-parser.js';
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
const TEMPLATE_FOLDER = fileURLToPath(new URL('../../template/', import.meta.url));
|
|
16
|
+
/**
|
|
17
|
+
* Get the folder of the generated markdown file
|
|
18
|
+
* @param {DirectoryFile} file
|
|
19
|
+
* @param {string} srcFolder
|
|
20
|
+
* @param {string} destFolder
|
|
21
|
+
* @returns {string} destination folder
|
|
22
|
+
*/
|
|
23
|
+
export const getDestFolder = (file, srcFolder, destFolder) => path.join(destFolder, path.relative(path.resolve(srcFolder), path.resolve(file.folder)));
|
|
24
|
+
/**
|
|
25
|
+
* Get a readable error message
|
|
26
|
+
* @param {unknown} error
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
const getErrorMessage = (error) => (error instanceof Error ? error.message : String(error)).split('\n').filter(Boolean).slice(0, 3).join('\n');
|
|
30
|
+
/**
|
|
31
|
+
* Remove TypeScript types from source code, so jsdoc is able to parse it.
|
|
32
|
+
* Types are replaced with whitespace, so all comments and line numbers stay intact.
|
|
33
|
+
* @param {string} code TypeScript code
|
|
34
|
+
* @returns {string} JavaScript code
|
|
35
|
+
*/
|
|
36
|
+
export const stripTypes = (code) => {
|
|
37
|
+
const { stripTypeScriptTypes } = nodeModule;
|
|
38
|
+
if (typeof stripTypeScriptTypes !== 'function') {
|
|
39
|
+
throw new Error('TypeScript files need Node.js >= 22.13 or a jsdoc config (--jsDocConfigPath)');
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
41
|
+
// stripTypeScriptTypes is still experimental and would print a warning
|
|
42
|
+
const emitWarning = process.emitWarning;
|
|
43
|
+
process.emitWarning = () => { };
|
|
53
44
|
try {
|
|
54
|
-
|
|
45
|
+
return stripTypeScriptTypes(code, { mode: 'strip' });
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
throw new Error(getErrorMessage(e), { cause: e });
|
|
55
49
|
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
50
|
finally {
|
|
58
|
-
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
51
|
+
process.emitWarning = emitWarning;
|
|
62
52
|
}
|
|
63
|
-
return ar;
|
|
64
53
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Load the TypeScript compiler API. The project of the user is preferred over the bundled one.
|
|
56
|
+
* `typescript` >= 7 has no JavaScript API anymore, so `@typescript/typescript6` is tried as well.
|
|
57
|
+
* The result is cached, because it is used for every TypeScript file.
|
|
58
|
+
* @returns {TypeScriptApi | null} TypeScript module or null if it is not installed
|
|
59
|
+
*/
|
|
60
|
+
let typescript;
|
|
61
|
+
const loadTypeScript = () => {
|
|
62
|
+
if (typescript !== undefined)
|
|
63
|
+
return typescript;
|
|
64
|
+
const requires = [createRequire(path.join(process.cwd(), 'package.json')), require];
|
|
65
|
+
for (const req of requires) {
|
|
66
|
+
for (const name of ['typescript', '@typescript/typescript6']) {
|
|
67
|
+
try {
|
|
68
|
+
const ts = req(name);
|
|
69
|
+
if (typeof ts?.transpileModule === 'function')
|
|
70
|
+
return (typescript = ts);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// try the next one
|
|
74
|
+
}
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
|
-
return
|
|
77
|
+
return (typescript = null);
|
|
73
78
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* @vuepress
|
|
81
|
-
* ---
|
|
82
|
-
* headline: lib/parser.ts
|
|
83
|
-
* ---
|
|
79
|
+
/**
|
|
80
|
+
* Transpile TypeScript with the TypeScript compiler. Comments and JSX are preserved.
|
|
81
|
+
* This supports syntax that type stripping can not handle: `enum`, `namespace`, parameter properties and JSX.
|
|
82
|
+
* @param {string} code TypeScript code
|
|
83
|
+
* @param {string} fileName used to detect `.tsx`
|
|
84
|
+
* @returns {string | null} JavaScript code or null if TypeScript is not installed
|
|
84
85
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
const transpileTypes = (code, fileName) => {
|
|
87
|
+
const ts = loadTypeScript();
|
|
88
|
+
if (!ts)
|
|
89
|
+
return null;
|
|
90
|
+
return ts.transpileModule(code, {
|
|
91
|
+
fileName,
|
|
92
|
+
reportDiagnostics: false,
|
|
93
|
+
compilerOptions: {
|
|
94
|
+
target: ts.ScriptTarget.ESNext,
|
|
95
|
+
module: ts.ModuleKind.ESNext,
|
|
96
|
+
jsx: ts.JsxEmit.Preserve,
|
|
97
|
+
removeComments: false,
|
|
98
|
+
verbatimModuleSyntax: false,
|
|
99
|
+
isolatedModules: true
|
|
100
|
+
}
|
|
101
|
+
}).outputText;
|
|
102
|
+
};
|
|
93
103
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
* @
|
|
99
|
-
* @param partials {string | string[]}
|
|
100
|
-
* @returns {object} file data
|
|
104
|
+
* Convert TypeScript to JavaScript. Type stripping of Node.js is used first, because it keeps all line numbers.
|
|
105
|
+
* If the file contains syntax which needs a transformation, the TypeScript compiler is used.
|
|
106
|
+
* @param {string} code TypeScript code
|
|
107
|
+
* @param {string} fileName
|
|
108
|
+
* @returns {string} JavaScript code
|
|
101
109
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (!file.folder)
|
|
108
|
-
return [2 /*return*/, null];
|
|
109
|
-
root = process.cwd();
|
|
110
|
-
relativePathDest = (0, path_1.join)(destFolder, file.folder.replace(srcFolder, ''));
|
|
111
|
-
folderInDest = (0, path_1.join)(root, relativePathDest);
|
|
112
|
-
folderInSrc = (0, path_1.join)(root, file.folder);
|
|
113
|
-
success = true;
|
|
114
|
-
empty = false;
|
|
115
|
-
excluded = false;
|
|
116
|
-
fileContent = '';
|
|
117
|
-
_b.label = 1;
|
|
118
|
-
case 1:
|
|
119
|
-
_b.trys.push([1, 4, , 5]);
|
|
120
|
-
content = '';
|
|
121
|
-
fileName = file.name;
|
|
122
|
-
if (fileName === '__index__') {
|
|
123
|
-
fileName = 'index';
|
|
124
|
-
}
|
|
125
|
-
return [4 /*yield*/, jsdoc_to_markdown_1.default.render({
|
|
126
|
-
'no-cache': configPath ? true : false,
|
|
127
|
-
files: [(0, path_1.join)(process.cwd(), file.folder, fileName + file.ext)],
|
|
128
|
-
configure: configPath,
|
|
129
|
-
partial: __spreadArray([
|
|
130
|
-
(0, path_1.resolve)(__filename, '../../../template/header.hbs'),
|
|
131
|
-
(0, path_1.resolve)(__filename, '../../../template/main.hbs')
|
|
132
|
-
], __read(partials), false)
|
|
133
|
-
})];
|
|
134
|
-
case 2:
|
|
135
|
-
content = _b.sent();
|
|
136
|
-
_a = comment_parser_1.parseVuepressFileHeader;
|
|
137
|
-
return [4 /*yield*/, promises_1.default.readFile("".concat((0, path_1.join)(folderInSrc, fileName + file.ext)), 'utf-8')];
|
|
138
|
-
case 3:
|
|
139
|
-
fileContent = _a.apply(void 0, [_b.sent(), file]);
|
|
140
|
-
if (content) {
|
|
141
|
-
fileContent += content;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
empty = true;
|
|
145
|
-
}
|
|
146
|
-
return [3 /*break*/, 5];
|
|
147
|
-
case 4:
|
|
148
|
-
e_1 = _b.sent();
|
|
149
|
-
success = false;
|
|
150
|
-
excluded = true;
|
|
151
|
-
return [3 /*break*/, 5];
|
|
152
|
-
case 5: return [2 /*return*/, {
|
|
153
|
-
success: success,
|
|
154
|
-
file: file,
|
|
155
|
-
empty: empty,
|
|
156
|
-
excluded: excluded,
|
|
157
|
-
relativePathDest: relativePathDest,
|
|
158
|
-
relativePathSrc: file.folder,
|
|
159
|
-
dest: folderInDest,
|
|
160
|
-
content: fileContent
|
|
161
|
-
}];
|
|
110
|
+
export const typescriptToJavaScript = (code, fileName) => {
|
|
111
|
+
let reason = 'JSX can not be stripped';
|
|
112
|
+
if (!fileName.endsWith('.tsx')) {
|
|
113
|
+
try {
|
|
114
|
+
return stripTypes(code);
|
|
162
115
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
116
|
+
catch (e) {
|
|
117
|
+
reason = getErrorMessage(e);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const transpiled = transpileTypes(code, fileName);
|
|
121
|
+
if (transpiled !== null)
|
|
122
|
+
return transpiled;
|
|
123
|
+
throw new Error(`${reason}\nInstall typescript or use a jsdoc config with babel (--jsDocConfigPath) for this file.`);
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Escape vue interpolations (`{{ }}`) outside of code, because VuePress compiles every page as a vue template.
|
|
127
|
+
* @param {string} markdown
|
|
128
|
+
* @returns {string} escaped markdown
|
|
129
|
+
*/
|
|
130
|
+
export const escapeVueInterpolation = (markdown) => markdown
|
|
131
|
+
// split by fenced code blocks, <code> and <pre> tags and inline code
|
|
132
|
+
.split(/(```[\s\S]*?```|<pre[\s\S]*?<\/pre>|<code>[\s\S]*?<\/code>|`[^`\n]*`)/)
|
|
133
|
+
// odd parts are code, which is kept. Inside <code> tags vue still interpolates.
|
|
134
|
+
.map((part, i) => i % 2 === 1 && !part.startsWith('<code>')
|
|
135
|
+
? part
|
|
136
|
+
: part.replace(/\{\{/g, '{{').replace(/\}\}/g, '}}'))
|
|
137
|
+
.join('');
|
|
166
138
|
/**
|
|
167
|
-
*
|
|
139
|
+
* Render a javascript or typescript file with jsdoc-to-markdown
|
|
168
140
|
* @param {DirectoryFile} file
|
|
169
|
-
* @param {
|
|
170
|
-
* @param {string}
|
|
171
|
-
* @returns {
|
|
141
|
+
* @param {ParseOptions} options
|
|
142
|
+
* @param {string} source content of the file
|
|
143
|
+
* @returns {Promise<string>} markdown
|
|
172
144
|
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
case 2:
|
|
197
|
-
data = _b.sent();
|
|
198
|
-
_a = comment_parser_1.parseVuepressFileHeader;
|
|
199
|
-
return [4 /*yield*/, promises_1.default.readFile("".concat((0, path_1.join)(folderInSrc, fileName + file.ext)), 'utf-8')];
|
|
200
|
-
case 3:
|
|
201
|
-
fileContent = _a.apply(void 0, [_b.sent(), file]);
|
|
202
|
-
if (data.content) {
|
|
203
|
-
fileContent += data.content;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
empty = true;
|
|
207
|
-
}
|
|
208
|
-
return [3 /*break*/, 5];
|
|
209
|
-
case 4:
|
|
210
|
-
e_2 = _b.sent();
|
|
211
|
-
console.log(e_2);
|
|
212
|
-
success = false;
|
|
213
|
-
return [3 /*break*/, 5];
|
|
214
|
-
case 5: return [2 /*return*/, {
|
|
215
|
-
success: success,
|
|
216
|
-
file: file,
|
|
217
|
-
empty: empty,
|
|
218
|
-
relativePathDest: relativePathDest,
|
|
219
|
-
relativePathSrc: file.folder,
|
|
220
|
-
dest: folderInDest,
|
|
221
|
-
content: fileContent
|
|
222
|
-
}];
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}); };
|
|
226
|
-
exports.parseVueFile = parseVueFile;
|
|
145
|
+
const renderScript = async (file, options, source) => {
|
|
146
|
+
const absolutePath = path.resolve(file.path);
|
|
147
|
+
const jsdocOptions = {
|
|
148
|
+
partial: [
|
|
149
|
+
path.join(TEMPLATE_FOLDER, 'header.hbs'),
|
|
150
|
+
path.join(TEMPLATE_FOLDER, 'main.hbs'),
|
|
151
|
+
...(options.partials || [])
|
|
152
|
+
]
|
|
153
|
+
};
|
|
154
|
+
if (options.jsDocConfigPath) {
|
|
155
|
+
// the user config takes care of the file (e.g. typescript via jsdoc-babel)
|
|
156
|
+
jsdocOptions.files = [absolutePath];
|
|
157
|
+
jsdocOptions.configure = path.resolve(options.jsDocConfigPath);
|
|
158
|
+
jsdocOptions['no-cache'] = true;
|
|
159
|
+
}
|
|
160
|
+
else if (TYPESCRIPT_EXTENSIONS.includes(file.ext)) {
|
|
161
|
+
jsdocOptions.source = typescriptToJavaScript(source, file.path);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
jsdocOptions.files = [absolutePath];
|
|
165
|
+
}
|
|
166
|
+
return jsdoc2md.render(jsdocOptions);
|
|
167
|
+
};
|
|
227
168
|
/**
|
|
228
|
-
*
|
|
229
|
-
* @param {
|
|
230
|
-
* @
|
|
231
|
-
* @returns {Promise | null} null or type with some data of the saved file
|
|
169
|
+
* Render a vue file with vue-docgen-cli
|
|
170
|
+
* @param {DirectoryFile} file
|
|
171
|
+
* @returns {Promise<string>} markdown
|
|
232
172
|
*/
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
173
|
+
const renderVue = async (file) => {
|
|
174
|
+
const { default: compileTemplates } = require('vue-docgen-cli/lib/compileTemplates');
|
|
175
|
+
const { extractConfig } = require('vue-docgen-cli/lib/docgen');
|
|
176
|
+
const fileName = path.basename(file.path);
|
|
177
|
+
const config = await extractConfig(path.resolve(file.folder));
|
|
178
|
+
const { content } = await compileTemplates('add', path.join(config.componentsRoot, fileName), config, fileName);
|
|
179
|
+
return content;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Parse a javascript, typescript or vue file and create the markdown content
|
|
183
|
+
* @param {DirectoryFile} file
|
|
184
|
+
* @param {ParseOptions} options
|
|
185
|
+
* @returns {Promise<ParseReturn>} file data
|
|
186
|
+
*/
|
|
187
|
+
export const parseFile = async (file, options) => {
|
|
188
|
+
const dest = getDestFolder(file, options.srcFolder, options.destFolder);
|
|
189
|
+
const empty = { type: StatisticType.EMPTY, file, dest, content: '' };
|
|
190
|
+
try {
|
|
191
|
+
const source = await fs.readFile(file.path, 'utf-8');
|
|
192
|
+
const isVue = VUE_EXTENSIONS.includes(file.ext);
|
|
193
|
+
const content = isVue ? await renderVue(file) : await renderScript(file, options, source);
|
|
194
|
+
if (!content?.trim())
|
|
195
|
+
return empty;
|
|
196
|
+
return {
|
|
197
|
+
type: StatisticType.INCLUDE,
|
|
198
|
+
file,
|
|
199
|
+
dest,
|
|
200
|
+
content: parseVuepressFileHeader(source, file) + escapeVueInterpolation(content.trim()) + '\n'
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
catch (e) {
|
|
204
|
+
const error = getErrorMessage(e);
|
|
205
|
+
// the file is excluded by the jsdoc config (source.excludePattern)
|
|
206
|
+
if (/no input files to process/i.test(error))
|
|
207
|
+
return empty;
|
|
208
|
+
return { ...empty, type: StatisticType.ERROR, error };
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Write the parsed content to disk. Files without content are skipped.
|
|
213
|
+
* @param {ParseReturn} parseData
|
|
214
|
+
* @returns {Promise<string | null>} path of the written file or null
|
|
215
|
+
*/
|
|
216
|
+
export const writeContentToFile = async (parseData) => {
|
|
217
|
+
if (parseData.type !== StatisticType.INCLUDE || !parseData.content)
|
|
218
|
+
return null;
|
|
219
|
+
const filePath = path.join(parseData.dest, `${parseData.file.name}.md`);
|
|
220
|
+
await fs.mkdir(parseData.dest, { recursive: true });
|
|
221
|
+
await fs.writeFile(filePath, parseData.content, 'utf-8');
|
|
222
|
+
return filePath;
|
|
223
|
+
};
|
|
@@ -1,23 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
|
|
1
|
+
import { FileTree } from '../interfaces.js';
|
|
2
|
+
export interface SidebarGroup {
|
|
3
|
+
text: string;
|
|
4
|
+
collapsible: boolean;
|
|
5
|
+
children: SidebarItem[];
|
|
6
|
+
}
|
|
7
|
+
export type SidebarItem = string | {
|
|
8
|
+
text: string;
|
|
9
|
+
link: string;
|
|
10
|
+
} | SidebarGroup;
|
|
11
|
+
export interface SidebarOptions {
|
|
12
|
+
/** tree structure, created by `listFolder` */
|
|
13
|
+
fileTree: FileTree[];
|
|
14
|
+
/** name of the folder inside the vuepress folder, e.g. `code` */
|
|
13
15
|
codeFolder: string;
|
|
16
|
+
/** source folder, e.g. `src` */
|
|
14
17
|
srcFolder: string;
|
|
18
|
+
/** folder of the generated markdown files, e.g. `documentation/code` */
|
|
15
19
|
docsFolder: string;
|
|
20
|
+
/** title of the first sidebar group */
|
|
16
21
|
title: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
/** sidebar format of the generated `config.js` */
|
|
23
|
+
format?: SiteFormat;
|
|
24
|
+
/** text of the first entry, which links to the readme */
|
|
25
|
+
readmeTitle?: string;
|
|
26
|
+
/** make the top level groups collapsible. Nested folders are always collapsible. */
|
|
27
|
+
collapsible?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export type SiteFormat = 'vuepress' | 'vitepress';
|
|
30
|
+
/**
|
|
31
|
+
* Get the route of the generated folder, e.g. `/code/`
|
|
32
|
+
* @param {string} codeFolder
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
export declare const getSidebarBase: (codeFolder: string) => string;
|
|
36
|
+
export interface VitepressSidebarItem {
|
|
37
|
+
text: string;
|
|
38
|
+
link?: string;
|
|
39
|
+
collapsed?: boolean;
|
|
40
|
+
items?: VitepressSidebarItem[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Runs through the given tree structure and creates a vuepress 2 sidebar config.
|
|
44
|
+
* Only pages that were generated are linked. Folders become nested sidebar groups.
|
|
45
|
+
* @param {SidebarOptions} data Information to build config
|
|
46
|
+
* @returns {object} returns the vuepress sidebar structure
|
|
47
|
+
*/
|
|
48
|
+
export declare const generateVueSidebar: ({ fileTree, codeFolder, srcFolder, docsFolder, title, readmeTitle, collapsible }: SidebarOptions) => {
|
|
49
|
+
[x: string]: SidebarGroup[];
|
|
23
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Runs through the given tree structure and creates a vitepress sidebar config.
|
|
53
|
+
* Vitepress needs the text of every link, so it is read from the generated page.
|
|
54
|
+
* @param {SidebarOptions} data Information to build config
|
|
55
|
+
* @returns {object} returns the vitepress sidebar structure
|
|
56
|
+
*/
|
|
57
|
+
export declare const generateVitepressSidebar: (data: SidebarOptions) => {
|
|
58
|
+
[x: string]: VitepressSidebarItem[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Create the content of the `config.js`, which is placed into the generated folder.
|
|
62
|
+
* It exports the file tree and a `sidebarTree(title)` function, which returns the vuepress or vitepress sidebar.
|
|
63
|
+
* @param {SidebarOptions} options
|
|
64
|
+
* @returns {string} javascript code (ES module)
|
|
65
|
+
*/
|
|
66
|
+
export declare const createSidebarConfig: (options: SidebarOptions) => string;
|