-
Notifications
You must be signed in to change notification settings - Fork 14
/
gh-pages-deploy.mjs
63 lines (61 loc) · 1.25 KB
/
gh-pages-deploy.mjs
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
/* eslint-disable max-statements, no-process-exit, no-console */
import { execa } from "execa";
import * as emoji from "node-emoji";
import chalk from "chalk";
import * as fs from "fs";
const iconArrows = emoji.get("fast_forward");
const iconRocket = emoji.get("rocket");
(async () => {
try {
await execa("git", [
"checkout",
"--orphan",
"gh-pages",
]);
console.log(`${iconArrows} ${chalk.yellow("Building started...")}`);
await execa("npm", [
"run",
"build",
]);
// Understand if it's dist or build folder
const folderName = fs.existsSync("dist") ? "dist" : "build";
await execa("git", [
"--work-tree",
folderName,
"add",
"--all",
]);
await execa("git", [
"--work-tree",
folderName,
"commit",
"-m",
"gh-pages",
]);
console.log(`${iconArrows} ${chalk.yellow("Pushing to gh-pages...")}`);
await execa("git", [
"push",
"origin",
"HEAD:gh-pages",
"--force",
]);
await execa("rm", [
"-r",
folderName,
]);
await execa("git", [
"checkout",
"-f",
"master",
]);
await execa("git", [
"branch",
"-D",
"gh-pages",
]);
console.log(`${iconRocket} ${chalk.green("Successfully deployed")} ${iconRocket}`);
} catch (e) {
console.log(e.message);
process.exit(1);
}
})();