-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-date-version.mjs
More file actions
52 lines (45 loc) · 1.75 KB
/
set-date-version.mjs
File metadata and controls
52 lines (45 loc) · 1.75 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
#!/usr/bin/env node
/**
* Set package.json version to a CalVer YYYY.M.D (no leading zeros) based on UTC date.
* If the current version already matches today's date, append a numeric suffix
* (YYYY.M.D.N) to keep publishing multiple builds per day — npm accepts 4-segment
* versions via the semver "build" via prerelease style is not ideal, so we instead
* go to YYYY.M.D{N*10+...} style — but most of the time this is a no-op.
*
* Convention matches AceDataCloud MCP servers (e.g. SunoMCP: 2026.1.22, 2026.1.22.6).
*
* Usage:
* node scripts/set-date-version.mjs # set to today's date
* node scripts/set-date-version.mjs --dry-run # print only
*/
import { readFileSync, writeFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const pkgPath = resolve(__dirname, '..', 'package.json');
const now = new Date();
const y = now.getUTCFullYear();
const m = now.getUTCMonth() + 1;
const d = now.getUTCDate();
const datePrefix = `${y}.${m}.${d}`;
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
const current = pkg.version ?? '';
let next;
if (current === datePrefix) {
next = `${datePrefix}.1`;
} else if (current.startsWith(`${datePrefix}.`)) {
const tail = current.slice(datePrefix.length + 1);
const n = Number.parseInt(tail, 10);
next = Number.isFinite(n) ? `${datePrefix}.${n + 1}` : `${datePrefix}.1`;
} else {
next = datePrefix;
}
const dryRun = process.argv.includes('--dry-run');
console.log(`current version: ${current}`);
console.log(`new version: ${next}`);
if (dryRun) {
process.exit(0);
}
pkg.version = next;
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
console.log(`✓ wrote ${pkgPath}`);