Skip to content

Commit 595cdbc

Browse files
committed
Add docs deploy script
Signed-off-by: Andrew Stein <steinlink@gmail.com>
1 parent 643b74a commit 595cdbc

4 files changed

Lines changed: 107 additions & 9 deletions

File tree

docs/deploy.mjs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.`);

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"start": "node server.mjs",
99
"serve": "node server.mjs",
1010
"clean": "rm -rf dist",
11+
"deploy": "node deploy.mjs",
1112
"mdbook": "docker compose run --rm mdbook build"
1213
},
1314
"dependencies": {

packages/viewer-charts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@perspective-dev/viewer-charts",
3-
"version": "4.3.0",
3+
"version": "4.5.0",
44
"description": "Perspective.js WebGL Plugin",
55
"unpkg": "./dist/cdn/perspective-viewer-charts.js",
66
"jsdelivr": "./dist/cdn/perspective-viewer-charts.js",

tools/scripts/publish.mjs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import { Octokit } from "octokit";
1414
import fs from "node:fs/promises";
15+
import { execSync } from "child_process";
1516

1617
import "zx/globals";
1718

@@ -62,6 +63,11 @@ async function download_release_assets(releases) {
6263
);
6364
}
6465

66+
const SH_ENV = {
67+
env: process.env,
68+
stdio: "inherit",
69+
};
70+
6571
async function publish_release_assets(releases) {
6672
if (process.env.COMMIT) {
6773
for (const release of releases) {
@@ -70,22 +76,45 @@ async function publish_release_assets(releases) {
7076
release.name.endsWith("tar.gz")) &&
7177
release.name.indexOf("wasm") === -1
7278
) {
73-
$.sync`twine upload ${release.name}`;
79+
execSync(`twine upload ${release.name}`, SH_ENV);
7480
} else if (release.name.endsWith(".tgz")) {
75-
$.sync`npm publish ${release.name}`;
81+
execSync(`npm publish ${release.name}`, SH_ENV);
7682
} else {
7783
console.log(`Skipping "${release.name}"`);
7884
}
7985
}
8086

8187
await $`mkdir -p rust/target/package && mv *.crate rust/target/package`;
8288

83-
await $`cargo publish -p perspective-server --allow-dirty --no-verify`;
84-
await $`cargo publish -p perspective-client --allow-dirty --no-verify`;
85-
await $`cargo publish -p perspective-python --allow-dirty --no-verify`;
86-
await $`cargo publish -p perspective-js --allow-dirty --no-verify`;
87-
await $`cargo publish -p perspective-viewer --allow-dirty --no-verify`;
88-
await $`cargo publish -p perspective --allow-dirty --no-verify`;
89+
execSync(
90+
`cargo publish -p perspective-server --allow-dirty --no-verify`,
91+
SH_ENV,
92+
);
93+
94+
execSync(
95+
`cargo publish -p perspective-client --allow-dirty --no-verify`,
96+
SH_ENV,
97+
);
98+
99+
execSync(
100+
`cargo publish -p perspective-python --allow-dirty --no-verify`,
101+
SH_ENV,
102+
);
103+
104+
execSync(
105+
`cargo publish -p perspective-js --allow-dirty --no-verify`,
106+
SH_ENV,
107+
);
108+
109+
execSync(
110+
`cargo publish -p perspective-viewer --allow-dirty --no-verify`,
111+
SH_ENV,
112+
);
113+
114+
execSync(
115+
`cargo publish -p perspective --allow-dirty --no-verify`,
116+
SH_ENV,
117+
);
89118
} else {
90119
console.warn(`COMMIT not specified, aborting`);
91120
}

0 commit comments

Comments
 (0)