fuma-content 0.0.2 → 1.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/bin.d.ts +1 -0
- package/dist/bin.js +18 -0
- package/dist/build-mdx-Q4RMDWYK.js +8 -0
- package/dist/bun/index.d.ts +16 -0
- package/dist/bun/index.js +36 -0
- package/dist/bun-DMNX4PBC.js +40 -0
- package/dist/chunk-3VQS3KSP.js +39 -0
- package/dist/chunk-4RMSJCK2.js +50 -0
- package/dist/chunk-6XDQG2GV.js +17 -0
- package/dist/chunk-AMBGM4OK.js +412 -0
- package/dist/chunk-BTRE6MOX.js +16 -0
- package/dist/chunk-E4HRKSP4.js +24 -0
- package/dist/chunk-ERBMAQYP.js +33 -0
- package/dist/chunk-IGLM4N4P.js +34 -0
- package/dist/chunk-LDBQ66H3.js +38 -0
- package/dist/chunk-M72VQL5M.js +40 -0
- package/dist/chunk-OUJENWQ4.js +45 -0
- package/dist/chunk-PNA5UGSL.js +104 -0
- package/dist/chunk-RMSV4HP6.js +85 -0
- package/dist/chunk-RXR7OL76.js +37 -0
- package/dist/chunk-VWJKRQZR.js +19 -0
- package/dist/chunk-Z7KHD7MS.js +368 -0
- package/dist/collections/handlers/fs.d.ts +10 -0
- package/dist/collections/handlers/fs.js +6 -0
- package/dist/collections/index.d.ts +10 -0
- package/dist/collections/index.js +6 -0
- package/dist/collections/mdx/loader-webpack.d.ts +17 -0
- package/dist/collections/mdx/loader-webpack.js +38 -0
- package/dist/collections/mdx/runtime-browser.d.ts +44 -0
- package/dist/collections/mdx/runtime-browser.js +74 -0
- package/dist/collections/mdx/runtime-dynamic.d.ts +42 -0
- package/dist/collections/mdx/runtime-dynamic.js +94 -0
- package/dist/collections/mdx/runtime.d.ts +69 -0
- package/dist/collections/mdx/runtime.js +45 -0
- package/dist/collections/mdx.d.ts +10 -0
- package/dist/collections/mdx.js +287 -0
- package/dist/collections/meta/loader-webpack.d.ts +17 -0
- package/dist/collections/meta/loader-webpack.js +41 -0
- package/dist/collections/meta/runtime.d.ts +19 -0
- package/dist/collections/meta/runtime.js +18 -0
- package/dist/collections/meta.d.ts +10 -0
- package/dist/collections/meta.js +166 -0
- package/dist/collections/runtime/file-store.d.ts +19 -0
- package/dist/collections/runtime/file-store.js +7 -0
- package/dist/collections/runtime/store.d.ts +28 -0
- package/dist/collections/runtime/store.js +6 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +7 -0
- package/dist/core-DxnSmTRe.d.ts +411 -0
- package/dist/index.d.ts +13 -31
- package/dist/index.js +0 -51
- package/dist/load-from-file-MLL4WQ5J.js +7 -0
- package/dist/loader-T756NSCS.js +7 -0
- package/dist/loader-VGDLYG4T.js +7 -0
- package/dist/next/index.cjs +571 -0
- package/dist/next/index.d.ts +27 -0
- package/dist/next/index.js +99 -0
- package/dist/node/loader.d.ts +5 -0
- package/dist/node/loader.js +46 -0
- package/dist/node-DCMYL4DL.js +34 -0
- package/dist/plugins/git.d.ts +10 -0
- package/dist/plugins/git.js +70 -0
- package/dist/plugins/json-schema.d.ts +10 -0
- package/dist/plugins/json-schema.js +59 -0
- package/dist/plugins/with-loader/index.d.ts +61 -0
- package/dist/plugins/with-loader/index.js +6 -0
- package/dist/plugins/with-loader/webpack.d.ts +27 -0
- package/dist/plugins/with-loader/webpack.js +11 -0
- package/dist/vite/index.d.ts +33 -0
- package/dist/vite/index.js +60 -0
- package/dist/vite-QCUPZHHB.js +32 -0
- package/package.json +103 -36
- package/dist/internal.d.ts +0 -114
- package/dist/internal.js +0 -420
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { G as GlobalConfig } from './core-DxnSmTRe.js';
|
|
2
|
+
export { a as Core, C as CoreOptions, g as EmitCodeGeneratorContext, f as EmitContext, e as EmitEntry, i as EmitOptions, j as EmitOutput, E as ExtractedReference, d as Plugin, P as PluginContext, h as PluginOption, S as ServerContext } from './core-DxnSmTRe.js';
|
|
3
|
+
import 'chokidar';
|
|
4
|
+
import '@mdx-js/mdx';
|
|
5
|
+
import 'vfile';
|
|
6
|
+
import '@standard-schema/spec';
|
|
7
|
+
import 'unified';
|
|
8
|
+
import 'mdast';
|
|
9
|
+
import 'vite';
|
|
10
|
+
import 'next';
|
|
11
|
+
import 'node:module';
|
|
3
12
|
|
|
4
|
-
|
|
5
|
-
schema?: AnyZodObject;
|
|
6
|
-
/**
|
|
7
|
-
* Filter file paths
|
|
8
|
-
*/
|
|
9
|
-
include?: string | string[];
|
|
10
|
-
}
|
|
11
|
-
interface Document<Info = unknown> {
|
|
12
|
-
info: Info;
|
|
13
|
-
/**
|
|
14
|
-
* Render data, should be accepted by renderer
|
|
15
|
-
*/
|
|
16
|
-
renderer: MDXContent;
|
|
17
|
-
/**
|
|
18
|
-
* File Path
|
|
19
|
-
*/
|
|
20
|
-
file: string;
|
|
21
|
-
}
|
|
22
|
-
interface Json<Info = unknown> {
|
|
23
|
-
info: Info;
|
|
24
|
-
/**
|
|
25
|
-
* File Path
|
|
26
|
-
*/
|
|
27
|
-
file: string;
|
|
28
|
-
}
|
|
29
|
-
type GetInfoType<T extends CreateOptions> = T["schema"] extends AnyZodObject ? z.infer<T["schema"]> : Record<string, unknown>;
|
|
30
|
-
declare function document<T extends CreateOptions>(entryPoint: unknown, options?: T): Document<GetInfoType<T>>[];
|
|
31
|
-
declare function json<T extends CreateOptions>(entryPoint: unknown, options?: T): Json<GetInfoType<T>>[];
|
|
13
|
+
type GetCollectionConfig<Config, Name extends string> = Config extends GlobalConfig<infer Collections> ? Collections[Name] : never;
|
|
32
14
|
|
|
33
|
-
export
|
|
15
|
+
export type { GetCollectionConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// src/source/index.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import micromatch from "micromatch";
|
|
4
|
-
var defaultSchema = z.record(z.string(), z.unknown());
|
|
5
|
-
function document(entryPoint, options) {
|
|
6
|
-
const { schema = defaultSchema, include } = options ?? {};
|
|
7
|
-
return read(entryPoint, ["md", "mdx"], include).map((item) => {
|
|
8
|
-
const {
|
|
9
|
-
default: render,
|
|
10
|
-
format: _format,
|
|
11
|
-
file,
|
|
12
|
-
frontmatter,
|
|
13
|
-
...rest
|
|
14
|
-
} = item;
|
|
15
|
-
const result = schema.safeParse(frontmatter);
|
|
16
|
-
if (!result.success) throw createError(file, result.error);
|
|
17
|
-
return {
|
|
18
|
-
file,
|
|
19
|
-
info: result.data,
|
|
20
|
-
renderer: render,
|
|
21
|
-
...rest
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function json(entryPoint, options) {
|
|
26
|
-
const { schema = defaultSchema, include } = options ?? {};
|
|
27
|
-
return read(entryPoint, ["json"], include).map(
|
|
28
|
-
({ file, default: data }) => {
|
|
29
|
-
const result = schema.safeParse(data);
|
|
30
|
-
if (!result.success) throw createError(file, result.error);
|
|
31
|
-
return {
|
|
32
|
-
file,
|
|
33
|
-
info: result.data
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
function createError(file, err) {
|
|
39
|
-
const message = `${file}:
|
|
40
|
-
${Object.entries(err.flatten().fieldErrors).map(([k, v]) => `${k}: ${v?.join(", ") ?? ""}`).join("\n")}`;
|
|
41
|
-
return new Error(message);
|
|
42
|
-
}
|
|
43
|
-
function read(entryPoint, format, include) {
|
|
44
|
-
const cast = entryPoint;
|
|
45
|
-
const entries = format.flatMap((f) => cast[f] ?? []);
|
|
46
|
-
return entries.filter((e) => !include || micromatch.isMatch(e.file, include));
|
|
47
|
-
}
|
|
48
|
-
export {
|
|
49
|
-
document,
|
|
50
|
-
json
|
|
51
|
-
};
|
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/next/index.ts
|
|
31
|
+
var next_exports = {};
|
|
32
|
+
__export(next_exports, {
|
|
33
|
+
createContent: () => createContent,
|
|
34
|
+
createStandaloneCore: () => createStandaloneCore
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(next_exports);
|
|
37
|
+
var path3 = __toESM(require("path"), 1);
|
|
38
|
+
|
|
39
|
+
// src/config/load-from-file.ts
|
|
40
|
+
var import_node_url = require("url");
|
|
41
|
+
|
|
42
|
+
// src/config/build.ts
|
|
43
|
+
function buildConfig(config, workspace) {
|
|
44
|
+
const collections = /* @__PURE__ */ new Map();
|
|
45
|
+
const loaded = {};
|
|
46
|
+
const globalConfig = config.default ?? config;
|
|
47
|
+
if (globalConfig.collections) {
|
|
48
|
+
for (const [name, collection] of Object.entries(globalConfig.collections)) {
|
|
49
|
+
collection.init?.({ name, workspace });
|
|
50
|
+
collections.set(name, collection);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...globalConfig,
|
|
55
|
+
collections,
|
|
56
|
+
workspaces: Object.fromEntries(
|
|
57
|
+
Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
|
|
58
|
+
return [
|
|
59
|
+
key,
|
|
60
|
+
{
|
|
61
|
+
dir: value.dir,
|
|
62
|
+
config: buildConfig(value.config, {
|
|
63
|
+
...value,
|
|
64
|
+
name: key
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/config/load-from-file.ts
|
|
74
|
+
async function compileConfig(core) {
|
|
75
|
+
const { build } = await import("esbuild");
|
|
76
|
+
const { configPath, outDir } = core.getOptions();
|
|
77
|
+
const transformed = await build({
|
|
78
|
+
entryPoints: [{ in: configPath, out: "content.config" }],
|
|
79
|
+
bundle: true,
|
|
80
|
+
outdir: outDir,
|
|
81
|
+
target: "node20",
|
|
82
|
+
write: true,
|
|
83
|
+
platform: "node",
|
|
84
|
+
format: "esm",
|
|
85
|
+
packages: "external",
|
|
86
|
+
outExtension: {
|
|
87
|
+
".js": ".mjs"
|
|
88
|
+
},
|
|
89
|
+
allowOverwrite: true
|
|
90
|
+
});
|
|
91
|
+
if (transformed.errors.length > 0) {
|
|
92
|
+
throw new Error("failed to compile configuration file");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function loadConfig(core, build = false) {
|
|
96
|
+
if (build) await compileConfig(core);
|
|
97
|
+
const url = (0, import_node_url.pathToFileURL)(core.getCompiledConfigPath());
|
|
98
|
+
url.searchParams.set("hash", Date.now().toString());
|
|
99
|
+
const config = import(url.href).then(
|
|
100
|
+
(loaded) => buildConfig(loaded)
|
|
101
|
+
);
|
|
102
|
+
return await config;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/core.ts
|
|
106
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
107
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
108
|
+
|
|
109
|
+
// src/utils/code-generator.ts
|
|
110
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
111
|
+
var import_tinyglobby = require("tinyglobby");
|
|
112
|
+
|
|
113
|
+
// src/utils/async-cache.ts
|
|
114
|
+
function createCache(store = /* @__PURE__ */ new Map()) {
|
|
115
|
+
return {
|
|
116
|
+
store,
|
|
117
|
+
cached(key, fn) {
|
|
118
|
+
let cached = store.get(key);
|
|
119
|
+
if (cached) return cached;
|
|
120
|
+
cached = fn();
|
|
121
|
+
store.set(key, cached);
|
|
122
|
+
return cached;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/utils/code-generator.ts
|
|
128
|
+
function importInfo() {
|
|
129
|
+
return {
|
|
130
|
+
named: /* @__PURE__ */ new Map(),
|
|
131
|
+
namespaces: /* @__PURE__ */ new Set(),
|
|
132
|
+
isUsed: /* @__PURE__ */ new Set()
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
var CodeGenerator = class {
|
|
136
|
+
lines = [];
|
|
137
|
+
globCache;
|
|
138
|
+
// specifier -> imported members/info
|
|
139
|
+
importInfos = /* @__PURE__ */ new Map();
|
|
140
|
+
eagerImportId = 0;
|
|
141
|
+
options;
|
|
142
|
+
constructor({
|
|
143
|
+
target = "default",
|
|
144
|
+
jsExtension = false,
|
|
145
|
+
globCache = /* @__PURE__ */ new Map(),
|
|
146
|
+
outDir = ""
|
|
147
|
+
}) {
|
|
148
|
+
this.options = {
|
|
149
|
+
target,
|
|
150
|
+
jsExtension,
|
|
151
|
+
globCache,
|
|
152
|
+
outDir
|
|
153
|
+
};
|
|
154
|
+
this.globCache = createCache(globCache);
|
|
155
|
+
}
|
|
156
|
+
addNamespaceImport(namespace, specifier, types = false) {
|
|
157
|
+
const info = this.importInfos.get(specifier) ?? importInfo();
|
|
158
|
+
this.importInfos.set(specifier, info);
|
|
159
|
+
if (!types) info.isUsed.add(namespace);
|
|
160
|
+
info.namespaces.add(namespace);
|
|
161
|
+
}
|
|
162
|
+
addNamedImport(names, specifier, types = false) {
|
|
163
|
+
const info = this.importInfos.get(specifier) ?? importInfo();
|
|
164
|
+
this.importInfos.set(specifier, info);
|
|
165
|
+
for (const name of names) {
|
|
166
|
+
const [memberName, importName = memberName] = name.split(/\s+as\s+/, 2);
|
|
167
|
+
info.named.set(importName, memberName);
|
|
168
|
+
if (!types) info.isUsed.add(importName);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
push(...insert) {
|
|
172
|
+
this.lines.push(...insert);
|
|
173
|
+
}
|
|
174
|
+
async pushAsync(insert) {
|
|
175
|
+
for (const line of await Promise.all(insert)) {
|
|
176
|
+
if (line === void 0) continue;
|
|
177
|
+
this.lines.push(line);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async generateGlobImport(patterns, options) {
|
|
181
|
+
if (this.options.target === "vite") {
|
|
182
|
+
return this.generateViteGlobImport(patterns, options);
|
|
183
|
+
}
|
|
184
|
+
return this.generateNodeGlobImport(patterns, options);
|
|
185
|
+
}
|
|
186
|
+
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
187
|
+
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
188
|
+
normalizeViteGlobPath
|
|
189
|
+
);
|
|
190
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
191
|
+
{
|
|
192
|
+
base: normalizeViteGlobPath(import_node_path.default.relative(this.options.outDir, base)),
|
|
193
|
+
...rest
|
|
194
|
+
},
|
|
195
|
+
null,
|
|
196
|
+
2
|
|
197
|
+
)})`;
|
|
198
|
+
}
|
|
199
|
+
async generateNodeGlobImport(patterns, { base, eager = false, query = {}, import: importName }) {
|
|
200
|
+
const files = await this.globCache.cached(
|
|
201
|
+
JSON.stringify({ patterns, base }),
|
|
202
|
+
() => (0, import_tinyglobby.glob)(patterns, {
|
|
203
|
+
cwd: base
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
let code = "{";
|
|
207
|
+
for (const item of files) {
|
|
208
|
+
const fullPath = import_node_path.default.join(base, item);
|
|
209
|
+
const searchParams = new URLSearchParams();
|
|
210
|
+
for (const [k, v] of Object.entries(query)) {
|
|
211
|
+
if (v !== void 0) searchParams.set(k, v);
|
|
212
|
+
}
|
|
213
|
+
const importPath = `${this.formatImportPath(fullPath)}?${searchParams.toString()}`;
|
|
214
|
+
if (eager) {
|
|
215
|
+
const name = `__fd_glob_${this.eagerImportId++}`;
|
|
216
|
+
this.lines.unshift(
|
|
217
|
+
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
218
|
+
);
|
|
219
|
+
code += `${JSON.stringify(item)}: ${name}, `;
|
|
220
|
+
} else {
|
|
221
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
222
|
+
if (importName) {
|
|
223
|
+
line += `.then(mod => mod.${importName})`;
|
|
224
|
+
}
|
|
225
|
+
code += `${line}, `;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
code += "}";
|
|
229
|
+
return code;
|
|
230
|
+
}
|
|
231
|
+
formatImportPath(file) {
|
|
232
|
+
const ext = import_node_path.default.extname(file);
|
|
233
|
+
let filename;
|
|
234
|
+
if (ext === ".ts") {
|
|
235
|
+
filename = file.substring(0, file.length - ext.length);
|
|
236
|
+
if (this.options.jsExtension) filename += ".js";
|
|
237
|
+
} else {
|
|
238
|
+
filename = file;
|
|
239
|
+
}
|
|
240
|
+
const importPath = slash(import_node_path.default.relative(this.options.outDir, filename));
|
|
241
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
242
|
+
}
|
|
243
|
+
toString() {
|
|
244
|
+
const final = ["// @ts-nocheck"];
|
|
245
|
+
if (this.options.target === "vite") {
|
|
246
|
+
final.push('/// <reference types="vite/client" />');
|
|
247
|
+
}
|
|
248
|
+
for (const [specifier, info] of this.importInfos) {
|
|
249
|
+
const { namespaces, named, isUsed } = info;
|
|
250
|
+
for (const namespace of namespaces) {
|
|
251
|
+
final.push(
|
|
252
|
+
isUsed.has(namespace) ? `import * as ${namespace} from "${specifier}";` : `import type * as ${namespace} from "${specifier}";`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
const namedImports = [];
|
|
256
|
+
for (const [importName, memberName] of named) {
|
|
257
|
+
const item = importName === memberName ? importName : `${memberName} as ${importName}`;
|
|
258
|
+
namedImports.push(isUsed.has(importName) ? item : `type ${item}`);
|
|
259
|
+
}
|
|
260
|
+
if (namedImports.length > 0) {
|
|
261
|
+
final.push(
|
|
262
|
+
`import { ${namedImports.join(", ")} } from "${specifier}";`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
final.push(...this.lines);
|
|
267
|
+
return final.join("\n");
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
function normalizeViteGlobPath(file) {
|
|
271
|
+
file = slash(file);
|
|
272
|
+
if (file.startsWith("./")) return file;
|
|
273
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
274
|
+
return `./${file}`;
|
|
275
|
+
}
|
|
276
|
+
function slash(path4) {
|
|
277
|
+
const isExtendedLengthPath = path4.startsWith("\\\\?\\");
|
|
278
|
+
if (isExtendedLengthPath) {
|
|
279
|
+
return path4;
|
|
280
|
+
}
|
|
281
|
+
return path4.replaceAll("\\", "/");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/core.ts
|
|
285
|
+
async function getPlugins(pluginOptions) {
|
|
286
|
+
const plugins = [];
|
|
287
|
+
for (const option of await Promise.all(pluginOptions)) {
|
|
288
|
+
if (!option) continue;
|
|
289
|
+
if (Array.isArray(option)) plugins.push(...await getPlugins(option));
|
|
290
|
+
else plugins.push(option);
|
|
291
|
+
}
|
|
292
|
+
return plugins;
|
|
293
|
+
}
|
|
294
|
+
var Core = class _Core {
|
|
295
|
+
workspaces = /* @__PURE__ */ new Map();
|
|
296
|
+
options;
|
|
297
|
+
plugins = [];
|
|
298
|
+
config;
|
|
299
|
+
static defaultOptions = {
|
|
300
|
+
configPath: "content.config.ts",
|
|
301
|
+
outDir: ".content"
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Convenient cache store, reset when config changes.
|
|
305
|
+
*
|
|
306
|
+
* You can group namespaces in cache key with ":", like `my-plugin:data`
|
|
307
|
+
*/
|
|
308
|
+
cache = /* @__PURE__ */ new Map();
|
|
309
|
+
constructor(options) {
|
|
310
|
+
this.options = options;
|
|
311
|
+
}
|
|
312
|
+
async init({ config: newConfig }) {
|
|
313
|
+
this.config = await newConfig;
|
|
314
|
+
this.cache.clear();
|
|
315
|
+
this.workspaces.clear();
|
|
316
|
+
const loadedCollectionTypeIds = /* @__PURE__ */ new Set();
|
|
317
|
+
this.plugins = await getPlugins([
|
|
318
|
+
this.options.plugins,
|
|
319
|
+
this.config.plugins,
|
|
320
|
+
...this.config.collections.values().map(({ typeInfo }) => {
|
|
321
|
+
if (loadedCollectionTypeIds.has(typeInfo.id)) return false;
|
|
322
|
+
loadedCollectionTypeIds.add(typeInfo.id);
|
|
323
|
+
return typeInfo.plugins;
|
|
324
|
+
})
|
|
325
|
+
]);
|
|
326
|
+
const ctx = this.getPluginContext();
|
|
327
|
+
for (const plugin of this.plugins) {
|
|
328
|
+
const out = await plugin.config?.call(ctx, this.config);
|
|
329
|
+
if (out) this.config = out;
|
|
330
|
+
}
|
|
331
|
+
const { workspace, outDir } = this.options;
|
|
332
|
+
if (!workspace) {
|
|
333
|
+
await Promise.all(
|
|
334
|
+
Object.entries(this.config.workspaces).map(
|
|
335
|
+
async ([name, workspace2]) => {
|
|
336
|
+
const child = new _Core({
|
|
337
|
+
...this.options,
|
|
338
|
+
outDir: import_node_path2.default.join(outDir, name),
|
|
339
|
+
workspace: {
|
|
340
|
+
name,
|
|
341
|
+
parent: this,
|
|
342
|
+
dir: workspace2.dir
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
await child.init({ config: workspace2.config });
|
|
346
|
+
this.workspaces.set(name, child);
|
|
347
|
+
}
|
|
348
|
+
)
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
await Promise.all(
|
|
352
|
+
this.config.collections.values().map(async (collection) => {
|
|
353
|
+
for (const plugin of this.plugins) {
|
|
354
|
+
await plugin.collection?.call(ctx, collection);
|
|
355
|
+
}
|
|
356
|
+
})
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
getWorkspaces() {
|
|
360
|
+
return this.workspaces;
|
|
361
|
+
}
|
|
362
|
+
getOptions() {
|
|
363
|
+
return this.options;
|
|
364
|
+
}
|
|
365
|
+
getConfig() {
|
|
366
|
+
return this.config;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
370
|
+
*/
|
|
371
|
+
getCompiledConfigPath() {
|
|
372
|
+
return import_node_path2.default.join(this.options.outDir, "content.config.mjs");
|
|
373
|
+
}
|
|
374
|
+
getPlugins(workspace = false) {
|
|
375
|
+
if (workspace) {
|
|
376
|
+
const plugins = [...this.plugins];
|
|
377
|
+
for (const workspace2 of this.workspaces.values()) {
|
|
378
|
+
plugins.push(...workspace2.plugins);
|
|
379
|
+
}
|
|
380
|
+
return plugins;
|
|
381
|
+
}
|
|
382
|
+
return this.plugins;
|
|
383
|
+
}
|
|
384
|
+
getCollections(workspace = false) {
|
|
385
|
+
const list = Array.from(this.config.collections.values());
|
|
386
|
+
if (workspace) {
|
|
387
|
+
for (const workspace2 of this.workspaces.values()) {
|
|
388
|
+
list.push(...workspace2.getCollections());
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return list;
|
|
392
|
+
}
|
|
393
|
+
getCollection(name) {
|
|
394
|
+
return this.config.collections.get(name);
|
|
395
|
+
}
|
|
396
|
+
getPluginContext() {
|
|
397
|
+
return {
|
|
398
|
+
core: this
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
async initServer(server) {
|
|
402
|
+
const ctx = this.getPluginContext();
|
|
403
|
+
const promises = [];
|
|
404
|
+
for (const plugin of this.plugins) {
|
|
405
|
+
promises.push(plugin.configureServer?.call(ctx, server));
|
|
406
|
+
}
|
|
407
|
+
for (const workspace of this.workspaces.values()) {
|
|
408
|
+
promises.push(workspace.initServer(server));
|
|
409
|
+
}
|
|
410
|
+
await Promise.all(promises);
|
|
411
|
+
}
|
|
412
|
+
async emit(emitOptions = {}) {
|
|
413
|
+
const {
|
|
414
|
+
workspace,
|
|
415
|
+
outDir,
|
|
416
|
+
emit: { target, jsExtension } = {}
|
|
417
|
+
} = this.options;
|
|
418
|
+
const { filterPlugin, filterWorkspace, write = false } = emitOptions;
|
|
419
|
+
const start = performance.now();
|
|
420
|
+
const globCache = /* @__PURE__ */ new Map();
|
|
421
|
+
const ctx = {
|
|
422
|
+
...this.getPluginContext(),
|
|
423
|
+
createCodeGenerator: async (path4, content) => {
|
|
424
|
+
const codegen = new CodeGenerator({
|
|
425
|
+
target,
|
|
426
|
+
outDir,
|
|
427
|
+
jsExtension,
|
|
428
|
+
globCache
|
|
429
|
+
});
|
|
430
|
+
await content({
|
|
431
|
+
core: this,
|
|
432
|
+
codegen,
|
|
433
|
+
workspace: workspace?.name
|
|
434
|
+
});
|
|
435
|
+
return {
|
|
436
|
+
path: path4,
|
|
437
|
+
content: codegen.toString()
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
const added = /* @__PURE__ */ new Set();
|
|
442
|
+
const out = {
|
|
443
|
+
entries: [],
|
|
444
|
+
workspaces: {}
|
|
445
|
+
};
|
|
446
|
+
for (const li of await Promise.all(
|
|
447
|
+
this.plugins.map((plugin) => {
|
|
448
|
+
if (filterPlugin && !filterPlugin(plugin) || !plugin.emit)
|
|
449
|
+
return null;
|
|
450
|
+
return plugin.emit.call(ctx);
|
|
451
|
+
})
|
|
452
|
+
)) {
|
|
453
|
+
if (!li) continue;
|
|
454
|
+
for (const item of li) {
|
|
455
|
+
if (added.has(item.path)) continue;
|
|
456
|
+
out.entries.push(item);
|
|
457
|
+
added.add(item.path);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (write) {
|
|
461
|
+
await Promise.all(
|
|
462
|
+
out.entries.map(async (entry) => {
|
|
463
|
+
const file = import_node_path2.default.join(outDir, entry.path);
|
|
464
|
+
await import_promises.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
|
|
465
|
+
await import_promises.default.writeFile(file, entry.content);
|
|
466
|
+
})
|
|
467
|
+
);
|
|
468
|
+
console.log(
|
|
469
|
+
workspace ? `[MDX: ${workspace.name}] generated files in ${performance.now() - start}ms` : `[MDX] generated files in ${performance.now() - start}ms`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
await Promise.all(
|
|
473
|
+
this.workspaces.entries().map(async ([name, workspace2]) => {
|
|
474
|
+
if (filterWorkspace && !filterWorkspace(name)) return;
|
|
475
|
+
out.workspaces[name] = (await workspace2.emit(emitOptions)).entries;
|
|
476
|
+
})
|
|
477
|
+
);
|
|
478
|
+
return out;
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// src/next/index.ts
|
|
483
|
+
async function createContent(nextOptions = {}) {
|
|
484
|
+
const core = createNextCore(applyDefaults(nextOptions));
|
|
485
|
+
await core.init({
|
|
486
|
+
config: loadConfig(core, true)
|
|
487
|
+
});
|
|
488
|
+
if (process.env._FUMADOCS_MDX !== "1") {
|
|
489
|
+
process.env._FUMADOCS_MDX = "1";
|
|
490
|
+
await core.emit({ write: true });
|
|
491
|
+
await init(process.env.NODE_ENV === "development", core);
|
|
492
|
+
}
|
|
493
|
+
return (nextConfig = {}) => {
|
|
494
|
+
const ctx = core.getPluginContext();
|
|
495
|
+
for (const plugin of core.getPlugins(true)) {
|
|
496
|
+
nextConfig = plugin.next?.config?.call(ctx, nextConfig) ?? nextConfig;
|
|
497
|
+
}
|
|
498
|
+
return nextConfig;
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
async function init(dev, core) {
|
|
502
|
+
if (!dev) return;
|
|
503
|
+
const { FSWatcher } = await import("chokidar");
|
|
504
|
+
const { configPath, outDir } = core.getOptions();
|
|
505
|
+
const absoluteConfigPath = path3.resolve(configPath);
|
|
506
|
+
let watcher;
|
|
507
|
+
async function devServer() {
|
|
508
|
+
if (watcher && !watcher.closed) {
|
|
509
|
+
await watcher.close();
|
|
510
|
+
}
|
|
511
|
+
watcher = new FSWatcher({
|
|
512
|
+
ignoreInitial: true,
|
|
513
|
+
persistent: true,
|
|
514
|
+
ignored: [outDir]
|
|
515
|
+
});
|
|
516
|
+
watcher.add(configPath);
|
|
517
|
+
for (const collection of core.getCollections(true)) {
|
|
518
|
+
const handler = collection.handlers.fs;
|
|
519
|
+
if (handler) {
|
|
520
|
+
watcher.add(handler.dir);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
watcher.once("ready", () => {
|
|
524
|
+
console.log("[MDX] started dev server");
|
|
525
|
+
});
|
|
526
|
+
watcher.on("all", (_event, file) => {
|
|
527
|
+
if (path3.resolve(file) === absoluteConfigPath) {
|
|
528
|
+
console.log("[MDX] restarting dev server");
|
|
529
|
+
watcher?.removeAllListeners();
|
|
530
|
+
void (async () => {
|
|
531
|
+
await core.init({
|
|
532
|
+
config: loadConfig(core, true)
|
|
533
|
+
});
|
|
534
|
+
await devServer();
|
|
535
|
+
await core.emit({ write: true });
|
|
536
|
+
})();
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
await core.initServer({ watcher });
|
|
540
|
+
}
|
|
541
|
+
process.on("exit", () => {
|
|
542
|
+
if (!watcher || watcher.closed) return;
|
|
543
|
+
console.log("[MDX] closing dev server");
|
|
544
|
+
void watcher.close();
|
|
545
|
+
});
|
|
546
|
+
await devServer();
|
|
547
|
+
}
|
|
548
|
+
async function createStandaloneCore(options) {
|
|
549
|
+
const core = createNextCore(applyDefaults(options));
|
|
550
|
+
await core.init({
|
|
551
|
+
config: loadConfig(core, true)
|
|
552
|
+
});
|
|
553
|
+
return core;
|
|
554
|
+
}
|
|
555
|
+
function applyDefaults(options) {
|
|
556
|
+
return {
|
|
557
|
+
outDir: options.outDir ?? Core.defaultOptions.outDir,
|
|
558
|
+
configPath: options.configPath ?? Core.defaultOptions.configPath
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function createNextCore(options) {
|
|
562
|
+
return new Core({
|
|
563
|
+
outDir: options.outDir,
|
|
564
|
+
configPath: options.configPath
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
568
|
+
0 && (module.exports = {
|
|
569
|
+
createContent,
|
|
570
|
+
createStandaloneCore
|
|
571
|
+
});
|