Skip to content

Commit 1fad925

Browse files
committed
Add script to deploy build output
1 parent 18acc5a commit 1fad925

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

deploy.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import path from "path";
2+
import fs from "fs";
3+
import { execSync } from "child_process";
4+
5+
const githubRemoteURL = "https://github.com/NetLogo/ColorPicker.git";
6+
const deployBranch = "build";
7+
8+
const distDir = path.resolve("./dist");
9+
process.chdir(distDir);
10+
11+
if (fs.existsSync(".git")) {
12+
execSync("git remote set-url origin " + githubRemoteURL);
13+
} else {
14+
execSync("git init");
15+
execSync(`git checkout --orphan ${deployBranch}`);
16+
execSync(`git remote add origin ${githubRemoteURL}`);
17+
execSync("git fetch origin " + deployBranch, { stdio: "ignore" });
18+
}
19+
20+
execSync("git add .");
21+
try {
22+
execSync(`git commit -m 'Deploy to ${deployBranch}'`);
23+
} catch (e) {
24+
console.warn("Nothing to commit.");
25+
}
26+
execSync(`git push origin ${deployBranch} --force`);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dev": "vite",
88
"build": "tsc && vite build && vite build --mode inlined",
99
"build:inlined": "vite build --mode inlined",
10+
"deploy": "npm run build && node deploy.js",
1011
"preview": "vite preview"
1112
},
1213
"devDependencies": {

0 commit comments

Comments
 (0)