-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun
executable file
·66 lines (60 loc) · 1.93 KB
/
run
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
#!/usr/bin/env node
require("./support/jbash.js");
function help() {
echo(`\
Usage: run [command]
Runs commands for development tooling and deployment
Commands:
init Initializes the project by installing dependencies and seeding a config file
start Starts the server (default command)
deploy [user@host] Deploys the application (assumes user@host has sudo access)
`);
}
let command = $1 || "start";
switch (command) {
case "init":
console.log("\x1b[33m%s\x1b[0m", "Initializing project ...");
exec(
"set -x; cd ./src && cp -n -v config.example.json config.json || true && npm install"
);
break;
case "start":
const fs = require("fs");
if (
!fs.existsSync("./src/config.json") ||
!fs.existsSync("./src/node_modules")
) {
console.log(
"\x1b[31m%s\x1b[0m",
"Project not initialized!\nUse `./run init` first."
);
} else {
console.log("\x1b[33m%s\x1b[0m", "Starting server ...");
exec(`cd ./src && npm run dev`);
}
break;
case "deploy":
const userAtHost = $2;
if (userAtHost) {
console.log(
"[user@host] argument required for deployment.\nFor example: ./run deploy [email protected]"
);
}
const appName = require("./src/package.json").name; // Pull name from package.json
const deployPath = `/opt/${appName}`;
console.log("\x1b[33m%s\x1b[0m", "Deploying ...");
set("-x");
echo("[Building]");
exec(`cd ./src && npm run build`);
echo("[Copying files]");
exec(
`ssh ${userAtHost} "set -x; sudo mkdir -p ${deployPath} && sudo chown -R ${userAtHost} ${deployPath}"`
);
exec(`rsync -arv ./src/ ${userAtHost}:${deployPath} --delete`);
echo("[Provisioning]");
exec(`ssh ${userAtHost} "sudo ${deployPath}/provision-systemd.sh"`);
console.log("\x1b[32m%s\x1b[0m", "Deployment was successful!");
break;
default:
help();
}