forked from thomasboyt/manygolf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flightplan.js
53 lines (40 loc) · 1.21 KB
/
flightplan.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
'use strict';
const plan = require('flightplan');
const secret = require('./secret.json');
const globSync = require('glob').sync;
const sshConfig = {
host: secret.host,
username: secret.username,
agent: process.env.SSH_AUTH_SOCK,
};
plan.target('production', sshConfig, secret.environments.production);
plan.target('client-staging', sshConfig, secret.environments['client-staging']);
plan.remote((remote) => {
remote.rm(`-rf ${getTmpPath()}`, {failsafe: true});
});
plan.local((local) => {
local.log('Building...');
local.npm('run build-client');
const files = globSync('build/client/**/*')
.concat(globSync('static/**/*'));
local.log('Uploading files...');
local.transfer(files, getTmpPath());
});
function getWebRoot() {
return plan.runtime.options.path;
}
function getTmpPath() {
return `/tmp/manygolf-${plan.runtime.target}`;
}
plan.remote((remote) => {
remote.log('Replacing files...');
const outPath = getWebRoot();
const tmpPath = getTmpPath();
remote.rm(`-rf ${outPath}`, {failsafe: true});
remote.mkdir(`-p ${outPath}`);
remote.cd(outPath);
remote.with(`cd ${outPath}`, () => {
remote.cp(`-r ${tmpPath}/build/client/* .`);
remote.cp(`-r ${tmpPath}/static/* .`);
});
});