-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.js
95 lines (78 loc) · 3.03 KB
/
deploy.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const mode = process.argv[2];
if (!mode) {
console.log("No mode specified; will deploy to production");
}
console.log(`\nAttempting to deploy to "${mode ? mode : "production"}"`);
const public_env_file = path.resolve(__dirname, mode ? `.env.${mode}` : ".env");
const local_env_file = path.resolve(__dirname, mode ? `.env.${mode}.local` : ".env.local");
const env_file = fs.existsSync(local_env_file) ? local_env_file : public_env_file;
if (!fs.existsSync(env_file)) {
console.error(`No env file found for ${mode ? mode : "production"}`);
process.exit(1);
}
// load with dotenv
const env = require("dotenv").config({ path: env_file });
function centerMsg(opt, message) {
const width = process.stdout.columns;
if (message.length > width) {
message = message.slice(0, width - 3) + "...";
}
const spaces = " ".repeat(Math.max(Math.floor((width - message.length) / 2), 9));
console.log(opt, spaces + message);
}
function runCommand(command, tag, message) {
const width = Math.floor((process.stdout.columns - 10) / 2);
console.log(
"\x1b[33m%s\x1b[0m",
`\n|${"-".repeat(Math.max(width - Math.ceil(tag.length / 2), 0))} START ${tag} ${"-".repeat(
Math.max(width - Math.floor(tag.length / 2), 0)
)}|\n`
);
centerMsg("\x1b[34m%s\x1b[0m", message);
execSync(command, { stdio: "inherit" });
console.log(
"\x1b[33m%s\x1b[0m",
`\n|${"-".repeat(Math.max(width + 1 - Math.ceil(tag.length / 2), 0))} END ${tag} ${"-".repeat(
Math.max(width + 1 - Math.floor(tag.length / 2), 0)
)}|\n`
);
}
function deploy() {
// if this is a fork, pull the upstream
const hasUpstream = execSync("git remote -v").toString().includes("upstream");
if (hasUpstream) {
runCommand("git pull upstream main", "pull", "Pulling upstream");
runCommand("git push origin main", "push", "Pushing to origin");
} else {
// create the documentation
runCommand(
[
// remove existing docs
"rm -r -f public/docs",
// compile ts to js for docs generation, into tmp folder
"tsc --outDir tmp --rootDir src",
// generate the docs
"jsdoc -c jsdoc.config",
// delete the tmp folder
"rm -r -f tmp",
].join(" && "),
"build docs",
"Building new JSDocs from transpiled TypeScript src"
);
centerMsg("\x1b[35m\x1b[2m%s\x1b[0m", "NOTE: JSDocs may lose content during compiling");
}
runCommand(
`vue-cli-service build${mode ? ` --mode ${mode}` : ""}`,
"build",
`Building "${env.parsed.VUE_APP_BRAND_NAME_LONG}" (${env.parsed.VUE_APP_BRAND_NAME_SHORT})`
);
runCommand("npm run postbuild", "postbuild", "Running postbuild script");
const domain = env.parsed.VUE_APP_BRAND_DOMAIN;
runCommand(`echo ${domain} > ./dist/CNAME`, "domain", `Writing domain ${domain} to CNAME`);
runCommand("npm run publish", "publish", "Publishing to remote gh-pages branch");
centerMsg("\n\x1b[32m%s\x1b[0m", "[ finished deploying ]\n\n");
}
deploy();