33 lines
1.4 KiB
JavaScript
33 lines
1.4 KiB
JavaScript
// Copies the locally installed @sveltia/cms bundle into public/admin so
|
|
// the CMS page is fully self-hosted: the site bakes the bundle into its
|
|
// static output and nothing loads from a CDN at runtime. The bundle
|
|
// references its per-backend chunks relative to itself, so the chunks
|
|
// tree rides along. Source maps and the ESM wrapper stay out — the
|
|
// admin page loads sveltia-cms.js with a plain script tag.
|
|
//
|
|
// NOTE: the package's "." export is the bundler API wrapper
|
|
// (npm/index.js), NOT the standalone browser bundle — the script tag
|
|
// always loads dist/sveltia-cms.js.
|
|
import { cpSync, rmSync, readdirSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const distDir = join(process.cwd(), "node_modules", "@sveltia/cms", "dist");
|
|
const destDir = join(fileURLToPath(new URL(".", import.meta.url)), "public", "admin");
|
|
|
|
// Only the build outputs are removed — index.html and config.yml live in
|
|
// this directory and are tracked in git.
|
|
for (const stale of ["sveltia-cms.js", "sveltia-cms.mjs", "chunks"]) {
|
|
rmSync(join(destDir, stale), { recursive: true, force: true });
|
|
}
|
|
|
|
for (const entry of readdirSync(distDir)) {
|
|
if (entry === "sveltia-cms.mjs" || entry.endsWith(".map")) continue;
|
|
cpSync(join(distDir, entry), join(destDir, entry), {
|
|
recursive: true,
|
|
filter: (src) => !src.endsWith(".map"),
|
|
});
|
|
}
|
|
|
|
console.log(`copied @sveltia/cms dist -> ${destDir}`);
|