-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.mjs
More file actions
77 lines (66 loc) · 3.84 KB
/
deploy.mjs
File metadata and controls
77 lines (66 loc) · 3.84 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░░░▄▀░█▀▄░█▀▀░█▀▀░█░█░█░░░█▀█░█▀▄░░░░░█░░░█▀█░█░█░█▀█░█░█░▀█▀░▀▄░░░░░░░░
// ░░░░░░░▀▄░░█▀▄░█▀▀░█░█░█░█░█░░░█▀█░█▀▄░▀▀▀░█░░░█▀█░░█░░█░█░█░█░░█░░░▄▀░░░░░░░
// ░░░░░░░░░▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░▀░▀░░░░░▀▀▀░▀░▀░░▀░░▀▀▀░▀▀▀░░▀░░▀░░░░░░░░░
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ * Copyright (c) 2026, the Regular Layout Authors. This file is part * ┃
// ┃ * of the Regular Layout library, distributed under the terms of the * ┃
// ┃ * [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). * ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
import { execSync } from "node:child_process";
import { cpSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
function exec(command, options = {}) {
console.log(`> ${command}`);
return execSync(command, { stdio: "inherit", ...options });
}
function execOutput(command) {
return execSync(command, { encoding: "utf-8" }).trim();
}
try {
console.log("Checking git status...");
const gitStatus = execOutput("git status --porcelain");
if (gitStatus) {
console.error("Error: Git staging area is not clean. Please commit or stash your changes.");
console.error(gitStatus);
process.exit(1);
}
console.log("Building project...");
exec("pnpm run build");
console.log("Preparing deployment files...");
const currentBranch = execOutput("git rev-parse --abbrev-ref HEAD");
const currentCommit = execOutput("git rev-parse --short HEAD");
const tempDir = mkdtempSync(join(tmpdir(), "gh-pages-"));
cpSync("dist", join(tempDir, "dist"), { recursive: true });
cpSync("examples", tempDir, { recursive: true });
console.log("Switching to gh-pages branch...");
let ghPagesExists = false;
try {
execSync("git show-ref --verify --quiet refs/heads/gh-pages");
ghPagesExists = true;
} catch (e) {
throw new Error("No gh-pages branch found");
}
if (ghPagesExists) {
exec("git checkout gh-pages");
exec("git add -A");
exec("git stash");
} else {
throw new Error("No gh-pages branch found");
}
console.log("Copying build artifacts...");
cpSync(tempDir, ".", { recursive: true });
console.log("Committing changes...");
exec("git add -A");
exec(`git commit -m "Deploy from ${currentBranch} @ ${currentCommit}"`);
console.log(`Returning to ${currentBranch}...`);
exec(`git stash pop`);
exec(`git checkout ${currentBranch}`);
rmSync(tempDir, { recursive: true, force: true });
console.log("Deployment complete! gh-pages branch updated locally.");
} catch (error) {
console.error("Deployment failed:", error.message);
process.exit(1);
}