#!/usr/bin/env node // SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC // SPDX-License-Identifier: Apache-2.0 /** * What a built site is made of, as JSON: the version and commit of each of the three repositories, and the Mojo the * corpus is pinned to. scripts/assemble.sh writes it to site/build.json beside VERSION (which stays the site's own * commit, for the deploy's smoke test), so the live site can say exactly which commits it was built from. * * node scripts/build-info.mjs print it * * A version is the one package.json states (pplus-library has none: its commit is its version); `describe` is * `git describe --tags --always --dirty`, so a tagged release reads as its tag and a change not yet committed says * so. Outside a git checkout a commit is null. GITHUB_SHA, when CI sets it, is the site's commit. */ import fs from 'node:fs'; import path from 'node:path'; import { spawnSync } from 'node:child_process'; import { fileURLToPath } from 'node:url'; const WEB = fileURLToPath(new URL('..', import.meta.url)); function git(dir, ...args) { const r = spawnSync('git', ['-C', dir, ...args], { encoding: 'utf8' }); return r.status === 0 ? r.stdout.trim() : null; } const version = (dir) => { try { return JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).version ?? null; } catch { return null; } }; /** One repository's entry. */ function repo(dir, name) { return { name, version: version(dir), commit: git(dir, 'rev-parse', 'HEAD'), describe: git(dir, 'describe', '--tags', '--always', '--dirty') }; } /** The build's description: web, core and library, and the pinned Mojo. */ export function buildInfo(web = WEB) { const core = path.join(web, 'core'); const lib = path.join(core, 'library'); const site = repo(web, 'pplus-web'); if (process.env.GITHUB_SHA && !site.commit) site.commit = process.env.GITHUB_SHA; let mojo = null; try { mojo = JSON.parse(fs.readFileSync(path.join(lib, 'mojo', 'pin.json'), 'utf8')).mojo.version; } catch { /* no library checked out */ } return { web: site, core: repo(core, 'pplus-core'), library: repo(lib, 'pplus-library'), mojo }; } if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { process.stdout.write(`${JSON.stringify(buildInfo(), null, 2)}\n`); }