ferst-core 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ // ferst-set-cms-branch — stamp the Sveltia CMS backend branch to match THIS
3
+ // deployment's branch, so config.yml never drifts from the platform git-proxy's
4
+ // branch policy (dev deploy → dev, main → main). Run it AFTER `astro build`:
5
+ //
6
+ // "build": "astro build && ferst-set-cms-branch"
7
+ //
8
+ // It rewrites the built CMS config's `branch:` from CF_PAGES_BRANCH (Cloudflare
9
+ // Pages), falling back to the current git branch, then `main`. The COMMITTED
10
+ // config.yml stays a neutral placeholder, identical on every branch — no
11
+ // per-branch config, no merge hazard.
12
+ //
13
+ // Why it matters: Sveltia READS content from `branch`, and the git-proxy rejects
14
+ // writes whose branch != the project's branch policy. A wrong value = the CMS
15
+ // shows no content and any save 403s. This makes that impossible to ship
16
+ // silently — it fails the build loudly if it can't stamp.
17
+ //
18
+ // Config path: `dist/admin/config.yml` under the current working directory
19
+ // (the client repo root at build time). Override with a first CLI arg.
20
+ import { readFileSync, writeFileSync } from 'node:fs';
21
+ import { execSync } from 'node:child_process';
22
+ import { resolve } from 'node:path';
23
+
24
+ const CONFIG = resolve(process.cwd(), process.argv[2] ?? 'dist/admin/config.yml');
25
+
26
+ function deploymentBranch() {
27
+ const cf = process.env.CF_PAGES_BRANCH?.trim();
28
+ if (cf) return cf;
29
+ try {
30
+ const git = execSync('git rev-parse --abbrev-ref HEAD', {
31
+ stdio: ['ignore', 'pipe', 'ignore'],
32
+ }).toString().trim();
33
+ if (git && git !== 'HEAD') return git;
34
+ } catch {
35
+ /* not a git checkout — fall through */
36
+ }
37
+ return 'main';
38
+ }
39
+
40
+ const branch = deploymentBranch();
41
+
42
+ let yml;
43
+ try {
44
+ yml = readFileSync(CONFIG, 'utf8');
45
+ } catch {
46
+ console.error(`ferst-set-cms-branch: ${CONFIG} not found — run this AFTER astro build.`);
47
+ process.exit(1);
48
+ }
49
+
50
+ // Check the `branch:` line EXISTS separately from whether it changed — stamping
51
+ // the same value (e.g. main→main on the prod placeholder) is a valid no-op.
52
+ const BRANCH_LINE = /^(\s*branch:\s*)\S.*$/m;
53
+ if (!BRANCH_LINE.test(yml)) {
54
+ console.error('ferst-set-cms-branch: no "branch:" line found in the CMS config backend.');
55
+ process.exit(1);
56
+ }
57
+ writeFileSync(CONFIG, yml.replace(BRANCH_LINE, `$1${branch}`));
58
+ console.log(`ferst-set-cms-branch: CMS backend branch → "${branch}"`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ferst-core",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "description": "Ferst Core — the shared, brand-agnostic client-site system: Astro components, layouts, content schemas, the layered config resolver, and a neutral styling architecture that every client overrides.",
6
6
  "license": "BUSL-1.1",
@@ -44,7 +44,8 @@
44
44
  "LICENSE-Apache-2.0"
45
45
  ],
46
46
  "bin": {
47
- "ferst-check-thin": "bin/check-thin.mjs"
47
+ "ferst-check-thin": "bin/check-thin.mjs",
48
+ "ferst-set-cms-branch": "bin/set-cms-branch.mjs"
48
49
  },
49
50
  "dependencies": {
50
51
  "zod": "^3.25.0"