|
| 1 | +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 2 | +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ |
| 3 | +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ |
| 4 | +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ |
| 5 | +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ |
| 6 | +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ |
| 7 | +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ |
| 8 | +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ |
| 9 | +// ┃ This file is part of the Perspective library, distributed under the terms ┃ |
| 10 | +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ |
| 11 | +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 12 | + |
| 13 | +import * as fs from "node:fs"; |
| 14 | +import * as path from "node:path"; |
| 15 | +import { execFileSync } from "node:child_process"; |
| 16 | +import { fileURLToPath } from "node:url"; |
| 17 | + |
| 18 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 19 | +const REPO_ROOT = path.resolve(__dirname, ".."); |
| 20 | +const DIST = path.join(__dirname, "dist"); |
| 21 | +const STAGING = path.join(REPO_ROOT, "dist-gh-pages"); |
| 22 | +const BRANCH = "gh-pages"; |
| 23 | + |
| 24 | +function git(args, opts = {}) { |
| 25 | + return execFileSync("git", args, { |
| 26 | + stdio: "inherit", |
| 27 | + cwd: REPO_ROOT, |
| 28 | + ...opts, |
| 29 | + }); |
| 30 | +} |
| 31 | + |
| 32 | +function copyRecursive(src, dest) { |
| 33 | + const stat = fs.statSync(src); |
| 34 | + if (stat.isDirectory()) { |
| 35 | + fs.mkdirSync(dest, { recursive: true }); |
| 36 | + for (const child of fs.readdirSync(src)) { |
| 37 | + copyRecursive(path.join(src, child), path.join(dest, child)); |
| 38 | + } |
| 39 | + } else { |
| 40 | + fs.copyFileSync(src, dest); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +if (!fs.existsSync(DIST)) { |
| 45 | + console.error(`Missing ${DIST} — run \`npm run build\` first.`); |
| 46 | + process.exit(1); |
| 47 | +} |
| 48 | + |
| 49 | +if (!fs.existsSync(STAGING)) { |
| 50 | + git(["worktree", "add", STAGING, BRANCH]); |
| 51 | +} else { |
| 52 | + git(["fetch", "origin", BRANCH]); |
| 53 | + git(["checkout", `origin/${BRANCH}`], { cwd: STAGING }); |
| 54 | +} |
| 55 | + |
| 56 | +// Clear tracked + untracked content in the staging worktree, preserving |
| 57 | +// the worktree's `.git` link. |
| 58 | +git(["rm", "-rf", "--quiet", "--ignore-unmatch", "."], { cwd: STAGING }); |
| 59 | +git(["clean", "-fdx"], { cwd: STAGING }); |
| 60 | + |
| 61 | +for (const entry of fs.readdirSync(DIST)) { |
| 62 | + copyRecursive(path.join(DIST, entry), path.join(STAGING, entry)); |
| 63 | +} |
| 64 | + |
| 65 | +git(["add", "-A"], { cwd: STAGING }); |
| 66 | + |
| 67 | +console.log(`Staged dist/ onto ${BRANCH} at ${STAGING}`); |
| 68 | +console.log(`Review with \`git -C ${STAGING} status\`, then commit and push.`); |
0 commit comments