fumadocs-typescript 4.0.0 → 4.0.2
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.
|
@@ -8,6 +8,45 @@ interface TypescriptConfig {
|
|
|
8
8
|
}
|
|
9
9
|
declare function getProject(options?: TypescriptConfig): Project;
|
|
10
10
|
|
|
11
|
+
interface BaseTypeTableProps {
|
|
12
|
+
/**
|
|
13
|
+
* The path to source TypeScript file.
|
|
14
|
+
*/
|
|
15
|
+
path?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Exported type name to generate from.
|
|
18
|
+
*/
|
|
19
|
+
name?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Set the type to generate from.
|
|
22
|
+
*
|
|
23
|
+
* When used with `name`, it generates the type with `name` as export name.
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* export const myName = MyType;
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* When `type` contains multiple lines, `export const` is not added.
|
|
30
|
+
* You need to export it manually, and specify the type name with `name`.
|
|
31
|
+
*
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <AutoTypeTable
|
|
34
|
+
* path="./file.ts"
|
|
35
|
+
* type={`import { ReactNode } from "react"
|
|
36
|
+
* export const MyName = ReactNode`}
|
|
37
|
+
* name="MyName"
|
|
38
|
+
* />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
type?: string;
|
|
42
|
+
}
|
|
43
|
+
interface GenerateTypeTableOptions extends GenerateOptions {
|
|
44
|
+
/**
|
|
45
|
+
* base path to resolve `path` prop
|
|
46
|
+
*/
|
|
47
|
+
basePath?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
11
50
|
interface GeneratedDoc {
|
|
12
51
|
name: string;
|
|
13
52
|
description: string;
|
|
@@ -45,6 +84,7 @@ declare function createGenerator(config?: TypescriptConfig | Project): {
|
|
|
45
84
|
path: string;
|
|
46
85
|
content?: string;
|
|
47
86
|
}, name: string | undefined, options?: GenerateOptions): GeneratedDoc[];
|
|
87
|
+
generateTypeTable(props: BaseTypeTableProps, options?: GenerateTypeTableOptions): Promise<GeneratedDoc[]>;
|
|
48
88
|
};
|
|
49
89
|
/**
|
|
50
90
|
* Generate documentation for properties in an exported type/interface
|
|
@@ -59,43 +99,4 @@ declare function generateDocumentation(file: string, name: string | undefined, c
|
|
|
59
99
|
project?: Project;
|
|
60
100
|
}): GeneratedDoc[];
|
|
61
101
|
|
|
62
|
-
interface BaseTypeTableProps {
|
|
63
|
-
/**
|
|
64
|
-
* The path to source TypeScript file.
|
|
65
|
-
*/
|
|
66
|
-
path?: string;
|
|
67
|
-
/**
|
|
68
|
-
* Exported type name to generate from.
|
|
69
|
-
*/
|
|
70
|
-
name?: string;
|
|
71
|
-
/**
|
|
72
|
-
* Set the type to generate from.
|
|
73
|
-
*
|
|
74
|
-
* When used with `name`, it generates the type with `name` as export name.
|
|
75
|
-
*
|
|
76
|
-
* ```ts
|
|
77
|
-
* export const myName = MyType;
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* When `type` contains multiple lines, `export const` is not added.
|
|
81
|
-
* You need to export it manually, and specify the type name with `name`.
|
|
82
|
-
*
|
|
83
|
-
* ```tsx
|
|
84
|
-
* <AutoTypeTable
|
|
85
|
-
* path="./file.ts"
|
|
86
|
-
* type={`import { ReactNode } from "react"
|
|
87
|
-
* export const MyName = ReactNode`}
|
|
88
|
-
* name="MyName"
|
|
89
|
-
* />
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
type?: string;
|
|
93
|
-
}
|
|
94
|
-
interface GenerateTypeTableOptions extends GenerateOptions {
|
|
95
|
-
/**
|
|
96
|
-
* base path to resolve `path` prop
|
|
97
|
-
*/
|
|
98
|
-
basePath?: string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
102
|
export { type BaseTypeTableProps as B, type DocEntry as D, type GenerateOptions as G, type GeneratedDoc as a, type Generator as b, type GenerateTypeTableOptions as c, createGenerator as d, generateDocumentation as e, getProject as g };
|
|
@@ -77,42 +77,10 @@ function renderMarkdownToHast(md) {
|
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
// src/utils/type-table.ts
|
|
81
|
-
import * as fs from "node:fs/promises";
|
|
82
|
-
import { join } from "node:path";
|
|
83
|
-
function getTypeTableOutput(gen, _a, options) {
|
|
84
|
-
return __async(this, null, function* () {
|
|
85
|
-
var _b = _a, { name, type } = _b, props = __objRest(_b, ["name", "type"]);
|
|
86
|
-
const file = props.path && (options == null ? void 0 : options.basePath) ? join(options.basePath, props.path) : props.path;
|
|
87
|
-
let typeName = name;
|
|
88
|
-
let content = "";
|
|
89
|
-
if (file) {
|
|
90
|
-
content = (yield fs.readFile(file)).toString();
|
|
91
|
-
}
|
|
92
|
-
if (type && type.split("\n").length > 1) {
|
|
93
|
-
content += `
|
|
94
|
-
${type}`;
|
|
95
|
-
} else if (type) {
|
|
96
|
-
typeName != null ? typeName : typeName = "$Fumadocs";
|
|
97
|
-
content += `
|
|
98
|
-
export type ${typeName} = ${type}`;
|
|
99
|
-
}
|
|
100
|
-
const output = gen.generateDocumentation(
|
|
101
|
-
{ path: file != null ? file : "temp.ts", content },
|
|
102
|
-
typeName,
|
|
103
|
-
options
|
|
104
|
-
);
|
|
105
|
-
if (name && output.length === 0)
|
|
106
|
-
throw new Error(`${name} in ${file != null ? file : "empty file"} doesn't exist`);
|
|
107
|
-
return output;
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
80
|
export {
|
|
112
81
|
__spreadValues,
|
|
113
82
|
__spreadProps,
|
|
114
83
|
__objRest,
|
|
115
84
|
__async,
|
|
116
|
-
renderMarkdownToHast
|
|
117
|
-
getTypeTableOutput
|
|
85
|
+
renderMarkdownToHast
|
|
118
86
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GenerateOptions, a as GeneratedDoc, D as DocEntry, b as Generator, c as GenerateTypeTableOptions } from './
|
|
2
|
-
export { d as createGenerator, e as generateDocumentation, g as getProject } from './
|
|
1
|
+
import { G as GenerateOptions, a as GeneratedDoc, D as DocEntry, b as Generator, c as GenerateTypeTableOptions } from './base-ze7ajmJT.js';
|
|
2
|
+
export { d as createGenerator, e as generateDocumentation, g as getProject } from './base-ze7ajmJT.js';
|
|
3
3
|
import fg from 'fast-glob';
|
|
4
4
|
import { Nodes } from 'hast';
|
|
5
5
|
import { Root } from 'mdast';
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,8 @@ import {
|
|
|
3
3
|
__objRest,
|
|
4
4
|
__spreadProps,
|
|
5
5
|
__spreadValues,
|
|
6
|
-
getTypeTableOutput,
|
|
7
6
|
renderMarkdownToHast
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-B4VUDCYC.js";
|
|
9
8
|
|
|
10
9
|
// src/lib/base.ts
|
|
11
10
|
import {
|
|
@@ -24,7 +23,40 @@ function getProject(options = {}) {
|
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
// src/lib/base.ts
|
|
27
|
-
import
|
|
26
|
+
import fs2 from "node:fs";
|
|
27
|
+
|
|
28
|
+
// src/lib/type-table.ts
|
|
29
|
+
import * as fs from "node:fs/promises";
|
|
30
|
+
import { join } from "node:path";
|
|
31
|
+
function getTypeTableOutput(gen, _a, options) {
|
|
32
|
+
return __async(this, null, function* () {
|
|
33
|
+
var _b = _a, { name, type } = _b, props = __objRest(_b, ["name", "type"]);
|
|
34
|
+
const file = props.path && (options == null ? void 0 : options.basePath) ? join(options.basePath, props.path) : props.path;
|
|
35
|
+
let typeName = name;
|
|
36
|
+
let content = "";
|
|
37
|
+
if (file) {
|
|
38
|
+
content = (yield fs.readFile(file)).toString();
|
|
39
|
+
}
|
|
40
|
+
if (type && type.split("\n").length > 1) {
|
|
41
|
+
content += `
|
|
42
|
+
${type}`;
|
|
43
|
+
} else if (type) {
|
|
44
|
+
typeName != null ? typeName : typeName = "$Fumadocs";
|
|
45
|
+
content += `
|
|
46
|
+
export type ${typeName} = ${type}`;
|
|
47
|
+
}
|
|
48
|
+
const output = gen.generateDocumentation(
|
|
49
|
+
{ path: file != null ? file : "temp.ts", content },
|
|
50
|
+
typeName,
|
|
51
|
+
options
|
|
52
|
+
);
|
|
53
|
+
if (name && output.length === 0)
|
|
54
|
+
throw new Error(`${name} in ${file != null ? file : "empty file"} doesn't exist`);
|
|
55
|
+
return output;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/lib/base.ts
|
|
28
60
|
function createGenerator(config) {
|
|
29
61
|
const project = config instanceof Project2 ? config : getProject(config);
|
|
30
62
|
return {
|
|
@@ -32,7 +64,7 @@ function createGenerator(config) {
|
|
|
32
64
|
var _a;
|
|
33
65
|
const sourceFile = project.createSourceFile(
|
|
34
66
|
file.path,
|
|
35
|
-
(_a = file.content) != null ? _a :
|
|
67
|
+
(_a = file.content) != null ? _a : fs2.readFileSync(file.path).toString(),
|
|
36
68
|
{
|
|
37
69
|
overwrite: true
|
|
38
70
|
}
|
|
@@ -47,6 +79,9 @@ function createGenerator(config) {
|
|
|
47
79
|
out.push(generate(project, k, d[0], options));
|
|
48
80
|
}
|
|
49
81
|
return out;
|
|
82
|
+
},
|
|
83
|
+
generateTypeTable(props, options) {
|
|
84
|
+
return getTypeTableOutput(this, props, options);
|
|
50
85
|
}
|
|
51
86
|
};
|
|
52
87
|
}
|
|
@@ -84,10 +119,16 @@ function getDocEntry(prop, context) {
|
|
|
84
119
|
const tags = Object.fromEntries(
|
|
85
120
|
prop.getJsDocTags().map((tag) => [tag.getName(), ts.displayPartsToString(tag.getText())])
|
|
86
121
|
);
|
|
87
|
-
let typeName = subType.
|
|
122
|
+
let typeName = subType.getText(
|
|
123
|
+
void 0,
|
|
124
|
+
ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
|
|
125
|
+
);
|
|
88
126
|
if (subType.getAliasSymbol() && subType.getAliasTypeArguments().length === 0) {
|
|
89
127
|
typeName = (_b = (_a = subType.getAliasSymbol()) == null ? void 0 : _a.getEscapedName()) != null ? _b : typeName;
|
|
90
128
|
}
|
|
129
|
+
if (prop.isOptional() && typeName.endsWith("| undefined")) {
|
|
130
|
+
typeName = typeName.slice(0, typeName.length - "| undefined".length).trimEnd();
|
|
131
|
+
}
|
|
91
132
|
if ("remarks" in tags) {
|
|
92
133
|
typeName = (_d = (_c = new RegExp("^`(?<name>.+)`").exec(tags.remarks)) == null ? void 0 : _c[1]) != null ? _d : typeName;
|
|
93
134
|
}
|
|
@@ -151,7 +192,7 @@ function replaceJsDocLinks(md) {
|
|
|
151
192
|
|
|
152
193
|
// src/lib/file.ts
|
|
153
194
|
import * as path2 from "node:path";
|
|
154
|
-
import { mkdir, writeFile, readFile } from "node:fs/promises";
|
|
195
|
+
import { mkdir, writeFile, readFile as readFile2 } from "node:fs/promises";
|
|
155
196
|
import fg from "fast-glob";
|
|
156
197
|
function generateFiles(generator, options) {
|
|
157
198
|
return __async(this, null, function* () {
|
|
@@ -162,7 +203,7 @@ function generateFiles(generator, options) {
|
|
|
162
203
|
options.output,
|
|
163
204
|
`${path2.basename(file, path2.extname(file))}.mdx`
|
|
164
205
|
);
|
|
165
|
-
const content = (yield
|
|
206
|
+
const content = (yield readFile2(absolutePath)).toString();
|
|
166
207
|
let result = generateMDX(generator, content, __spreadValues({
|
|
167
208
|
basePath: path2.dirname(absolutePath)
|
|
168
209
|
}, options.options));
|
|
@@ -191,7 +232,8 @@ function mapProperty(entry, renderMarkdown) {
|
|
|
191
232
|
return __async(this, null, function* () {
|
|
192
233
|
const value = valueToEstree({
|
|
193
234
|
type: entry.type,
|
|
194
|
-
default: entry.tags.default || entry.tags.defaultValue
|
|
235
|
+
default: entry.tags.default || entry.tags.defaultValue,
|
|
236
|
+
required: entry.required
|
|
195
237
|
});
|
|
196
238
|
if (entry.description) {
|
|
197
239
|
const hast = toEstree(yield renderMarkdown(entry.description), {
|
|
@@ -248,8 +290,7 @@ function remarkAutoTypeTable({
|
|
|
248
290
|
}
|
|
249
291
|
function run() {
|
|
250
292
|
return __async(this, null, function* () {
|
|
251
|
-
const output = yield
|
|
252
|
-
generator,
|
|
293
|
+
const output = yield generator.generateTypeTable(
|
|
253
294
|
props,
|
|
254
295
|
__spreadProps(__spreadValues({}, options), {
|
|
255
296
|
basePath
|
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, b as Generator, c as GenerateTypeTableOptions } from '../
|
|
3
|
+
import { B as BaseTypeTableProps, b as Generator, c as GenerateTypeTableOptions } from '../base-ze7ajmJT.js';
|
|
4
4
|
import 'ts-morph';
|
|
5
5
|
|
|
6
6
|
type AutoTypeTableProps = BaseTypeTableProps;
|
package/dist/ui/index.js
CHANGED
|
@@ -3,9 +3,8 @@ import {
|
|
|
3
3
|
__objRest,
|
|
4
4
|
__spreadProps,
|
|
5
5
|
__spreadValues,
|
|
6
|
-
getTypeTableOutput,
|
|
7
6
|
renderMarkdownToHast
|
|
8
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-B4VUDCYC.js";
|
|
9
8
|
|
|
10
9
|
// src/ui/auto-type-table.tsx
|
|
11
10
|
import { TypeTable } from "fumadocs-ui/components/type-table";
|
|
@@ -25,7 +24,7 @@ function AutoTypeTable(_a) {
|
|
|
25
24
|
"options",
|
|
26
25
|
"renderMarkdown"
|
|
27
26
|
]);
|
|
28
|
-
const output = yield
|
|
27
|
+
const output = yield generator.generateTypeTable(props, options);
|
|
29
28
|
return output.map((item) => __async(this, null, function* () {
|
|
30
29
|
const entries = item.entries.map(
|
|
31
30
|
(entry) => __async(this, null, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-typescript",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Typescript Integration for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -33,24 +33,24 @@
|
|
|
33
33
|
"hast-util-to-estree": "^3.1.3",
|
|
34
34
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
35
35
|
"remark": "^15.0.1",
|
|
36
|
-
"remark-rehype": "^11.1.
|
|
36
|
+
"remark-rehype": "^11.1.2",
|
|
37
37
|
"shiki": "^3.2.1",
|
|
38
38
|
"ts-morph": "^25.0.1",
|
|
39
39
|
"unist-util-visit": "^5.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@mdx-js/mdx": "^3.1.0",
|
|
43
|
-
"@types/estree": "^1.0.
|
|
43
|
+
"@types/estree": "^1.0.7",
|
|
44
44
|
"@types/hast": "^3.0.4",
|
|
45
45
|
"@types/mdast": "^4.0.3",
|
|
46
|
-
"@types/node": "22.
|
|
47
|
-
"@types/react": "19.0
|
|
48
|
-
"@types/react-dom": "19.
|
|
46
|
+
"@types/node": "22.14.0",
|
|
47
|
+
"@types/react": "19.1.0",
|
|
48
|
+
"@types/react-dom": "19.1.1",
|
|
49
49
|
"typescript": "^5.8.2",
|
|
50
50
|
"unified": "^11.0.5",
|
|
51
51
|
"eslint-config-custom": "0.0.0",
|
|
52
|
-
"fumadocs-core": "15.
|
|
53
|
-
"fumadocs-ui": "15.
|
|
52
|
+
"fumadocs-core": "15.2.2",
|
|
53
|
+
"fumadocs-ui": "15.2.2",
|
|
54
54
|
"tsconfig": "0.0.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|