UNPKG

4bnode

Version:

4bnode is a CLI-powered backend development platform with a built-in visual dashboard to generate, manage, and test Node.js/Express APIs faster.

48 lines (42 loc) 2.1 kB
#!/usr/bin/env node // ───────────────────────────────────────────────────────────────────────────── // Sync shared, project-bound modules into the skeleton. // // Some modules (currently lib/codegen.js) must exist BOTH in the 4bnode package // (for the CLI) AND inside every generated project's .4bnode/ folder (for the // in-project dashboard, dev-api.js). The package copy is the source of truth; // this script copies it verbatim into skeleton/.4bnode/ so the two never drift. // // Run automatically before publish (prepublishOnly) and manually via `npm run sync`. // ───────────────────────────────────────────────────────────────────────────── import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const root = path.join(__dirname, ".."); // Each entry: a package file copied verbatim into the skeleton. const SYNC_TARGETS = [ { src: path.join(root, "lib", "codegen.js"), dest: path.join(root, "skeleton", ".4bnode", "codegen.js"), }, ]; let changed = 0; for (const { src, dest } of SYNC_TARGETS) { if (!fs.existsSync(src)) { console.error(`✖ Source missing: ${path.relative(root, src)}`); process.exitCode = 1; continue; } const content = fs.readFileSync(src, "utf8"); const prev = fs.existsSync(dest) ? fs.readFileSync(dest, "utf8") : null; fs.mkdirSync(path.dirname(dest), { recursive: true }); if (prev !== content) { fs.writeFileSync(dest, content, "utf8"); changed++; console.log(`~ synced ${path.relative(root, src)}${path.relative(root, dest)}`); } else { console.log(`= up to date ${path.relative(root, dest)}`); } } console.log(changed === 0 ? "✔ Skeleton already in sync" : `✔ Synced ${changed} file(s)`);