Dashboard (content library, publishing queue with approvals, inbox, team management, AI runs), Meta connector, branded PDF reports, agent skills, and Docker packaging (Dockerfile, docker-compose with Caddy HTTPS, backup and path-relocation scripts). Client data, live data and secrets are excluded via .gitignore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
2.2 KiB
JavaScript
46 lines
2.2 KiB
JavaScript
// After moving the project to another machine (e.g. Windows PC → Linux server), point stored
|
|
// media paths in the content library and publishing queue at the new location.
|
|
// node connector/scripts/relocate-paths.js (shows what would change)
|
|
// node connector/scripts/relocate-paths.js --write (saves; keeps a .bak copy of each file)
|
|
// In Docker: docker compose run --rm app node connector/scripts/relocate-paths.js --write
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { PROJECT_ROOT } from "../src/env.js";
|
|
|
|
const FILES = ["data/library/items.json", "data/schedule/queue.json"].map((f) => path.join(PROJECT_ROOT, f));
|
|
const write = process.argv.includes("--write");
|
|
const DATA_DIR = path.join(PROJECT_ROOT, "data");
|
|
|
|
// Any absolute path (Windows or POSIX) that contains a "data" folder → same path under this machine's data/.
|
|
function relocate(value) {
|
|
if (typeof value !== "string" || /^https?:\/\//i.test(value)) return value;
|
|
const m = value.match(/^(?:[A-Za-z]:)?[\\/](?:.*?[\\/])?data[\\/](.+)$/);
|
|
if (!m) return value;
|
|
const next = path.join(DATA_DIR, ...m[1].split(/[\\/]/));
|
|
return next === value ? value : next;
|
|
}
|
|
|
|
let changed = 0, missing = 0;
|
|
function walk(node) {
|
|
if (Array.isArray(node)) return node.map(walk);
|
|
if (node && typeof node === "object") return Object.fromEntries(Object.entries(node).map(([k, v]) => [k, walk(v)]));
|
|
const next = relocate(node);
|
|
if (next !== node) {
|
|
changed++;
|
|
if (!fs.existsSync(next)) { missing++; console.log(` missing on this machine: ${next}`); }
|
|
}
|
|
return next;
|
|
}
|
|
|
|
for (const file of FILES) {
|
|
if (!fs.existsSync(file)) { console.log(`skip (not found): ${path.relative(PROJECT_ROOT, file)}`); continue; }
|
|
const before = changed;
|
|
const out = walk(JSON.parse(fs.readFileSync(file, "utf8")));
|
|
console.log(`${path.relative(PROJECT_ROOT, file)}: ${changed - before} path(s) to update`);
|
|
if (write && changed > before) {
|
|
fs.copyFileSync(file, `${file}.bak`);
|
|
fs.writeFileSync(file, JSON.stringify(out, null, 2));
|
|
}
|
|
}
|
|
console.log(write ? `Done. ${changed} path(s) updated, ${missing} file(s) not found.` : `Dry run: ${changed} path(s) would change, ${missing} file(s) not found. Add --write to save.`);
|