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