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