-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-system.mjs
More file actions
63 lines (55 loc) · 1.96 KB
/
Copy pathupdate-system.mjs
File metadata and controls
63 lines (55 loc) · 1.96 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
56
57
58
59
60
61
62
63
#!/usr/bin/env node
/**
* update-system.mjs — check/apply student-ops system updates.
*
* Commands:
* node update-system.mjs check # JSON status
* node update-system.mjs apply # pull latest system files, preserve user layer
* node update-system.mjs dismiss # skip this version
* node update-system.mjs rollback # undo last apply
*
* User layer (never touched):
* config/profile.yml, modes/_profile.md, portals.yml, data/*, reports/*,
* output/*, essays/*, aid-letters/*
*/
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const VERSION = path.join(__dirname, "VERSION");
const DISMISSED = path.join(__dirname, ".update-dismissed");
const cmd = process.argv[2] || "check";
function readVersion() {
if (!fs.existsSync(VERSION)) return "0.0.0";
return fs.readFileSync(VERSION, "utf8").trim();
}
async function check() {
const local = readVersion();
// TODO: wire up to GitHub releases / remote VERSION file
// For now, return up-to-date.
const result = { status: "up-to-date", local };
if (fs.existsSync(DISMISSED)) {
const dismissed = fs.readFileSync(DISMISSED, "utf8").trim();
result.dismissed = dismissed;
}
console.log(JSON.stringify(result));
}
function dismiss() {
fs.writeFileSync(DISMISSED, readVersion());
console.log(JSON.stringify({ status: "dismissed", version: readVersion() }));
}
async function apply() {
console.log(JSON.stringify({ status: "noop", message: "Update endpoint not yet wired. Update manually via git pull for now." }));
}
function rollback() {
console.log(JSON.stringify({ status: "noop", message: "Rollback not yet implemented." }));
}
switch (cmd) {
case "check": await check(); break;
case "apply": await apply(); break;
case "dismiss": dismiss(); break;
case "rollback": rollback(); break;
default:
console.error(`Unknown command: ${cmd}`);
process.exit(1);
}