-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncweb.mjs
More file actions
55 lines (48 loc) · 2.14 KB
/
Copy pathsyncweb.mjs
File metadata and controls
55 lines (48 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Syncs source-of-truth files from this repo into the sibling homeworldz.com
// website repo, so the Cloudflare Pages build (which only checks out that repo)
// bundles current copies. Run manually from this repo root: `node syncweb.mjs`.
//
// Changed files are left UNSTAGED in homeworldz.com for you to review, commit,
// and push (pushing homeworldz.com is what triggers the Pages deploy). No-ops
// when the sibling website repo is not present next to this one.
//
// Add entries to `files` as more content needs to travel from this repo to the
// website. Line endings are normalized to LF to match the website repo and
// avoid spurious working-tree churn.
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const repoRoot = dirname(fileURLToPath(import.meta.url));
const webRoot = resolve(repoRoot, "../homeworldz.com");
// { from } is relative to this repo; { to } is relative to homeworldz.com.
// The website keeps per-project roadmaps under content/roadmaps/; this repo's
// is the server roadmap.
const files = [{ from: "docs/ROADMAP.md", to: "content/roadmaps/SERVER.md" }];
const toLf = (text) => text.replace(/\r\n/g, "\n");
if (!existsSync(webRoot)) {
console.log(`[syncweb] Sibling homeworldz.com not found (${webRoot}); nothing to do.`);
process.exit(0);
}
let changed = 0;
for (const { from, to } of files) {
const source = resolve(repoRoot, from);
const dest = resolve(webRoot, to);
if (!existsSync(source)) {
console.warn(`[syncweb] Source missing, skipped: ${from}`);
continue;
}
const sourceText = toLf(readFileSync(source, "utf8"));
if (existsSync(dest) && toLf(readFileSync(dest, "utf8")) === sourceText) {
console.log(`[syncweb] up to date: ${to}`);
continue;
}
mkdirSync(dirname(dest), { recursive: true });
writeFileSync(dest, sourceText);
console.log(`[syncweb] updated: ${to} (from ${from})`);
changed += 1;
}
console.log(
changed > 0
? `[syncweb] ${changed} file(s) updated in homeworldz.com — review, commit, and push to deploy.`
: "[syncweb] everything already in sync.",
);