fumadocs-typescript 5.0.0 → 5.0.1
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-Dvhn4vZx.d.ts +115 -0
- package/dist/base-Dvhn4vZx.d.ts.map +1 -0
- package/dist/index.d.ts +32 -30
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +349 -412
- package/dist/index.js.map +1 -0
- package/dist/objectSpread2-BbbttTvx.js +203 -0
- package/dist/objectSpread2-BbbttTvx.js.map +1 -0
- package/dist/ui/index.d.ts +19 -11
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +77 -80
- package/dist/ui/index.js.map +1 -0
- package/package.json +22 -20
- package/dist/base-C72MF-7Q.d.ts +0 -110
- package/dist/chunk-H4DZJVYN.js +0 -142
package/dist/index.js
CHANGED
|
@@ -1,438 +1,375 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "
|
|
10
|
-
|
|
11
|
-
// src/lib/base.ts
|
|
12
|
-
import {
|
|
13
|
-
Project as Project2,
|
|
14
|
-
ts as ts2
|
|
15
|
-
} from "ts-morph";
|
|
1
|
+
import { a as _asyncToGenerator, i as renderTypeToHast, n as parseTags, o as _objectWithoutProperties, r as renderMarkdownToHast, t as _objectSpread2 } from "./objectSpread2-BbbttTvx.js";
|
|
2
|
+
import * as ts$1 from "ts-morph";
|
|
3
|
+
import { Project, ts } from "ts-morph";
|
|
4
|
+
import * as fs$1 from "node:fs/promises";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
import path, { join } from "node:path";
|
|
7
|
+
import { valueToEstree } from "estree-util-value-to-estree";
|
|
8
|
+
import { visit } from "unist-util-visit";
|
|
9
|
+
import { toEstree } from "hast-util-to-estree";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
import { Project } from "ts-morph";
|
|
12
|
+
//#region src/create-project.ts
|
|
19
13
|
function createProject(options = {}) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
var _options$tsconfigPath;
|
|
15
|
+
return new Project({
|
|
16
|
+
tsConfigFilePath: (_options$tsconfigPath = options.tsconfigPath) !== null && _options$tsconfigPath !== void 0 ? _options$tsconfigPath : "./tsconfig.json",
|
|
17
|
+
skipAddingFilesFromTsConfig: true
|
|
18
|
+
});
|
|
25
19
|
}
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
${type}`;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
55
|
-
if (name && output.length === 0)
|
|
56
|
-
throw new Error(`${name} in ${file != null ? file : "empty file"} doesn't exist`);
|
|
57
|
-
return output;
|
|
58
|
-
});
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/lib/type-table.ts
|
|
23
|
+
const _excluded = ["name", "type"];
|
|
24
|
+
function getTypeTableOutput(_x, _x2, _x3) {
|
|
25
|
+
return _getTypeTableOutput.apply(this, arguments);
|
|
26
|
+
}
|
|
27
|
+
function _getTypeTableOutput() {
|
|
28
|
+
_getTypeTableOutput = _asyncToGenerator(function* (gen, _ref, options) {
|
|
29
|
+
let { name, type } = _ref, props = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
const file = props.path && (options === null || options === void 0 ? void 0 : options.basePath) ? join(options.basePath, props.path) : props.path;
|
|
31
|
+
let typeName = name;
|
|
32
|
+
let content = "";
|
|
33
|
+
if (file) content = (yield fs$1.readFile(file)).toString();
|
|
34
|
+
if (type && type.split("\n").length > 1) content += `\n${type}`;
|
|
35
|
+
else if (type) {
|
|
36
|
+
var _typeName;
|
|
37
|
+
(_typeName = typeName) !== null && _typeName !== void 0 || (typeName = "$Fumadocs");
|
|
38
|
+
content += `\nexport type ${typeName} = ${type}`;
|
|
39
|
+
}
|
|
40
|
+
const output = yield gen.generateDocumentation({
|
|
41
|
+
path: file !== null && file !== void 0 ? file : "temp.ts",
|
|
42
|
+
content
|
|
43
|
+
}, typeName, options);
|
|
44
|
+
if (name && output.length === 0) throw new Error(`${name} in ${file !== null && file !== void 0 ? file : "empty file"} doesn't exist`);
|
|
45
|
+
return output;
|
|
46
|
+
});
|
|
47
|
+
return _getTypeTableOutput.apply(this, arguments);
|
|
59
48
|
}
|
|
60
49
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// src/lib/get-simple-form.ts
|
|
65
|
-
import * as ts from "ts-morph";
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/lib/get-simple-form.ts
|
|
66
52
|
function getSimpleForm(type, checker, noUndefined = false, location) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return `[${elements}]`;
|
|
96
|
-
}
|
|
97
|
-
if (type.isArray() || type.isReadonlyArray()) {
|
|
98
|
-
return "array";
|
|
99
|
-
}
|
|
100
|
-
if (type.getCallSignatures().length > 0) {
|
|
101
|
-
return "function";
|
|
102
|
-
}
|
|
103
|
-
if (type.isClassOrInterface() || type.isObject()) {
|
|
104
|
-
return "object";
|
|
105
|
-
}
|
|
106
|
-
return type.getText(
|
|
107
|
-
location,
|
|
108
|
-
ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
|
|
109
|
-
);
|
|
53
|
+
if (type.isUndefined() && noUndefined) return "";
|
|
54
|
+
const alias = type.getAliasSymbol();
|
|
55
|
+
if (alias) {
|
|
56
|
+
const args = type.getAliasTypeArguments();
|
|
57
|
+
if (args.length === 0) return alias.getName();
|
|
58
|
+
return `${alias.getName()}<${args.map((arg) => getSimpleForm(arg, checker)).join(", ")}>`;
|
|
59
|
+
}
|
|
60
|
+
if (type.isUnion()) {
|
|
61
|
+
const types = [];
|
|
62
|
+
for (const t of type.getUnionTypes()) {
|
|
63
|
+
const str = getSimpleForm(t, checker, noUndefined);
|
|
64
|
+
if (str.length > 0 && str !== "never") types.unshift(str);
|
|
65
|
+
}
|
|
66
|
+
return types.length > 0 ? dedupe(types).join(" | ").replace("true | false", "boolean") : "never";
|
|
67
|
+
}
|
|
68
|
+
if (type.isIntersection()) {
|
|
69
|
+
const types = [];
|
|
70
|
+
for (const t of type.getIntersectionTypes()) {
|
|
71
|
+
const str = getSimpleForm(t, checker, noUndefined);
|
|
72
|
+
if (str.length > 0 && str !== "never") types.unshift(str);
|
|
73
|
+
}
|
|
74
|
+
return dedupe(types).join(" & ");
|
|
75
|
+
}
|
|
76
|
+
if (type.isTuple()) return `[${type.getTupleElements().map((t) => getSimpleForm(t, checker)).join(", ")}]`;
|
|
77
|
+
if (type.isArray() || type.isReadonlyArray()) return "array";
|
|
78
|
+
if (type.getCallSignatures().length > 0) return "function";
|
|
79
|
+
if (type.isClassOrInterface() || type.isObject()) return "object";
|
|
80
|
+
return type.getText(location, ts$1.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
|
|
110
81
|
}
|
|
111
82
|
function dedupe(arr) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
return out;
|
|
83
|
+
const dedupe$1 = /* @__PURE__ */ new Set();
|
|
84
|
+
const out = [];
|
|
85
|
+
for (const item of arr) if (!dedupe$1.has(item)) {
|
|
86
|
+
out.push(item);
|
|
87
|
+
dedupe$1.add(item);
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
121
90
|
}
|
|
122
91
|
|
|
123
|
-
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/lib/base.ts
|
|
124
94
|
function createGenerator(config) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return out;
|
|
159
|
-
});
|
|
160
|
-
},
|
|
161
|
-
generateTypeTable(props, options2) {
|
|
162
|
-
return getTypeTableOutput(this, props, options2);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
95
|
+
const options = config instanceof Project ? { project: config } : config;
|
|
96
|
+
const cache = (options === null || options === void 0 ? void 0 : options.cache) ? options.cache : null;
|
|
97
|
+
let instance;
|
|
98
|
+
function getProject() {
|
|
99
|
+
var _instance, _options$project;
|
|
100
|
+
(_instance = instance) !== null && _instance !== void 0 || (instance = (_options$project = options === null || options === void 0 ? void 0 : options.project) !== null && _options$project !== void 0 ? _options$project : createProject(options));
|
|
101
|
+
return instance;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
generateDocumentation(file, name, options$1) {
|
|
105
|
+
return _asyncToGenerator(function* () {
|
|
106
|
+
var _file$content;
|
|
107
|
+
const content = (_file$content = file.content) !== null && _file$content !== void 0 ? _file$content : (yield fs.readFile(path.resolve(file.path))).toString();
|
|
108
|
+
const cacheKey = `${file.path}:${name}:${content}`;
|
|
109
|
+
if (cache) {
|
|
110
|
+
const cached = yield cache.read(cacheKey);
|
|
111
|
+
if (cached) return cached;
|
|
112
|
+
}
|
|
113
|
+
const sourceFile = getProject().createSourceFile(file.path, content, { overwrite: true });
|
|
114
|
+
const out = [];
|
|
115
|
+
for (const [k, d] of sourceFile.getExportedDeclarations()) {
|
|
116
|
+
if (name && name !== k) continue;
|
|
117
|
+
if (d.length > 1) console.warn(`export ${k} should not have more than one type declaration.`);
|
|
118
|
+
out.push(generate(getProject(), k, d[0], options$1));
|
|
119
|
+
}
|
|
120
|
+
cache === null || cache === void 0 || cache.write(cacheKey, out);
|
|
121
|
+
return out;
|
|
122
|
+
})();
|
|
123
|
+
},
|
|
124
|
+
generateTypeTable(props, options$1) {
|
|
125
|
+
return getTypeTableOutput(this, props, options$1);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
165
128
|
}
|
|
166
129
|
function generate(program, name, declaration, { allowInternal = false, transform } = {}) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
entries: declaration.getType().getProperties().map((prop) => getDocEntry(prop, entryContext)).filter(
|
|
181
|
-
(entry) => entry && (allowInternal || !("internal" in entry.tags))
|
|
182
|
-
)
|
|
183
|
-
};
|
|
130
|
+
var _declaration$getSymbo;
|
|
131
|
+
const entryContext = {
|
|
132
|
+
transform,
|
|
133
|
+
program,
|
|
134
|
+
type: declaration.getType(),
|
|
135
|
+
declaration
|
|
136
|
+
};
|
|
137
|
+
const comment = (_declaration$getSymbo = declaration.getSymbol()) === null || _declaration$getSymbo === void 0 ? void 0 : _declaration$getSymbo.compilerSymbol.getDocumentationComment(program.getTypeChecker().compilerObject);
|
|
138
|
+
return {
|
|
139
|
+
name,
|
|
140
|
+
description: comment ? ts.displayPartsToString(comment) : "",
|
|
141
|
+
entries: declaration.getType().getProperties().map((prop) => getDocEntry(prop, entryContext)).filter((entry) => entry && (allowInternal || !("internal" in entry.tags)))
|
|
142
|
+
};
|
|
184
143
|
}
|
|
185
144
|
function getDocEntry(prop, context) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const entry = {
|
|
221
|
-
name: prop.getName(),
|
|
222
|
-
description: ts2.displayPartsToString(
|
|
223
|
-
prop.compilerSymbol.getDocumentationComment(
|
|
224
|
-
program.getTypeChecker().compilerObject
|
|
225
|
-
)
|
|
226
|
-
),
|
|
227
|
-
tags,
|
|
228
|
-
type,
|
|
229
|
-
simplifiedType,
|
|
230
|
-
required: !isOptional,
|
|
231
|
-
deprecated: tags.some((tag) => tag.name === "deprecated")
|
|
232
|
-
};
|
|
233
|
-
transform == null ? void 0 : transform.call(context, entry, subType, prop);
|
|
234
|
-
return entry;
|
|
145
|
+
const { transform, program } = context;
|
|
146
|
+
if (context.type.isClass() && prop.getName().startsWith("#")) return;
|
|
147
|
+
const subType = prop.getTypeAtLocation(context.declaration);
|
|
148
|
+
const isOptional = prop.isOptional();
|
|
149
|
+
const tags = prop.getJsDocTags().map((tag) => ({
|
|
150
|
+
name: tag.getName(),
|
|
151
|
+
text: ts.displayPartsToString(tag.getText())
|
|
152
|
+
}));
|
|
153
|
+
let type = subType.getText(context.declaration, ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts.TypeFormatFlags.NoTruncation);
|
|
154
|
+
let simplifiedType = getSimpleForm(subType, program.getTypeChecker(), isOptional, context.declaration);
|
|
155
|
+
for (const tag of tags) {
|
|
156
|
+
if (tag.name === "fumadocsType") {
|
|
157
|
+
var _exec;
|
|
158
|
+
const match = (_exec = new RegExp("`(?<name>.+)`$", "").exec(tag.text)) === null || _exec === void 0 ? void 0 : _exec[1];
|
|
159
|
+
if (match) type = match;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (tag.name === "remarks") {
|
|
163
|
+
var _exec2;
|
|
164
|
+
const match = (_exec2 = new RegExp("^`(?<name>.+)`", "").exec(tag.text)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
|
|
165
|
+
if (match) simplifiedType = match;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const entry = {
|
|
169
|
+
name: prop.getName(),
|
|
170
|
+
description: ts.displayPartsToString(prop.compilerSymbol.getDocumentationComment(program.getTypeChecker().compilerObject)),
|
|
171
|
+
tags,
|
|
172
|
+
type,
|
|
173
|
+
simplifiedType,
|
|
174
|
+
required: !isOptional,
|
|
175
|
+
deprecated: tags.some((tag) => tag.name === "deprecated")
|
|
176
|
+
};
|
|
177
|
+
transform === null || transform === void 0 || transform.call(context, entry, subType, prop);
|
|
178
|
+
return entry;
|
|
235
179
|
}
|
|
236
180
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
import { visit } from "unist-util-visit";
|
|
240
|
-
import { toEstree } from "hast-util-to-estree";
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/lib/remark-auto-type-table.ts
|
|
241
183
|
function objectBuilder() {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
184
|
+
const out = {
|
|
185
|
+
type: "ObjectExpression",
|
|
186
|
+
properties: []
|
|
187
|
+
};
|
|
188
|
+
return {
|
|
189
|
+
addExpressionNode(key, expression) {
|
|
190
|
+
out.properties.push({
|
|
191
|
+
type: "Property",
|
|
192
|
+
method: false,
|
|
193
|
+
shorthand: false,
|
|
194
|
+
computed: false,
|
|
195
|
+
key: {
|
|
196
|
+
type: "Identifier",
|
|
197
|
+
name: key
|
|
198
|
+
},
|
|
199
|
+
kind: "init",
|
|
200
|
+
value: expression
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
addJsxProperty(key, hast) {
|
|
204
|
+
const estree = toEstree(hast, { elementAttributeNameCase: "react" }).body[0];
|
|
205
|
+
this.addExpressionNode(key, estree.expression);
|
|
206
|
+
},
|
|
207
|
+
build() {
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function buildTypeProp(_x4, _x5) {
|
|
213
|
+
return _buildTypeProp.apply(this, arguments);
|
|
271
214
|
}
|
|
272
|
-
function
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
);
|
|
324
|
-
for (const node of output) {
|
|
325
|
-
prop.addExpressionNode(node.name, node.node);
|
|
326
|
-
}
|
|
327
|
-
return prop.build();
|
|
328
|
-
});
|
|
215
|
+
function _buildTypeProp() {
|
|
216
|
+
_buildTypeProp = _asyncToGenerator(function* (entries, { renderMarkdown = renderMarkdownToHast, renderType = renderTypeToHast }) {
|
|
217
|
+
function onItem(_x) {
|
|
218
|
+
return _onItem.apply(this, arguments);
|
|
219
|
+
}
|
|
220
|
+
function _onItem() {
|
|
221
|
+
_onItem = _asyncToGenerator(function* (entry) {
|
|
222
|
+
const node = objectBuilder();
|
|
223
|
+
const tags = parseTags(entry.tags);
|
|
224
|
+
node.addJsxProperty("type", yield renderType(entry.simplifiedType));
|
|
225
|
+
node.addJsxProperty("typeDescription", yield renderType(entry.type));
|
|
226
|
+
node.addExpressionNode("required", valueToEstree(entry.required));
|
|
227
|
+
if (tags.default) node.addJsxProperty("default", yield renderType(tags.default));
|
|
228
|
+
if (tags.returns) node.addJsxProperty("returns", yield renderMarkdown(tags.returns));
|
|
229
|
+
if (tags.params) node.addExpressionNode("parameters", {
|
|
230
|
+
type: "ArrayExpression",
|
|
231
|
+
elements: yield Promise.all(tags.params.map(onParam))
|
|
232
|
+
});
|
|
233
|
+
if (entry.description) node.addJsxProperty("description", yield renderMarkdown(entry.description));
|
|
234
|
+
return node.build();
|
|
235
|
+
});
|
|
236
|
+
return _onItem.apply(this, arguments);
|
|
237
|
+
}
|
|
238
|
+
function onParam(_x2) {
|
|
239
|
+
return _onParam.apply(this, arguments);
|
|
240
|
+
}
|
|
241
|
+
function _onParam() {
|
|
242
|
+
_onParam = _asyncToGenerator(function* (param) {
|
|
243
|
+
const node = objectBuilder();
|
|
244
|
+
node.addExpressionNode("name", valueToEstree(param.name));
|
|
245
|
+
if (param.description) node.addJsxProperty("description", yield renderMarkdown(param.description));
|
|
246
|
+
return node.build();
|
|
247
|
+
});
|
|
248
|
+
return _onParam.apply(this, arguments);
|
|
249
|
+
}
|
|
250
|
+
const prop = objectBuilder();
|
|
251
|
+
const output = yield Promise.all(entries.map(function() {
|
|
252
|
+
var _ref = _asyncToGenerator(function* (entry) {
|
|
253
|
+
return {
|
|
254
|
+
name: entry.name,
|
|
255
|
+
node: yield onItem(entry)
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
return function(_x3) {
|
|
259
|
+
return _ref.apply(this, arguments);
|
|
260
|
+
};
|
|
261
|
+
}()));
|
|
262
|
+
for (const node of output) prop.addExpressionNode(node.name, node.node);
|
|
263
|
+
return prop.build();
|
|
264
|
+
});
|
|
265
|
+
return _buildTypeProp.apply(this, arguments);
|
|
329
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Compile `auto-type-table` into Fumadocs UI compatible TypeTable
|
|
269
|
+
*
|
|
270
|
+
* MDX is required to use this plugin.
|
|
271
|
+
*/
|
|
330
272
|
function remarkAutoTypeTable(config = {}) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
273
|
+
const { name = "auto-type-table", outputName = "TypeTable", options: generateOptions = {}, remarkStringify = true, generator = createGenerator() } = config;
|
|
274
|
+
return function() {
|
|
275
|
+
var _ref3 = _asyncToGenerator(function* (tree, file) {
|
|
276
|
+
const queue = [];
|
|
277
|
+
function run(_x7, _x8) {
|
|
278
|
+
return _run.apply(this, arguments);
|
|
279
|
+
}
|
|
280
|
+
function _run() {
|
|
281
|
+
_run = _asyncToGenerator(function* (node, props) {
|
|
282
|
+
let basePath = props.cwd ? file.cwd : generateOptions.basePath;
|
|
283
|
+
if (file.dirname) {
|
|
284
|
+
var _basePath;
|
|
285
|
+
(_basePath = basePath) !== null && _basePath !== void 0 || (basePath = file.dirname);
|
|
286
|
+
}
|
|
287
|
+
const rendered = (yield generator.generateTypeTable(props, _objectSpread2(_objectSpread2({}, generateOptions), {}, { basePath }))).map(function() {
|
|
288
|
+
var _ref2 = _asyncToGenerator(function* (doc) {
|
|
289
|
+
return {
|
|
290
|
+
type: "mdxJsxFlowElement",
|
|
291
|
+
name: outputName,
|
|
292
|
+
attributes: [{
|
|
293
|
+
type: "mdxJsxAttribute",
|
|
294
|
+
name: "type",
|
|
295
|
+
value: {
|
|
296
|
+
type: "mdxJsxAttributeValueExpression",
|
|
297
|
+
value: remarkStringify ? JSON.stringify(doc, null, 2) : "",
|
|
298
|
+
data: { estree: {
|
|
299
|
+
type: "Program",
|
|
300
|
+
sourceType: "module",
|
|
301
|
+
body: [{
|
|
302
|
+
type: "ExpressionStatement",
|
|
303
|
+
expression: yield buildTypeProp(doc.entries, config)
|
|
304
|
+
}]
|
|
305
|
+
} }
|
|
306
|
+
}
|
|
307
|
+
}],
|
|
308
|
+
children: []
|
|
309
|
+
};
|
|
310
|
+
});
|
|
311
|
+
return function(_x6) {
|
|
312
|
+
return _ref2.apply(this, arguments);
|
|
313
|
+
};
|
|
314
|
+
}());
|
|
315
|
+
Object.assign(node, {
|
|
316
|
+
type: "root",
|
|
317
|
+
attributes: [],
|
|
318
|
+
children: yield Promise.all(rendered)
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
return _run.apply(this, arguments);
|
|
322
|
+
}
|
|
323
|
+
visit(tree, "mdxJsxFlowElement", (node) => {
|
|
324
|
+
if (node.name !== name) return;
|
|
325
|
+
const props = {};
|
|
326
|
+
const onError = (message, cause) => {
|
|
327
|
+
const location = node.position ? `${file.path}:${node.position.start.line}:${node.position.start.column}` : file.path;
|
|
328
|
+
throw new Error(`${location} from <auto-type-table>: ${message}`, { cause });
|
|
329
|
+
};
|
|
330
|
+
for (const attr of node.attributes) if (attr.type !== "mdxJsxAttribute") onError("only named attributes are allowed.");
|
|
331
|
+
else if (typeof attr.value === "string") props[attr.name] = attr.value;
|
|
332
|
+
else if (attr.value === null) props[attr.name] = true;
|
|
333
|
+
else onError("only string & boolean attributes are allowed.");
|
|
334
|
+
queue.push(run(node, props).catch((err) => {
|
|
335
|
+
onError("failed to generate type table", err);
|
|
336
|
+
}));
|
|
337
|
+
return "skip";
|
|
338
|
+
});
|
|
339
|
+
yield Promise.all(queue);
|
|
340
|
+
});
|
|
341
|
+
return function(_x9, _x10) {
|
|
342
|
+
return _ref3.apply(this, arguments);
|
|
343
|
+
};
|
|
344
|
+
}();
|
|
400
345
|
}
|
|
401
346
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
import { createHash } from "crypto";
|
|
405
|
-
import path2 from "path";
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/cache/fs-cache.ts
|
|
406
349
|
function createFileSystemGeneratorCache(dir) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
};
|
|
350
|
+
dir = path.resolve(dir);
|
|
351
|
+
const initDirPromise = fs.mkdir(dir, { recursive: true }).catch(() => {});
|
|
352
|
+
return {
|
|
353
|
+
write(input, data) {
|
|
354
|
+
return _asyncToGenerator(function* () {
|
|
355
|
+
const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
|
|
356
|
+
yield initDirPromise;
|
|
357
|
+
yield fs.writeFile(path.join(dir, `${hash}.json`), JSON.stringify(data));
|
|
358
|
+
})();
|
|
359
|
+
},
|
|
360
|
+
read(input) {
|
|
361
|
+
return _asyncToGenerator(function* () {
|
|
362
|
+
const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
|
|
363
|
+
try {
|
|
364
|
+
return JSON.parse((yield fs.readFile(path.join(dir, `${hash}.json`))).toString());
|
|
365
|
+
} catch (_unused) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
})();
|
|
369
|
+
}
|
|
370
|
+
};
|
|
431
371
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
remarkAutoTypeTable,
|
|
437
|
-
renderMarkdownToHast
|
|
438
|
-
};
|
|
372
|
+
|
|
373
|
+
//#endregion
|
|
374
|
+
export { createFileSystemGeneratorCache, createGenerator, createProject, remarkAutoTypeTable, renderMarkdownToHast };
|
|
375
|
+
//# sourceMappingURL=index.js.map
|