editlet 0.0.0-stage → 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +140 -2
- package/dist/admin/config.d.ts +22 -0
- package/dist/admin/config.js +75 -0
- package/dist/admin/dist/assets/RichEditor-BlaCRrEX.css +1 -0
- package/dist/admin/dist/assets/RichEditor-IZKdt6MK.js +42 -0
- package/dist/admin/dist/assets/blank-line-CbGzlqBI.js +1 -0
- package/dist/admin/dist/assets/channel-CljeMIwA.js +1 -0
- package/dist/admin/dist/assets/db-CCMyPgQa.js +1 -0
- package/dist/admin/dist/assets/index-CWoJh4H8.js +257 -0
- package/dist/admin/dist/assets/index-DkRMnD_M.css +1 -0
- package/dist/admin/dist/assets/mdast-util-from-markdown-C79q1_d8.js +3 -0
- package/dist/admin/dist/assets/mdast-util-gfm-cM-_xFJE.js +19 -0
- package/dist/admin/dist/assets/micromark-extension-gfm-Wz6-oszS.js +1 -0
- package/dist/admin/dist/assets/micromark-util-classify-character-BgXaGAja.js +1 -0
- package/dist/admin/dist/assets/micromark-util-html-tag-name-B61T18yC.js +1 -0
- package/dist/admin/dist/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/admin/dist/index.html +16 -0
- package/dist/admin/dist/preview.js +1 -0
- package/dist/admin/dist/window.js +1 -0
- package/dist/astro/content.d.ts +21 -0
- package/dist/astro/content.js +235 -0
- package/dist/astro/devServer.js +89 -0
- package/dist/astro/index.d.ts +15 -0
- package/dist/astro/index.js +98 -0
- package/dist/astro/nodeBridge.js +36 -0
- package/dist/astro/shared.js +10 -0
- package/dist/astro/stub/index.html +71 -0
- package/dist/auth/client.d.ts +24 -0
- package/dist/auth/client.js +120 -0
- package/dist/auth/handler.d.ts +16 -0
- package/dist/auth/handler.js +281 -0
- package/dist/auth/protocol.d.ts +25 -0
- package/dist/auth/protocol.js +3 -0
- package/dist/core/assets.d.ts +73 -0
- package/dist/core/assets.js +405 -0
- package/dist/core/devApi.d.ts +28 -0
- package/dist/core/devApi.js +3 -0
- package/dist/core/entryFile.d.ts +13 -0
- package/dist/core/entryFile.js +81 -0
- package/dist/core/fields.js +147 -0
- package/dist/core/generate.d.ts +3 -0
- package/dist/core/generate.js +70 -0
- package/dist/core/gitStyle.d.ts +92 -0
- package/dist/core/gitStyle.js +206 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +16 -0
- package/dist/core/issues.d.ts +10 -0
- package/dist/core/issues.js +10 -0
- package/dist/core/paths.d.ts +31 -0
- package/dist/core/paths.js +114 -0
- package/dist/core/project.js +56 -0
- package/dist/core/references.d.ts +68 -0
- package/dist/core/references.js +103 -0
- package/dist/core/rename.d.ts +60 -0
- package/dist/core/rename.js +133 -0
- package/dist/core/schema.d.ts +117 -0
- package/dist/core/schema.js +299 -0
- package/dist/core/sha.d.ts +2 -0
- package/dist/core/sha.js +13 -0
- package/dist/core/source.d.ts +48 -0
- package/dist/core/source.js +57 -0
- package/dist/core/validate.d.ts +22 -0
- package/dist/core/validate.js +148 -0
- package/dist/core/walk.d.ts +23 -0
- package/dist/core/walk.js +94 -0
- package/dist/core/writes.d.ts +37 -0
- package/dist/core/writes.js +166 -0
- package/dist/github/base64.js +16 -0
- package/dist/github/cache.d.ts +34 -0
- package/dist/github/cache.js +126 -0
- package/dist/github/client.d.ts +38 -0
- package/dist/github/client.js +228 -0
- package/dist/github/codeowners.d.ts +23 -0
- package/dist/github/codeowners.js +96 -0
- package/dist/github/commitReader.d.ts +25 -0
- package/dist/github/commitReader.js +38 -0
- package/dist/github/deploy.d.ts +15 -0
- package/dist/github/deploy.js +33 -0
- package/dist/github/index.d.ts +9 -0
- package/dist/github/index.js +8 -0
- package/dist/github/repo.d.ts +95 -0
- package/dist/github/repo.js +375 -0
- package/dist/github/source.d.ts +115 -0
- package/dist/github/source.js +558 -0
- package/dist/loader/index.d.ts +27 -0
- package/dist/loader/index.js +151 -0
- package/dist/loader/protocol.d.ts +95 -0
- package/dist/loader/protocol.js +120 -0
- package/dist/loader/window/geometry.js +9 -0
- package/dist/next/EditletLoader.d.ts +5 -0
- package/dist/next/EditletLoader.js +33 -0
- package/dist/next/assetUrl.d.ts +9 -0
- package/dist/next/assetUrl.js +13 -0
- package/dist/next/buildGuard.js +26 -0
- package/dist/next/config.d.ts +18 -0
- package/dist/next/config.js +255 -0
- package/dist/next/devServer.js +70 -0
- package/dist/next/editletField.d.ts +7 -0
- package/dist/next/editletField.js +7 -0
- package/dist/next/index.d.ts +8 -0
- package/dist/next/index.js +6 -0
- package/dist/next/preview.d.ts +18 -0
- package/dist/next/preview.js +100 -0
- package/dist/next/previewCookie.d.ts +5 -0
- package/dist/next/previewCookie.js +72 -0
- package/dist/next/previewEnv.js +25 -0
- package/dist/next/previewRef.d.ts +8 -0
- package/dist/next/previewRef.js +17 -0
- package/dist/next/publicDir.js +65 -0
- package/dist/next/reader.d.ts +49 -0
- package/dist/next/reader.js +161 -0
- package/dist/next/stub/index.html +56 -0
- package/dist/node/devHandler.d.ts +6 -0
- package/dist/node/devHandler.js +430 -0
- package/dist/node/fs.js +37 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.js +3 -0
- package/dist/node/project.d.ts +12 -0
- package/dist/node/project.js +43 -0
- package/package.json +187 -4
- package/skills/README.md +84 -0
- package/skills/editlet/SKILL.md +119 -0
- package/skills/editlet/references/content-format.md +191 -0
- package/skills/editlet/references/preview.md +75 -0
- package/skills/editlet/references/publishing.md +137 -0
- package/skills/editlet/references/schema-changes.md +127 -0
- package/skills/editlet/scripts/guard.mjs +1061 -0
- package/skills/editlet/scripts/link.mjs +193 -0
- package/skills/editlet/scripts/refs.mjs +1480 -0
- package/skills/editlet/scripts/schema.mjs +1340 -0
- package/skills/editlet/scripts/style.mjs +657 -0
- package/skills/editlet/scripts/types.mjs +525 -0
- package/skills/editlet/scripts/validate.mjs +724 -0
- package/skills/editlet-migrate/SKILL.md +92 -0
- package/skills/editlet-migrate/references/mapping.md +73 -0
- package/skills/editlet-migrate/references/sources.md +70 -0
- package/skills/editlet-setup/SKILL.md +108 -0
- package/skills/editlet-setup/references/astro.md +83 -0
- package/skills/editlet-setup/references/doctor.md +89 -0
- package/skills/editlet-setup/references/next.md +140 -0
- package/skills/editlet-setup/references/preview.md +54 -0
- package/skills/editlet-setup/references/production.md +153 -0
- package/skills/editlet-setup/references/roles.md +238 -0
- package/skills/editlet-setup/references/skills.md +99 -0
- package/skills/editlet-setup/scripts/doctor.mjs +1378 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { findDevHandlerCode } from "./buildGuard.js";
|
|
2
|
+
import { startDevApi } from "./devServer.js";
|
|
3
|
+
import { shouldResyncContent, syncAdminOnly, syncContent, syncPublicDir } from "./publicDir.js";
|
|
4
|
+
import { buildAdminConfig, resolveParam } from "../admin/config.js";
|
|
5
|
+
import { DEV_API_BASE } from "../core/devApi.js";
|
|
6
|
+
import { loadProjectSchema } from "../node/fs.js";
|
|
7
|
+
import { writeTypes } from "../node/project.js";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
10
|
+
import { watch } from "node:fs";
|
|
11
|
+
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "next/constants.js";
|
|
12
|
+
// next/config.ts
|
|
13
|
+
const PREPARED_ENV = "EDITLET_NEXT_PREPARED";
|
|
14
|
+
const DEV_API_KEY = "__editletDevApi";
|
|
15
|
+
const PREPARE_KEY = "__editletPrepare";
|
|
16
|
+
function report(error) {
|
|
17
|
+
const issues = error.issues;
|
|
18
|
+
if (Array.isArray(issues)) for (const i of issues) console.error(`[editlet] ${[i.file, i.path].filter(Boolean).join(" ")}: ${i.message}`);
|
|
19
|
+
else console.error(`[editlet] ${error instanceof Error ? error.message : String(error)}`);
|
|
20
|
+
}
|
|
21
|
+
function warn(message) {
|
|
22
|
+
console.warn(`[editlet] ${message}`);
|
|
23
|
+
}
|
|
24
|
+
async function resolveAdminConfigUncached(root, schemaPath, admin, dev) {
|
|
25
|
+
let baseBranch = null;
|
|
26
|
+
try {
|
|
27
|
+
baseBranch = (await loadProjectSchema(root, schemaPath)).git.baseBranch;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (!dev) throw error;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const config = buildAdminConfig(admin, {
|
|
33
|
+
baseBranch,
|
|
34
|
+
env: process.env
|
|
35
|
+
});
|
|
36
|
+
if (config.preview && !config.github) {
|
|
37
|
+
const message = "admin.preview needs a GitHub repo: set the admin.repo option (or deploy on Vercel) and a git.baseBranch in the schema.";
|
|
38
|
+
if (!dev) throw new TypeError(message);
|
|
39
|
+
warn(message);
|
|
40
|
+
delete config.preview;
|
|
41
|
+
}
|
|
42
|
+
if (!dev && !config.github) warn("admin: no GitHub repo configured (set the admin.repo option or deploy on Vercel); the production admin cannot open a repo.");
|
|
43
|
+
return config;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (!dev) throw error;
|
|
46
|
+
report(error);
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const ADMIN_CONFIG_KEY = "__editletAdminConfig";
|
|
51
|
+
const warnedOnce = /* @__PURE__ */ new Set();
|
|
52
|
+
/**
|
|
53
|
+
* One resolution per process, root, schema path and mode: `prepare` and the preview env injection share it, so the
|
|
54
|
+
* schema is read once and problems are reported once. A failure is cached too (a failed build stops anyway).
|
|
55
|
+
*/
|
|
56
|
+
function resolveAdminConfig(root, schemaPath, admin, dev) {
|
|
57
|
+
const g = globalThis;
|
|
58
|
+
const all = g[ADMIN_CONFIG_KEY] ??= /* @__PURE__ */ new Map();
|
|
59
|
+
const key = `${root}\0${schemaPath}\0${dev ? "dev" : "prod"}`;
|
|
60
|
+
let found = all.get(key);
|
|
61
|
+
if (!found) {
|
|
62
|
+
found = resolveAdminConfigUncached(root, schemaPath, admin, dev);
|
|
63
|
+
all.set(key, found);
|
|
64
|
+
}
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
/** The non-secret runtime config for the preview route, as the `EDITLET_PREVIEW` env value, or `null`. */
|
|
68
|
+
async function previewEnvFor(root, schemaPath, admin, dev, build) {
|
|
69
|
+
if (!admin?.preview) return null;
|
|
70
|
+
let config;
|
|
71
|
+
try {
|
|
72
|
+
config = await resolveAdminConfig(root, schemaPath, admin, dev);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (build) throw error;
|
|
75
|
+
const key = `${root}\0${schemaPath}`;
|
|
76
|
+
if (!dev && !warnedOnce.has(key)) {
|
|
77
|
+
warnedOnce.add(key);
|
|
78
|
+
warn(`admin.preview is off: ${error instanceof Error ? error.message : String(error)}`);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
if (!config.preview || !config.github) return null;
|
|
83
|
+
return JSON.stringify({
|
|
84
|
+
owner: config.github.owner,
|
|
85
|
+
repo: config.github.repo,
|
|
86
|
+
schemaPath,
|
|
87
|
+
sessionMinutes: config.sessionMinutes ?? 60
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function createSyncer(run) {
|
|
91
|
+
let running = null;
|
|
92
|
+
let pending = null;
|
|
93
|
+
const start = () => {
|
|
94
|
+
const p = run().finally(() => {
|
|
95
|
+
if (running === p) running = null;
|
|
96
|
+
});
|
|
97
|
+
running = p;
|
|
98
|
+
return p;
|
|
99
|
+
};
|
|
100
|
+
return () => {
|
|
101
|
+
if (!running) return start();
|
|
102
|
+
pending ??= running.catch(() => void 0).then(() => {
|
|
103
|
+
pending = null;
|
|
104
|
+
return start();
|
|
105
|
+
});
|
|
106
|
+
return pending;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function resolvePackageDir(root) {
|
|
110
|
+
try {
|
|
111
|
+
const entry = createRequire(join(root, "package.json")).resolve("editlet/next/config");
|
|
112
|
+
return dirname(dirname(entry));
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new Error(`Cannot locate the editlet package from ${root}: ${error instanceof Error ? error.message : error}`, { cause: error });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function startWatchers(root, schemaPath, typesFile, sync) {
|
|
118
|
+
const watchers = /* @__PURE__ */ new Set();
|
|
119
|
+
let contentWatcher = null;
|
|
120
|
+
let contentTimer;
|
|
121
|
+
let schemaTimer;
|
|
122
|
+
const resync = () => {
|
|
123
|
+
clearTimeout(contentTimer);
|
|
124
|
+
contentTimer = setTimeout(() => void sync().catch(report), 100);
|
|
125
|
+
};
|
|
126
|
+
const ensureContentWatcher = async () => {
|
|
127
|
+
const schema = await loadProjectSchema(root, schemaPath);
|
|
128
|
+
const dir = join(root, schema.contentDir);
|
|
129
|
+
if (contentWatcher?.dir === dir) return;
|
|
130
|
+
contentWatcher?.watcher.close();
|
|
131
|
+
watchers.delete(contentWatcher?.watcher);
|
|
132
|
+
contentWatcher = null;
|
|
133
|
+
const watcher = watch(dir, { recursive: true }, (_event, filename) => {
|
|
134
|
+
if (shouldResyncContent(filename ? filename.toString() : null)) resync();
|
|
135
|
+
}).unref();
|
|
136
|
+
watchers.add(watcher);
|
|
137
|
+
contentWatcher = {
|
|
138
|
+
dir,
|
|
139
|
+
watcher
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
ensureContentWatcher().catch(() => void 0);
|
|
143
|
+
const schemaFile = join(root, schemaPath);
|
|
144
|
+
try {
|
|
145
|
+
watchers.add(watch(dirname(schemaFile), (_event, filename) => {
|
|
146
|
+
if (filename && filename.toString() !== basename(schemaFile)) return;
|
|
147
|
+
clearTimeout(schemaTimer);
|
|
148
|
+
schemaTimer = setTimeout(() => {
|
|
149
|
+
(async () => {
|
|
150
|
+
await writeTypes(root, typesFile, schemaPath);
|
|
151
|
+
await sync();
|
|
152
|
+
await ensureContentWatcher();
|
|
153
|
+
})().catch(report);
|
|
154
|
+
}, 100);
|
|
155
|
+
}).unref());
|
|
156
|
+
} catch {}
|
|
157
|
+
}
|
|
158
|
+
async function runPrepare(root, schemaPath, typesFile, dev, pkgDir, contentSync, admin) {
|
|
159
|
+
const config = await resolveAdminConfig(root, schemaPath, admin, dev);
|
|
160
|
+
try {
|
|
161
|
+
await writeTypes(root, typesFile, schemaPath);
|
|
162
|
+
await syncPublicDir(root, schemaPath, pkgDir, config);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (!dev) throw error;
|
|
165
|
+
report(error);
|
|
166
|
+
try {
|
|
167
|
+
await syncAdminOnly(root, pkgDir, config);
|
|
168
|
+
} catch (inner) {
|
|
169
|
+
report(inner);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
process.env[PREPARED_ENV] = "1";
|
|
173
|
+
if (dev) startWatchers(root, schemaPath, typesFile, contentSync);
|
|
174
|
+
}
|
|
175
|
+
/** One prepare per process (and per project): concurrent config evaluations share it. */
|
|
176
|
+
function prepare(root, schemaPath, typesFile, dev, pkgDir, admin) {
|
|
177
|
+
if (process.env[PREPARED_ENV] === "1") return Promise.resolve();
|
|
178
|
+
const g = globalThis;
|
|
179
|
+
const all = g[PREPARE_KEY] ??= {};
|
|
180
|
+
const key = `${root}\0${schemaPath}`;
|
|
181
|
+
if (!all[key]) {
|
|
182
|
+
const contentSync = createSyncer(() => syncContent(root, schemaPath));
|
|
183
|
+
all[key] = {
|
|
184
|
+
done: runPrepare(root, schemaPath, typesFile, dev, pkgDir, contentSync, admin).catch((error) => {
|
|
185
|
+
delete all[key];
|
|
186
|
+
throw error;
|
|
187
|
+
}),
|
|
188
|
+
contentSync
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return all[key].done;
|
|
192
|
+
}
|
|
193
|
+
function ensureDevApi(root, schemaPath) {
|
|
194
|
+
const g = globalThis;
|
|
195
|
+
g[DEV_API_KEY] ??= startDevApi({
|
|
196
|
+
root,
|
|
197
|
+
schemaPath
|
|
198
|
+
}).catch((error) => {
|
|
199
|
+
delete g[DEV_API_KEY];
|
|
200
|
+
throw error;
|
|
201
|
+
});
|
|
202
|
+
return g[DEV_API_KEY];
|
|
203
|
+
}
|
|
204
|
+
function mergeRewrites(user, rewrite) {
|
|
205
|
+
if (user === void 0) return { beforeFiles: [rewrite] };
|
|
206
|
+
if (Array.isArray(user)) return {
|
|
207
|
+
beforeFiles: [rewrite],
|
|
208
|
+
afterFiles: user
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
...user,
|
|
212
|
+
beforeFiles: [rewrite, ...user.beforeFiles ?? []]
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function withEditlet(nextConfig = {}, options = {}) {
|
|
216
|
+
const root = options.root ?? process.cwd();
|
|
217
|
+
const schemaPath = options.schemaPath ?? "cms/schema.json";
|
|
218
|
+
return async (phase, ctx) => {
|
|
219
|
+
const user = typeof nextConfig === "function" ? await nextConfig(phase, ctx) : nextConfig;
|
|
220
|
+
const dev = phase === PHASE_DEVELOPMENT_SERVER;
|
|
221
|
+
const build = phase === PHASE_PRODUCTION_BUILD;
|
|
222
|
+
if (dev || build) {
|
|
223
|
+
const pkgDir = options.packageDir ?? resolvePackageDir(root);
|
|
224
|
+
await prepare(root, schemaPath, options.typesFile, dev, pkgDir, options.admin);
|
|
225
|
+
}
|
|
226
|
+
const previewEnv = await previewEnvFor(root, schemaPath, options.admin, dev, build);
|
|
227
|
+
const api = dev ? await ensureDevApi(root, schemaPath) : null;
|
|
228
|
+
const env = {
|
|
229
|
+
...user.env,
|
|
230
|
+
EDITLET_PARAM: resolveParam(options.admin, process.env)
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
...user,
|
|
234
|
+
env: previewEnv ? {
|
|
235
|
+
...env,
|
|
236
|
+
EDITLET_PREVIEW: previewEnv
|
|
237
|
+
} : env,
|
|
238
|
+
transpilePackages: [.../* @__PURE__ */ new Set([...user.transpilePackages ?? [], "editlet"])],
|
|
239
|
+
...api ? { async rewrites() {
|
|
240
|
+
return mergeRewrites(await user.rewrites?.(), {
|
|
241
|
+
source: `${DEV_API_BASE}/:path*`,
|
|
242
|
+
destination: `http://127.0.0.1:${api.port}${DEV_API_BASE}/:path*`
|
|
243
|
+
});
|
|
244
|
+
} } : build ? { compiler: {
|
|
245
|
+
...user.compiler,
|
|
246
|
+
async runAfterProductionCompile(metadata) {
|
|
247
|
+
await user.compiler?.runAfterProductionCompile?.(metadata);
|
|
248
|
+
const found = await findDevHandlerCode(resolve(metadata.projectDir, metadata.distDir));
|
|
249
|
+
if (found) throw new Error(`Editlet dev handler code leaked into the production build: ${found}`);
|
|
250
|
+
}
|
|
251
|
+
} } : {}
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
export { withEditlet };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { DEV_API_BASE } from "../core/devApi.js";
|
|
2
|
+
import { createDevHandler } from "../node/devHandler.js";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { createServer } from "node:http";
|
|
5
|
+
// next/devServer.ts
|
|
6
|
+
function firstValue(value) {
|
|
7
|
+
return Array.isArray(value) ? value[0] : value;
|
|
8
|
+
}
|
|
9
|
+
/** Browser-facing host from `x-forwarded-host` (first entry), or `null` when absent or empty. */
|
|
10
|
+
function forwardedHost(req) {
|
|
11
|
+
const first = firstValue(req.headers["x-forwarded-host"])?.split(",")[0]?.trim();
|
|
12
|
+
return first ? first : null;
|
|
13
|
+
}
|
|
14
|
+
function toRequest(req, host) {
|
|
15
|
+
const headers = new Headers();
|
|
16
|
+
for (const [name, value] of Object.entries(req.headers)) {
|
|
17
|
+
if (value === void 0) continue;
|
|
18
|
+
if (Array.isArray(value)) for (const v of value) headers.append(name, v);
|
|
19
|
+
else headers.set(name, value);
|
|
20
|
+
}
|
|
21
|
+
const method = req.method ?? "GET";
|
|
22
|
+
const hasBody = method !== "GET" && method !== "HEAD";
|
|
23
|
+
return new Request(`http://${host}${req.url ?? "/"}`, {
|
|
24
|
+
method,
|
|
25
|
+
headers,
|
|
26
|
+
body: hasBody ? Readable.toWeb(req) : void 0,
|
|
27
|
+
duplex: "half"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Dev-only loopback server that exposes the `/__editlet` file API; the Next adapter proxies to it so the
|
|
32
|
+
* site needs no route file. Never import this in production.
|
|
33
|
+
*/
|
|
34
|
+
async function startDevApi(options) {
|
|
35
|
+
if (process.env.NODE_ENV === "production") throw new Error("editlet/next/devServer must not be used in production");
|
|
36
|
+
const handler = createDevHandler(options);
|
|
37
|
+
let port = 0;
|
|
38
|
+
const server = createServer((req, res) => {
|
|
39
|
+
(async () => {
|
|
40
|
+
try {
|
|
41
|
+
const host = forwardedHost(req);
|
|
42
|
+
if (req.headers.host !== `127.0.0.1:${port}` || host === null) {
|
|
43
|
+
res.writeHead(403, { "Content-Type": "text/plain; charset=utf-8" });
|
|
44
|
+
res.end("Forbidden");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const response = await handler(toRequest(req, host));
|
|
48
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
49
|
+
res.writeHead(response.status, Object.fromEntries(response.headers));
|
|
50
|
+
res.end(body);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });
|
|
53
|
+
res.end(`${DEV_API_BASE}: ${error instanceof Error ? error.message : "internal error"}`);
|
|
54
|
+
}
|
|
55
|
+
})();
|
|
56
|
+
});
|
|
57
|
+
await new Promise((resolve, reject) => {
|
|
58
|
+
server.once("error", reject);
|
|
59
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
60
|
+
});
|
|
61
|
+
port = server.address().port;
|
|
62
|
+
return {
|
|
63
|
+
port,
|
|
64
|
+
close: () => new Promise((resolve, reject) => {
|
|
65
|
+
server.close((error) => error ? reject(error) : resolve());
|
|
66
|
+
server.closeAllConnections();
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export { startDevApi };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PreviewRef } from "./previewCookie.js";
|
|
2
|
+
/** Spread onto the element that shows `field`. Marks only in a draft render (entry carries `ref`); else `{}`. */
|
|
3
|
+
export declare function editletField(entry: {
|
|
4
|
+
collection: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
ref?: PreviewRef;
|
|
7
|
+
}, field: string): Record<string, string>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FIELD_ATTR, fieldMark } from "../loader/protocol.js";
|
|
2
|
+
// next/editletField.ts
|
|
3
|
+
/** Spread onto the element that shows `field`. Marks only in a draft render (entry carries `ref`); else `{}`. */
|
|
4
|
+
function editletField(entry, field) {
|
|
5
|
+
return entry.ref ? { [FIELD_ATTR]: fieldMark(`${entry.collection}/${entry.slug}`, field) } : {};
|
|
6
|
+
}
|
|
7
|
+
export { editletField };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Resolved } from "../core/references.js";
|
|
2
|
+
import { PreviewRef } from "./previewCookie.js";
|
|
3
|
+
import { AnyEntry, CollectionOf, ReadOptions, ReaderOptions, RefKey, ReferrerOptions, createReader } from "./reader.js";
|
|
4
|
+
import { CONTENT_URL, assetUrl } from "./assetUrl.js";
|
|
5
|
+
import { EditletLoader } from "./EditletLoader.js";
|
|
6
|
+
import { editletField } from "./editletField.js";
|
|
7
|
+
import { previewRef } from "./previewRef.js";
|
|
8
|
+
export { type AnyEntry, CONTENT_URL, type CollectionOf, EditletLoader, type PreviewRef, type ReadOptions, type ReaderOptions, type RefKey, type ReferrerOptions, type Resolved, assetUrl, createReader, editletField, previewRef };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createReader } from "./reader.js";
|
|
2
|
+
import { CONTENT_URL, assetUrl } from "./assetUrl.js";
|
|
3
|
+
import { EditletLoader } from "./EditletLoader.js";
|
|
4
|
+
import { editletField } from "./editletField.js";
|
|
5
|
+
import { previewRef } from "./previewRef.js";
|
|
6
|
+
export { CONTENT_URL, EditletLoader, assetUrl, createReader, editletField, previewRef };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface PreviewHandlerDeps {
|
|
2
|
+
fetch?: typeof fetch;
|
|
3
|
+
/** Milliseconds since the epoch. */
|
|
4
|
+
now?: () => number;
|
|
5
|
+
}
|
|
6
|
+
export interface PreviewHandlers {
|
|
7
|
+
POST(req: Request): Promise<Response>;
|
|
8
|
+
DELETE(): Promise<Response>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The preview Route Handler. `POST { branch, sha }` with the editor's GitHub token in `Authorization` checks push
|
|
12
|
+
* access once, turns on draft mode and sets the signed preview cookie. `DELETE` ends the session.
|
|
13
|
+
* The editor token is used for the permission call only; it is never stored, logged or put in the cookie.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createPreviewHandlers(deps?: PreviewHandlerDeps): PreviewHandlers;
|
|
16
|
+
/** Re-export from `app/api/editlet/preview/route.ts`: `export { POST, DELETE } from 'editlet/next/preview'`. */
|
|
17
|
+
export declare const POST: (req: Request) => Promise<Response>;
|
|
18
|
+
export declare const DELETE: () => Promise<Response>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { PREVIEW_COOKIE, isPreviewRef, readPreviewSecret, signPreview } from "./previewCookie.js";
|
|
2
|
+
import { readPreviewEnv } from "./previewEnv.js";
|
|
3
|
+
import { cookies, draftMode } from "next/headers";
|
|
4
|
+
// next/preview.ts
|
|
5
|
+
function reply(status, message) {
|
|
6
|
+
const headers = { "Cache-Control": "no-store" };
|
|
7
|
+
if (message === void 0) return new Response(null, {
|
|
8
|
+
status,
|
|
9
|
+
headers
|
|
10
|
+
});
|
|
11
|
+
headers["Content-Type"] = "text/plain; charset=utf-8";
|
|
12
|
+
return new Response(message, {
|
|
13
|
+
status,
|
|
14
|
+
headers
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function missingEnv() {
|
|
18
|
+
if (!readPreviewSecret()) return "CMS_PREVIEW_SECRET is missing or shorter than 32 characters";
|
|
19
|
+
if (!process.env.CMS_GITHUB_TOKEN) return "CMS_GITHUB_TOKEN is missing";
|
|
20
|
+
if (!readPreviewEnv()) return "EDITLET_PREVIEW is missing or malformed; turn on admin.preview in withEditlet";
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function bearerToken(req) {
|
|
24
|
+
const match = /^Bearer\s+(\S+)\s*$/i.exec(req.headers.get("authorization") ?? "");
|
|
25
|
+
return match ? match[1] : null;
|
|
26
|
+
}
|
|
27
|
+
async function endPreview() {
|
|
28
|
+
(await draftMode()).disable();
|
|
29
|
+
(await cookies()).delete({
|
|
30
|
+
name: PREVIEW_COOKIE,
|
|
31
|
+
path: "/"
|
|
32
|
+
});
|
|
33
|
+
return reply(204);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The preview Route Handler. `POST { branch, sha }` with the editor's GitHub token in `Authorization` checks push
|
|
37
|
+
* access once, turns on draft mode and sets the signed preview cookie. `DELETE` ends the session.
|
|
38
|
+
* The editor token is used for the permission call only; it is never stored, logged or put in the cookie.
|
|
39
|
+
*/
|
|
40
|
+
function createPreviewHandlers(deps = {}) {
|
|
41
|
+
const now = deps.now ?? Date.now;
|
|
42
|
+
async function POST(req) {
|
|
43
|
+
if (req.headers.get("origin") !== new URL(req.url).origin) return reply(403, "Forbidden origin");
|
|
44
|
+
const missing = missingEnv();
|
|
45
|
+
if (missing) return reply(500, `Preview is not configured: ${missing}`);
|
|
46
|
+
const secret = readPreviewSecret();
|
|
47
|
+
const env = readPreviewEnv();
|
|
48
|
+
let body;
|
|
49
|
+
try {
|
|
50
|
+
body = await req.json();
|
|
51
|
+
} catch {
|
|
52
|
+
return reply(400, "Body must be JSON { branch, sha }");
|
|
53
|
+
}
|
|
54
|
+
if (!isPreviewRef(body)) return reply(400, "branch must be a branch name and sha a 40-character commit id");
|
|
55
|
+
const { branch, sha } = body;
|
|
56
|
+
const token = bearerToken(req);
|
|
57
|
+
if (!token) return reply(401, "Missing Authorization: Bearer token");
|
|
58
|
+
const doFetch = deps.fetch ?? fetch;
|
|
59
|
+
let canPush = false;
|
|
60
|
+
try {
|
|
61
|
+
const res = await doFetch(`https://api.github.com/repos/${encodeURIComponent(env.owner)}/${encodeURIComponent(env.repo)}`, {
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: `Bearer ${token}`,
|
|
64
|
+
Accept: "application/vnd.github+json",
|
|
65
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
66
|
+
},
|
|
67
|
+
cache: "no-store"
|
|
68
|
+
});
|
|
69
|
+
if (res.status >= 500 || res.status === 429) return reply(502, `GitHub answered ${res.status}; try again`);
|
|
70
|
+
if (res.ok) canPush = (await res.json())?.permissions?.push === true;
|
|
71
|
+
} catch {
|
|
72
|
+
return reply(502, "Could not reach GitHub");
|
|
73
|
+
}
|
|
74
|
+
if (!canPush) return reply(403, "No push access to the repository");
|
|
75
|
+
const maxAge = Math.round(env.sessionMinutes * 60);
|
|
76
|
+
const value = await signPreview({
|
|
77
|
+
branch,
|
|
78
|
+
sha,
|
|
79
|
+
exp: Math.floor(now() / 1e3) + maxAge
|
|
80
|
+
}, secret);
|
|
81
|
+
(await draftMode()).enable();
|
|
82
|
+
(await cookies()).set(PREVIEW_COOKIE, value, {
|
|
83
|
+
httpOnly: true,
|
|
84
|
+
secure: true,
|
|
85
|
+
sameSite: "lax",
|
|
86
|
+
path: "/",
|
|
87
|
+
maxAge
|
|
88
|
+
});
|
|
89
|
+
return reply(204);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
POST,
|
|
93
|
+
DELETE: endPreview
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const handlers = createPreviewHandlers();
|
|
97
|
+
/** Re-export from `app/api/editlet/preview/route.ts`: `export { POST, DELETE } from 'editlet/next/preview'`. */
|
|
98
|
+
const POST = handlers.POST;
|
|
99
|
+
const DELETE = handlers.DELETE;
|
|
100
|
+
export { DELETE, POST, createPreviewHandlers };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isRefPath } from "../core/schema.js";
|
|
2
|
+
import { EDITLET_SOURCE } from "../loader/protocol.js";
|
|
3
|
+
// next/previewCookie.ts
|
|
4
|
+
const PREVIEW_COOKIE = `${EDITLET_SOURCE}-preview`;
|
|
5
|
+
const SHA_RE = /^[0-9a-f]{40}$/;
|
|
6
|
+
/** `CMS_PREVIEW_SECRET` when it is set and long enough, else `null`. */
|
|
7
|
+
function readPreviewSecret() {
|
|
8
|
+
const secret = process.env.CMS_PREVIEW_SECRET;
|
|
9
|
+
return secret && secret.length >= 32 ? secret : null;
|
|
10
|
+
}
|
|
11
|
+
function isPreviewRef(value) {
|
|
12
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
13
|
+
const { branch, sha } = value;
|
|
14
|
+
return typeof branch === "string" && isRefPath(branch) && typeof sha === "string" && SHA_RE.test(sha);
|
|
15
|
+
}
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
function b64url(bytes) {
|
|
18
|
+
let binary = "";
|
|
19
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
20
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
21
|
+
}
|
|
22
|
+
/** Strict decode: only the canonical unpadded encoding is accepted, so one value has one spelling. */
|
|
23
|
+
function fromB64url(text) {
|
|
24
|
+
if (!/^[A-Za-z0-9_-]+$/.test(text)) return null;
|
|
25
|
+
let binary;
|
|
26
|
+
try {
|
|
27
|
+
binary = atob(text.replace(/-/g, "+").replace(/_/g, "/"));
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
|
|
32
|
+
return b64url(bytes) === text ? bytes : null;
|
|
33
|
+
}
|
|
34
|
+
function hmacKey(secret, usage) {
|
|
35
|
+
return crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
36
|
+
name: "HMAC",
|
|
37
|
+
hash: "SHA-256"
|
|
38
|
+
}, false, [usage]);
|
|
39
|
+
}
|
|
40
|
+
/** `<b64url(json)>.<b64url(HMAC-SHA256 over the first part)>`. */
|
|
41
|
+
async function signPreview(payload, secret) {
|
|
42
|
+
const body = b64url(encoder.encode(JSON.stringify({
|
|
43
|
+
branch: payload.branch,
|
|
44
|
+
sha: payload.sha,
|
|
45
|
+
exp: payload.exp
|
|
46
|
+
})));
|
|
47
|
+
const sig = await crypto.subtle.sign("HMAC", await hmacKey(secret, "sign"), encoder.encode(body));
|
|
48
|
+
return `${body}.${b64url(new Uint8Array(sig))}`;
|
|
49
|
+
}
|
|
50
|
+
/** The signed ref, or `null` when the value is malformed, tampered with, or expired (`exp <= now / 1000`). */
|
|
51
|
+
async function verifyPreview(value, secret, now = Date.now()) {
|
|
52
|
+
const parts = value.split(".");
|
|
53
|
+
if (parts.length !== 2) return null;
|
|
54
|
+
const [body, sigText] = parts;
|
|
55
|
+
const sig = fromB64url(sigText);
|
|
56
|
+
if (!sig || !fromB64url(body)) return null;
|
|
57
|
+
if (!await crypto.subtle.verify("HMAC", await hmacKey(secret, "verify"), sig, encoder.encode(body))) return null;
|
|
58
|
+
let payload;
|
|
59
|
+
try {
|
|
60
|
+
payload = JSON.parse(new TextDecoder().decode(fromB64url(body)));
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (!isPreviewRef(payload)) return null;
|
|
65
|
+
const { exp } = payload;
|
|
66
|
+
if (typeof exp !== "number" || !Number.isFinite(exp) || exp <= now / 1e3) return null;
|
|
67
|
+
return {
|
|
68
|
+
branch: payload.branch,
|
|
69
|
+
sha: payload.sha
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export { PREVIEW_COOKIE, SHA_RE, isPreviewRef, readPreviewSecret, signPreview, verifyPreview };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// next/previewEnv.ts
|
|
2
|
+
/** The non-secret preview config `withEditlet` injects as `EDITLET_PREVIEW`. `null` when missing or malformed. */
|
|
3
|
+
function readPreviewEnv() {
|
|
4
|
+
const raw = process.env.EDITLET_PREVIEW;
|
|
5
|
+
if (!raw) return null;
|
|
6
|
+
let value;
|
|
7
|
+
try {
|
|
8
|
+
value = JSON.parse(raw);
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
13
|
+
const { owner, repo, schemaPath, sessionMinutes } = value;
|
|
14
|
+
if (typeof owner !== "string" || !owner) return null;
|
|
15
|
+
if (typeof repo !== "string" || !repo) return null;
|
|
16
|
+
if (typeof schemaPath !== "string" || !schemaPath) return null;
|
|
17
|
+
if (typeof sessionMinutes !== "number" || !Number.isFinite(sessionMinutes) || sessionMinutes <= 0) return null;
|
|
18
|
+
return {
|
|
19
|
+
owner,
|
|
20
|
+
repo,
|
|
21
|
+
schemaPath,
|
|
22
|
+
sessionMinutes
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export { readPreviewEnv };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PreviewRef } from "./previewCookie.js";
|
|
2
|
+
/**
|
|
3
|
+
* The ref a draft render reads, or `undefined` for a normal render. Defined only when draft mode is on and the
|
|
4
|
+
* preview cookie verifies with `CMS_PREVIEW_SECRET` and has not expired. Call it outside `"use cache"` scopes and pass
|
|
5
|
+
* the result to the reader (and to cached helpers as an argument).
|
|
6
|
+
*/
|
|
7
|
+
export declare function previewRef(): Promise<PreviewRef | undefined>;
|
|
8
|
+
export type { PreviewRef };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PREVIEW_COOKIE, readPreviewSecret, verifyPreview } from "./previewCookie.js";
|
|
2
|
+
import { cookies, draftMode } from "next/headers";
|
|
3
|
+
// next/previewRef.ts
|
|
4
|
+
/**
|
|
5
|
+
* The ref a draft render reads, or `undefined` for a normal render. Defined only when draft mode is on and the
|
|
6
|
+
* preview cookie verifies with `CMS_PREVIEW_SECRET` and has not expired. Call it outside `"use cache"` scopes and pass
|
|
7
|
+
* the result to the reader (and to cached helpers as an argument).
|
|
8
|
+
*/
|
|
9
|
+
async function previewRef() {
|
|
10
|
+
if (!(await draftMode()).isEnabled) return void 0;
|
|
11
|
+
const secret = readPreviewSecret();
|
|
12
|
+
if (!secret) return void 0;
|
|
13
|
+
const value = (await cookies()).get(PREVIEW_COOKIE)?.value;
|
|
14
|
+
if (!value) return void 0;
|
|
15
|
+
return await verifyPreview(value, secret) ?? void 0;
|
|
16
|
+
}
|
|
17
|
+
export { previewRef };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ADMIN_CONFIG_FILE } from "../admin/config.js";
|
|
2
|
+
import { isHiddenContentPath, isImagePath } from "../core/paths.js";
|
|
3
|
+
import { DEFAULT_SCHEMA_PATH, listFiles, loadProjectSchema } from "../node/fs.js";
|
|
4
|
+
import { access, cp, mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { dirname, extname, join } from "node:path";
|
|
6
|
+
// next/publicDir.ts
|
|
7
|
+
const GENERATED_MARKER = ".editlet-generated";
|
|
8
|
+
async function exists(path) {
|
|
9
|
+
try {
|
|
10
|
+
await access(path);
|
|
11
|
+
return true;
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function adminSource(pkg) {
|
|
17
|
+
const dist = join(pkg, "admin", "dist");
|
|
18
|
+
return await exists(join(dist, "index.html")) ? dist : join(pkg, "next", "stub");
|
|
19
|
+
}
|
|
20
|
+
const RM = {
|
|
21
|
+
recursive: true,
|
|
22
|
+
force: true,
|
|
23
|
+
maxRetries: 3
|
|
24
|
+
};
|
|
25
|
+
async function assertOwned(out) {
|
|
26
|
+
if (!await exists(join(out, ".editlet-generated"))) throw new Error(`Refusing to overwrite ${out}: it was not generated by Editlet (no ${GENERATED_MARKER} marker).`);
|
|
27
|
+
}
|
|
28
|
+
/** Rebuilds the admin part of `public/editlet/` (everything except `content/`), including `config.json`. Used once per prepare. */
|
|
29
|
+
async function syncAdminOnly(root, pkgDir, config) {
|
|
30
|
+
const out = join(root, "public", "editlet");
|
|
31
|
+
if (await exists(out)) {
|
|
32
|
+
await assertOwned(out);
|
|
33
|
+
for (const name of await readdir(out)) if (name !== ".editlet-generated" && name !== "content") await rm(join(out, name), RM);
|
|
34
|
+
} else {
|
|
35
|
+
await mkdir(out, { recursive: true });
|
|
36
|
+
await writeFile(join(out, GENERATED_MARKER), "Generated by editlet/next. Safe to delete.\n");
|
|
37
|
+
}
|
|
38
|
+
await cp(await adminSource(pkgDir), out, { recursive: true });
|
|
39
|
+
await writeFile(join(out, ADMIN_CONFIG_FILE), `${JSON.stringify(config, null, 2)}\n`);
|
|
40
|
+
}
|
|
41
|
+
/** Rebuilds only `public/editlet/content/` (the images under `contentDir`); the admin files are not touched. */
|
|
42
|
+
async function syncContent(root, schemaPath = DEFAULT_SCHEMA_PATH) {
|
|
43
|
+
const out = join(root, "public", "editlet");
|
|
44
|
+
await assertOwned(out);
|
|
45
|
+
const schema = await loadProjectSchema(root, schemaPath);
|
|
46
|
+
const files = await listFiles(root, schema.contentDir);
|
|
47
|
+
await rm(join(out, "content"), RM);
|
|
48
|
+
for (const file of files) {
|
|
49
|
+
if (!isImagePath(file) || isHiddenContentPath(schema, file)) continue;
|
|
50
|
+
const target = join(out, "content", file.slice(schema.contentDir.length + 1));
|
|
51
|
+
await mkdir(dirname(target), { recursive: true });
|
|
52
|
+
await cp(join(root, file), target);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Full rebuild of `<root>/public/editlet/`: the admin bundle plus the content images. */
|
|
56
|
+
async function syncPublicDir(root, schemaPath = DEFAULT_SCHEMA_PATH, pkgDir, config) {
|
|
57
|
+
await syncAdminOnly(root, pkgDir, config);
|
|
58
|
+
await syncContent(root, schemaPath);
|
|
59
|
+
}
|
|
60
|
+
/** Watch events worth a content re-sync: image files, or paths without an extension (directory moves/deletes). */
|
|
61
|
+
function shouldResyncContent(filename) {
|
|
62
|
+
if (!filename) return true;
|
|
63
|
+
return isImagePath(filename) || extname(filename) === "";
|
|
64
|
+
}
|
|
65
|
+
export { GENERATED_MARKER, shouldResyncContent, syncAdminOnly, syncContent, syncPublicDir };
|