fumadocs-typescript 4.0.13 → 5.0.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/dist/{base-Q18nCvFH.d.ts → base-C72MF-7Q.d.ts} +9 -16
- package/dist/{chunk-REUDVA2G.js → chunk-H4DZJVYN.js} +14 -4
- package/dist/index.d.ts +8 -32
- package/dist/index.js +124 -201
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +1 -1
- package/package.json +6 -6
|
@@ -47,6 +47,11 @@ interface GenerateTypeTableOptions extends GenerateOptions {
|
|
|
47
47
|
basePath?: string;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
interface Cache {
|
|
51
|
+
read: (key: string) => unknown | undefined | Promise<unknown | undefined>;
|
|
52
|
+
write: (key: string, value: unknown) => void | Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
|
|
50
55
|
interface GeneratedDoc {
|
|
51
56
|
name: string;
|
|
52
57
|
description: string;
|
|
@@ -89,29 +94,17 @@ interface GeneratorOptions extends TypescriptConfig {
|
|
|
89
94
|
/**
|
|
90
95
|
* cache results, note that some options are not marked as dependency.
|
|
91
96
|
*
|
|
92
|
-
* @defaultValue
|
|
97
|
+
* @defaultValue false
|
|
93
98
|
*/
|
|
94
|
-
cache?:
|
|
99
|
+
cache?: Cache | false;
|
|
95
100
|
project?: Project;
|
|
96
101
|
}
|
|
97
102
|
declare function createGenerator(config?: GeneratorOptions | Project): {
|
|
98
103
|
generateDocumentation(file: {
|
|
99
104
|
path: string;
|
|
100
105
|
content?: string;
|
|
101
|
-
}, name: string | undefined, options?: GenerateOptions): GeneratedDoc[]
|
|
106
|
+
}, name: string | undefined, options?: GenerateOptions): Promise<GeneratedDoc[]>;
|
|
102
107
|
generateTypeTable(props: BaseTypeTableProps, options?: GenerateTypeTableOptions): Promise<GeneratedDoc[]>;
|
|
103
108
|
};
|
|
104
|
-
/**
|
|
105
|
-
* Generate documentation for properties in an exported type/interface
|
|
106
|
-
*
|
|
107
|
-
* @deprecated use `createGenerator` instead
|
|
108
|
-
*/
|
|
109
|
-
declare function generateDocumentation(file: string, name: string | undefined, content: string, options?: GenerateOptions & {
|
|
110
|
-
/**
|
|
111
|
-
* Typescript configurations
|
|
112
|
-
*/
|
|
113
|
-
config?: TypescriptConfig;
|
|
114
|
-
project?: Project;
|
|
115
|
-
}): GeneratedDoc[];
|
|
116
109
|
|
|
117
|
-
export { type BaseTypeTableProps as B, type DocEntry as D, type
|
|
110
|
+
export { type BaseTypeTableProps as B, type Cache as C, type DocEntry as D, type GenerateTypeTableOptions as G, type RawTag as R, type Generator as a, type GeneratedDoc as b, createProject as c, type GenerateOptions as d, type GeneratorOptions as e, createGenerator as f };
|
|
@@ -57,9 +57,13 @@ import {
|
|
|
57
57
|
rehypeCode
|
|
58
58
|
} from "fumadocs-core/mdx-plugins/rehype-code";
|
|
59
59
|
import remarkRehype from "remark-rehype";
|
|
60
|
-
import {
|
|
60
|
+
import { getHighlighter } from "fumadocs-core/highlight";
|
|
61
61
|
var shikiOptions = {
|
|
62
62
|
lazy: true,
|
|
63
|
+
langs: ["ts", "tsx"],
|
|
64
|
+
// disable default transformers & meta parser
|
|
65
|
+
transformers: [],
|
|
66
|
+
parseMetaString: void 0,
|
|
63
67
|
themes: {
|
|
64
68
|
light: "github-light",
|
|
65
69
|
dark: "github-dark"
|
|
@@ -68,10 +72,16 @@ var shikiOptions = {
|
|
|
68
72
|
var processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCode, shikiOptions);
|
|
69
73
|
function renderTypeToHast(type) {
|
|
70
74
|
return __async(this, null, function* () {
|
|
71
|
-
const
|
|
75
|
+
const highlighter = yield getHighlighter("js", {
|
|
76
|
+
langs: ["ts"],
|
|
77
|
+
themes: Object.values(shikiOptions.themes)
|
|
78
|
+
});
|
|
79
|
+
const nodes = highlighter.codeToHast(type, {
|
|
72
80
|
lang: "ts",
|
|
73
|
-
structure: "inline"
|
|
74
|
-
|
|
81
|
+
structure: "inline",
|
|
82
|
+
themes: shikiOptions.themes,
|
|
83
|
+
defaultColor: false
|
|
84
|
+
});
|
|
75
85
|
return {
|
|
76
86
|
type: "element",
|
|
77
87
|
tagName: "span",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,10 @@
|
|
|
1
|
-
import { G as
|
|
2
|
-
export { e as GeneratorOptions, R as RawTag, f as createGenerator,
|
|
3
|
-
import { GlobOptions } from 'tinyglobby';
|
|
1
|
+
import { G as GenerateTypeTableOptions, a as Generator, B as BaseTypeTableProps, C as Cache } from './base-C72MF-7Q.js';
|
|
2
|
+
export { D as DocEntry, d as GenerateOptions, b as GeneratedDoc, e as GeneratorOptions, R as RawTag, f as createGenerator, c as createProject } from './base-C72MF-7Q.js';
|
|
4
3
|
import { Nodes } from 'hast';
|
|
5
4
|
import { Root } from 'mdast';
|
|
6
5
|
import { Transformer } from 'unified';
|
|
7
6
|
import 'ts-morph';
|
|
8
7
|
|
|
9
|
-
interface Templates {
|
|
10
|
-
block: (doc: GeneratedDoc, children: string) => string;
|
|
11
|
-
property: (entry: DocEntry) => string;
|
|
12
|
-
}
|
|
13
|
-
interface GenerateMDXOptions extends GenerateOptions {
|
|
14
|
-
/**
|
|
15
|
-
* a root directory to resolve relative file paths
|
|
16
|
-
*/
|
|
17
|
-
basePath?: string;
|
|
18
|
-
templates?: Partial<Templates>;
|
|
19
|
-
}
|
|
20
|
-
declare function generateMDX(generator: Generator, source: string, { basePath, templates: overrides, ...rest }?: GenerateMDXOptions): string;
|
|
21
|
-
|
|
22
|
-
interface GenerateFilesOptions {
|
|
23
|
-
input: string | string[];
|
|
24
|
-
/**
|
|
25
|
-
* Output directory, or a function that returns the output path
|
|
26
|
-
*/
|
|
27
|
-
output: string | ((inputPath: string) => string);
|
|
28
|
-
globOptions?: GlobOptions;
|
|
29
|
-
options?: GenerateMDXOptions;
|
|
30
|
-
/**
|
|
31
|
-
* @returns New content
|
|
32
|
-
*/
|
|
33
|
-
transformOutput?: (path: string, content: string) => string;
|
|
34
|
-
}
|
|
35
|
-
declare function generateFiles(generator: Generator, options: GenerateFilesOptions): Promise<void>;
|
|
36
|
-
|
|
37
8
|
declare function renderTypeToHast(type: string): Promise<Nodes>;
|
|
38
9
|
declare function renderMarkdownToHast(md: string): Promise<Nodes>;
|
|
39
10
|
|
|
@@ -58,6 +29,9 @@ interface RemarkAutoTypeTableOptions {
|
|
|
58
29
|
remarkStringify?: boolean;
|
|
59
30
|
generator?: Generator;
|
|
60
31
|
}
|
|
32
|
+
interface TypeTableProps extends BaseTypeTableProps {
|
|
33
|
+
cwd?: true;
|
|
34
|
+
}
|
|
61
35
|
/**
|
|
62
36
|
* Compile `auto-type-table` into Fumadocs UI compatible TypeTable
|
|
63
37
|
*
|
|
@@ -65,4 +39,6 @@ interface RemarkAutoTypeTableOptions {
|
|
|
65
39
|
*/
|
|
66
40
|
declare function remarkAutoTypeTable(config?: RemarkAutoTypeTableOptions): Transformer<Root, Root>;
|
|
67
41
|
|
|
68
|
-
|
|
42
|
+
declare function createFileSystemGeneratorCache(dir: string): Cache;
|
|
43
|
+
|
|
44
|
+
export { Cache, Generator, type RemarkAutoTypeTableOptions, type TypeTableProps, createFileSystemGeneratorCache, remarkAutoTypeTable, renderMarkdownToHast };
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
parseTags,
|
|
7
7
|
renderMarkdownToHast,
|
|
8
8
|
renderTypeToHast
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-H4DZJVYN.js";
|
|
10
10
|
|
|
11
11
|
// src/lib/base.ts
|
|
12
12
|
import {
|
|
@@ -25,7 +25,7 @@ function createProject(options = {}) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// src/lib/base.ts
|
|
28
|
-
import
|
|
28
|
+
import fs2 from "fs/promises";
|
|
29
29
|
|
|
30
30
|
// src/lib/type-table.ts
|
|
31
31
|
import * as fs from "fs/promises";
|
|
@@ -47,7 +47,7 @@ ${type}`;
|
|
|
47
47
|
content += `
|
|
48
48
|
export type ${typeName} = ${type}`;
|
|
49
49
|
}
|
|
50
|
-
const output = gen.generateDocumentation(
|
|
50
|
+
const output = yield gen.generateDocumentation(
|
|
51
51
|
{ path: file != null ? file : "temp.ts", content },
|
|
52
52
|
typeName,
|
|
53
53
|
options
|
|
@@ -58,36 +58,8 @@ export type ${typeName} = ${type}`;
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
// src/lib/cache.ts
|
|
62
|
-
import fs2 from "fs";
|
|
63
|
-
import { createHash } from "crypto";
|
|
64
|
-
import path from "path";
|
|
65
|
-
function createCache() {
|
|
66
|
-
const dir = path.join(process.cwd(), ".next/fumadocs-typescript");
|
|
67
|
-
try {
|
|
68
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
69
|
-
} catch (e) {
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
write(input, data) {
|
|
73
|
-
const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
|
|
74
|
-
fs2.writeFileSync(path.join(dir, `${hash}.json`), JSON.stringify(data));
|
|
75
|
-
},
|
|
76
|
-
read(input) {
|
|
77
|
-
const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
|
|
78
|
-
try {
|
|
79
|
-
return JSON.parse(
|
|
80
|
-
fs2.readFileSync(path.join(dir, `${hash}.json`)).toString()
|
|
81
|
-
);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
61
|
// src/lib/base.ts
|
|
90
|
-
import
|
|
62
|
+
import path from "path";
|
|
91
63
|
|
|
92
64
|
// src/lib/get-simple-form.ts
|
|
93
65
|
import * as ts from "ts-morph";
|
|
@@ -150,12 +122,10 @@ function dedupe(arr) {
|
|
|
150
122
|
|
|
151
123
|
// src/lib/base.ts
|
|
152
124
|
function createGenerator(config) {
|
|
153
|
-
var _a;
|
|
154
125
|
const options = config instanceof Project2 ? {
|
|
155
126
|
project: config
|
|
156
127
|
} : config;
|
|
157
|
-
const
|
|
158
|
-
const cache = cacheType === "fs" ? createCache() : null;
|
|
128
|
+
const cache = (options == null ? void 0 : options.cache) ? options.cache : null;
|
|
159
129
|
let instance;
|
|
160
130
|
function getProject() {
|
|
161
131
|
var _a2;
|
|
@@ -164,38 +134,35 @@ function createGenerator(config) {
|
|
|
164
134
|
}
|
|
165
135
|
return {
|
|
166
136
|
generateDocumentation(file, name, options2) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
137
|
+
return __async(this, null, function* () {
|
|
138
|
+
var _a2;
|
|
139
|
+
const content = (_a2 = file.content) != null ? _a2 : (yield fs2.readFile(path.resolve(file.path))).toString();
|
|
140
|
+
const cacheKey = `${file.path}:${name}:${content}`;
|
|
141
|
+
if (cache) {
|
|
142
|
+
const cached = yield cache.read(cacheKey);
|
|
143
|
+
if (cached) return cached;
|
|
144
|
+
}
|
|
145
|
+
const sourceFile = getProject().createSourceFile(file.path, content, {
|
|
146
|
+
overwrite: true
|
|
147
|
+
});
|
|
148
|
+
const out = [];
|
|
149
|
+
for (const [k, d] of sourceFile.getExportedDeclarations()) {
|
|
150
|
+
if (name && name !== k) continue;
|
|
151
|
+
if (d.length > 1)
|
|
152
|
+
console.warn(
|
|
153
|
+
`export ${k} should not have more than one type declaration.`
|
|
154
|
+
);
|
|
155
|
+
out.push(generate(getProject(), k, d[0], options2));
|
|
156
|
+
}
|
|
157
|
+
void (cache == null ? void 0 : cache.write(cacheKey, out));
|
|
158
|
+
return out;
|
|
176
159
|
});
|
|
177
|
-
const out = [];
|
|
178
|
-
for (const [k, d] of sourceFile.getExportedDeclarations()) {
|
|
179
|
-
if (name && name !== k) continue;
|
|
180
|
-
if (d.length > 1)
|
|
181
|
-
console.warn(
|
|
182
|
-
`export ${k} should not have more than one type declaration.`
|
|
183
|
-
);
|
|
184
|
-
out.push(generate(getProject(), k, d[0], options2));
|
|
185
|
-
}
|
|
186
|
-
cache == null ? void 0 : cache.write(cacheKey, out);
|
|
187
|
-
return out;
|
|
188
160
|
},
|
|
189
161
|
generateTypeTable(props, options2) {
|
|
190
162
|
return getTypeTableOutput(this, props, options2);
|
|
191
163
|
}
|
|
192
164
|
};
|
|
193
165
|
}
|
|
194
|
-
function generateDocumentation(file, name, content, options = {}) {
|
|
195
|
-
var _a;
|
|
196
|
-
const gen = createGenerator((_a = options.project) != null ? _a : options.config);
|
|
197
|
-
return gen.generateDocumentation({ path: file, content }, name, options);
|
|
198
|
-
}
|
|
199
166
|
function generate(program, name, declaration, { allowInternal = false, transform } = {}) {
|
|
200
167
|
var _a;
|
|
201
168
|
const entryContext = {
|
|
@@ -216,7 +183,7 @@ function generate(program, name, declaration, { allowInternal = false, transform
|
|
|
216
183
|
};
|
|
217
184
|
}
|
|
218
185
|
function getDocEntry(prop, context) {
|
|
219
|
-
var _a;
|
|
186
|
+
var _a, _b;
|
|
220
187
|
const { transform, program } = context;
|
|
221
188
|
if (context.type.isClass() && prop.getName().startsWith("#")) {
|
|
222
189
|
return;
|
|
@@ -229,16 +196,26 @@ function getDocEntry(prop, context) {
|
|
|
229
196
|
text: ts2.displayPartsToString(tag.getText())
|
|
230
197
|
})
|
|
231
198
|
);
|
|
199
|
+
let type = subType.getText(
|
|
200
|
+
context.declaration,
|
|
201
|
+
ts2.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts2.TypeFormatFlags.NoTruncation
|
|
202
|
+
);
|
|
232
203
|
let simplifiedType = getSimpleForm(
|
|
233
204
|
subType,
|
|
234
205
|
program.getTypeChecker(),
|
|
235
206
|
isOptional,
|
|
236
207
|
context.declaration
|
|
237
208
|
);
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
209
|
+
for (const tag of tags) {
|
|
210
|
+
if (tag.name === "fumadocsType") {
|
|
211
|
+
const match = (_a = new RegExp("`(?<name>.+)`$").exec(tag.text)) == null ? void 0 : _a[1];
|
|
212
|
+
if (match) type = match;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (tag.name === "remarks") {
|
|
216
|
+
const match = (_b = new RegExp("^`(?<name>.+)`").exec(tag.text)) == null ? void 0 : _b[1];
|
|
217
|
+
if (match) simplifiedType = match;
|
|
218
|
+
}
|
|
242
219
|
}
|
|
243
220
|
const entry = {
|
|
244
221
|
name: prop.getName(),
|
|
@@ -248,10 +225,7 @@ function getDocEntry(prop, context) {
|
|
|
248
225
|
)
|
|
249
226
|
),
|
|
250
227
|
tags,
|
|
251
|
-
type
|
|
252
|
-
context.declaration,
|
|
253
|
-
ts2.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts2.TypeFormatFlags.NoTruncation
|
|
254
|
-
),
|
|
228
|
+
type,
|
|
255
229
|
simplifiedType,
|
|
256
230
|
required: !isOptional,
|
|
257
231
|
deprecated: tags.some((tag) => tag.name === "deprecated")
|
|
@@ -260,89 +234,10 @@ function getDocEntry(prop, context) {
|
|
|
260
234
|
return entry;
|
|
261
235
|
}
|
|
262
236
|
|
|
263
|
-
// src/lib/mdx.ts
|
|
264
|
-
import * as path3 from "path";
|
|
265
|
-
var regex = new RegExp("^---type-table---\\r?\\n(?<file>.+?)(?:#(?<name>.+))?\\r?\\n---end---$", "gm");
|
|
266
|
-
var defaultTemplates = {
|
|
267
|
-
block: (doc, c) => `### ${doc.name}
|
|
268
|
-
|
|
269
|
-
${doc.description}
|
|
270
|
-
|
|
271
|
-
<div className='*:border-b [&>*:last-child]:border-b-0'>${c}</div>`,
|
|
272
|
-
property: (c) => `<div className='text-sm text-fd-muted-foreground py-4'>
|
|
273
|
-
|
|
274
|
-
<div className="flex flex-row items-center gap-4">
|
|
275
|
-
<code className="text-sm">${c.name}</code>
|
|
276
|
-
<code className="text-fd-muted-foreground">{${JSON.stringify(c.simplifiedType)}}</code>
|
|
277
|
-
</div>
|
|
278
|
-
|
|
279
|
-
Full Type: <code className="text-fd-muted-foreground">{${JSON.stringify(c.type)}}</code>
|
|
280
|
-
|
|
281
|
-
${c.description || "No Description"}
|
|
282
|
-
|
|
283
|
-
${c.tags.map((tag) => `- ${tag.name}:
|
|
284
|
-
${replaceJsDocLinks(tag.text)}`).join("\n")}
|
|
285
|
-
|
|
286
|
-
</div>`
|
|
287
|
-
};
|
|
288
|
-
function generateMDX(generator, source, _a = {}) {
|
|
289
|
-
var _b = _a, { basePath = "./", templates: overrides } = _b, rest = __objRest(_b, ["basePath", "templates"]);
|
|
290
|
-
const templates = __spreadValues(__spreadValues({}, defaultTemplates), overrides);
|
|
291
|
-
return source.replace(regex, (...args) => {
|
|
292
|
-
const groups = args[args.length - 1];
|
|
293
|
-
const file = path3.resolve(basePath, groups.file);
|
|
294
|
-
const docs = generator.generateDocumentation(
|
|
295
|
-
{ path: file },
|
|
296
|
-
groups.name,
|
|
297
|
-
rest
|
|
298
|
-
);
|
|
299
|
-
return docs.map(
|
|
300
|
-
(doc) => templates.block(doc, doc.entries.map(templates.property).join("\n"))
|
|
301
|
-
).join("\n\n");
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
function replaceJsDocLinks(md) {
|
|
305
|
-
return md.replace(new RegExp("{@link (?<link>[^}]*)}", "g"), "$1");
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// src/lib/file.ts
|
|
309
|
-
import * as path4 from "path";
|
|
310
|
-
import { mkdir, writeFile, readFile as readFile2 } from "fs/promises";
|
|
311
|
-
import { glob } from "tinyglobby";
|
|
312
|
-
function generateFiles(generator, options) {
|
|
313
|
-
return __async(this, null, function* () {
|
|
314
|
-
const files = yield glob(options.input, options.globOptions);
|
|
315
|
-
const produce = files.map((file) => __async(null, null, function* () {
|
|
316
|
-
const absolutePath = path4.resolve(file);
|
|
317
|
-
const outputPath = typeof options.output === "function" ? options.output(file) : path4.resolve(
|
|
318
|
-
options.output,
|
|
319
|
-
`${path4.basename(file, path4.extname(file))}.mdx`
|
|
320
|
-
);
|
|
321
|
-
const content = (yield readFile2(absolutePath)).toString();
|
|
322
|
-
let result = generateMDX(generator, content, __spreadValues({
|
|
323
|
-
basePath: path4.dirname(absolutePath)
|
|
324
|
-
}, options.options));
|
|
325
|
-
if (options.transformOutput) {
|
|
326
|
-
result = options.transformOutput(outputPath, result);
|
|
327
|
-
}
|
|
328
|
-
yield write(outputPath, result);
|
|
329
|
-
console.log(`Generated: ${outputPath}`);
|
|
330
|
-
}));
|
|
331
|
-
yield Promise.all(produce);
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
function write(file, content) {
|
|
335
|
-
return __async(this, null, function* () {
|
|
336
|
-
yield mkdir(path4.dirname(file), { recursive: true });
|
|
337
|
-
yield writeFile(file, content);
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
|
|
341
237
|
// src/lib/remark-auto-type-table.ts
|
|
342
238
|
import { valueToEstree } from "estree-util-value-to-estree";
|
|
343
239
|
import { visit } from "unist-util-visit";
|
|
344
240
|
import { toEstree } from "hast-util-to-estree";
|
|
345
|
-
import { dirname as dirname2 } from "path";
|
|
346
241
|
function objectBuilder() {
|
|
347
242
|
const out = {
|
|
348
243
|
type: "ObjectExpression",
|
|
@@ -382,10 +277,10 @@ function buildTypeProp(_0, _1) {
|
|
|
382
277
|
function onItem(entry) {
|
|
383
278
|
return __async(this, null, function* () {
|
|
384
279
|
const node = objectBuilder();
|
|
280
|
+
const tags = parseTags(entry.tags);
|
|
385
281
|
node.addJsxProperty("type", yield renderType(entry.simplifiedType));
|
|
386
282
|
node.addJsxProperty("typeDescription", yield renderType(entry.type));
|
|
387
283
|
node.addExpressionNode("required", valueToEstree(entry.required));
|
|
388
|
-
const tags = parseTags(entry.tags);
|
|
389
284
|
if (tags.default)
|
|
390
285
|
node.addJsxProperty("default", yield renderType(tags.default));
|
|
391
286
|
if (tags.returns)
|
|
@@ -442,74 +337,102 @@ function remarkAutoTypeTable(config = {}) {
|
|
|
442
337
|
} = config;
|
|
443
338
|
return (tree, file) => __async(null, null, function* () {
|
|
444
339
|
const queue = [];
|
|
445
|
-
|
|
340
|
+
function run(node, props) {
|
|
341
|
+
return __async(this, null, function* () {
|
|
342
|
+
let basePath = props.cwd ? file.cwd : generateOptions.basePath;
|
|
343
|
+
if (file.dirname) {
|
|
344
|
+
basePath != null ? basePath : basePath = file.dirname;
|
|
345
|
+
}
|
|
346
|
+
const output = yield generator.generateTypeTable(props, __spreadProps(__spreadValues({}, generateOptions), {
|
|
347
|
+
basePath
|
|
348
|
+
}));
|
|
349
|
+
const rendered = output.map((doc) => __async(null, null, function* () {
|
|
350
|
+
return {
|
|
351
|
+
type: "mdxJsxFlowElement",
|
|
352
|
+
name: outputName,
|
|
353
|
+
attributes: [
|
|
354
|
+
{
|
|
355
|
+
type: "mdxJsxAttribute",
|
|
356
|
+
name: "type",
|
|
357
|
+
value: {
|
|
358
|
+
type: "mdxJsxAttributeValueExpression",
|
|
359
|
+
value: remarkStringify ? JSON.stringify(doc, null, 2) : "",
|
|
360
|
+
data: {
|
|
361
|
+
estree: {
|
|
362
|
+
type: "Program",
|
|
363
|
+
sourceType: "module",
|
|
364
|
+
body: [
|
|
365
|
+
{
|
|
366
|
+
type: "ExpressionStatement",
|
|
367
|
+
expression: yield buildTypeProp(doc.entries, config)
|
|
368
|
+
}
|
|
369
|
+
]
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
],
|
|
375
|
+
children: []
|
|
376
|
+
};
|
|
377
|
+
}));
|
|
378
|
+
Object.assign(node, {
|
|
379
|
+
type: "root",
|
|
380
|
+
attributes: [],
|
|
381
|
+
children: yield Promise.all(rendered)
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
}
|
|
446
385
|
visit(tree, "mdxJsxFlowElement", (node) => {
|
|
447
386
|
if (node.name !== name) return;
|
|
448
387
|
const props = {};
|
|
449
388
|
for (const attr of node.attributes) {
|
|
450
|
-
if (attr.type !== "mdxJsxAttribute" || typeof attr.value !== "string")
|
|
389
|
+
if (attr.type !== "mdxJsxAttribute" || typeof attr.value !== "string" && attr.value !== null)
|
|
451
390
|
throw new Error(
|
|
452
|
-
"`auto-type-table`
|
|
391
|
+
"`auto-type-table` only support string & boolean attributes"
|
|
453
392
|
);
|
|
454
393
|
props[attr.name] = attr.value;
|
|
455
394
|
}
|
|
456
|
-
|
|
457
|
-
return __async(this, null, function* () {
|
|
458
|
-
var _a;
|
|
459
|
-
const output = yield generator.generateTypeTable(
|
|
460
|
-
props,
|
|
461
|
-
__spreadProps(__spreadValues({}, generateOptions), {
|
|
462
|
-
basePath: (_a = generateOptions.basePath) != null ? _a : defaultBasePath
|
|
463
|
-
})
|
|
464
|
-
);
|
|
465
|
-
const rendered = output.map((doc) => __async(null, null, function* () {
|
|
466
|
-
return {
|
|
467
|
-
type: "mdxJsxFlowElement",
|
|
468
|
-
name: outputName,
|
|
469
|
-
attributes: [
|
|
470
|
-
{
|
|
471
|
-
type: "mdxJsxAttribute",
|
|
472
|
-
name: "type",
|
|
473
|
-
value: {
|
|
474
|
-
type: "mdxJsxAttributeValueExpression",
|
|
475
|
-
value: remarkStringify ? JSON.stringify(doc, null, 2) : "",
|
|
476
|
-
data: {
|
|
477
|
-
estree: {
|
|
478
|
-
type: "Program",
|
|
479
|
-
sourceType: "module",
|
|
480
|
-
body: [
|
|
481
|
-
{
|
|
482
|
-
type: "ExpressionStatement",
|
|
483
|
-
expression: yield buildTypeProp(doc.entries, config)
|
|
484
|
-
}
|
|
485
|
-
]
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
],
|
|
491
|
-
children: []
|
|
492
|
-
};
|
|
493
|
-
}));
|
|
494
|
-
Object.assign(node, {
|
|
495
|
-
type: "root",
|
|
496
|
-
attributes: [],
|
|
497
|
-
children: yield Promise.all(rendered)
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
queue.push(run());
|
|
395
|
+
queue.push(run(node, props));
|
|
502
396
|
return "skip";
|
|
503
397
|
});
|
|
504
398
|
yield Promise.all(queue);
|
|
505
399
|
});
|
|
506
400
|
}
|
|
401
|
+
|
|
402
|
+
// src/cache/fs-cache.ts
|
|
403
|
+
import fs3 from "fs/promises";
|
|
404
|
+
import { createHash } from "crypto";
|
|
405
|
+
import path2 from "path";
|
|
406
|
+
function createFileSystemGeneratorCache(dir) {
|
|
407
|
+
dir = path2.resolve(dir);
|
|
408
|
+
const initDirPromise = fs3.mkdir(dir, { recursive: true }).catch(() => {
|
|
409
|
+
});
|
|
410
|
+
return {
|
|
411
|
+
write(input, data) {
|
|
412
|
+
return __async(this, null, function* () {
|
|
413
|
+
const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
|
|
414
|
+
yield initDirPromise;
|
|
415
|
+
yield fs3.writeFile(path2.join(dir, `${hash}.json`), JSON.stringify(data));
|
|
416
|
+
});
|
|
417
|
+
},
|
|
418
|
+
read(input) {
|
|
419
|
+
return __async(this, null, function* () {
|
|
420
|
+
const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
|
|
421
|
+
try {
|
|
422
|
+
return JSON.parse(
|
|
423
|
+
(yield fs3.readFile(path2.join(dir, `${hash}.json`))).toString()
|
|
424
|
+
);
|
|
425
|
+
} catch (e) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
507
432
|
export {
|
|
433
|
+
createFileSystemGeneratorCache,
|
|
508
434
|
createGenerator,
|
|
509
435
|
createProject,
|
|
510
|
-
generateDocumentation,
|
|
511
|
-
generateFiles,
|
|
512
|
-
generateMDX,
|
|
513
436
|
remarkAutoTypeTable,
|
|
514
437
|
renderMarkdownToHast
|
|
515
438
|
};
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { B as BaseTypeTableProps,
|
|
3
|
+
import { B as BaseTypeTableProps, a as Generator, G as GenerateTypeTableOptions } from '../base-C72MF-7Q.js';
|
|
4
4
|
import 'ts-morph';
|
|
5
5
|
|
|
6
6
|
type AutoTypeTableProps = BaseTypeTableProps;
|
package/dist/ui/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-typescript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Typescript Integration for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"@types/estree": "^1.0.8",
|
|
43
43
|
"@types/hast": "^3.0.4",
|
|
44
44
|
"@types/mdast": "^4.0.4",
|
|
45
|
-
"@types/node": "24.10.
|
|
46
|
-
"@types/react": "^19.2.
|
|
47
|
-
"@types/react-dom": "^19.2.
|
|
45
|
+
"@types/node": "24.10.2",
|
|
46
|
+
"@types/react": "^19.2.7",
|
|
47
|
+
"@types/react-dom": "^19.2.3",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"unified": "^11.0.5",
|
|
50
50
|
"eslint-config-custom": "0.0.0",
|
|
51
|
-
"fumadocs-core": "16.
|
|
52
|
-
"fumadocs-ui": "16.
|
|
51
|
+
"fumadocs-core": "16.3.2",
|
|
52
|
+
"fumadocs-ui": "16.3.2",
|
|
53
53
|
"tsconfig": "0.0.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|