-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbundle.js
122 lines (113 loc) · 2.94 KB
/
bundle.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env node
/*
Copyright (C) 2013-2017 Bryan Hughes <[email protected]>
Aquarium Control is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Aquarium Control is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Aquarium Control. If not, see <http://www.gnu.org/licenses/>.
*/
const spawn = require('child_process').spawn;
const path = require('path');
const fs = require('fs');
const DESTINATION_DIR = path.join(__dirname, '..', 'aquarium-control-deploy');
console.log('Cleaning previous build...');
clean((error) => {
if (error) {
console.error(error);
return;
}
console.log('Building server and client...');
build((error) => {
if (error) {
console.error(error);
return;
}
console.log('Assembling image...');
assemble((error) => {
if (error) {
console.error(error);
return;
}
console.log('Finished building');
});
});
});
function clean(cb) {
function rmdir(dir) {
const files = fs.readdirSync(dir);
for (const file of files) {
if (file === '.git' || file === '.vscode') {
continue;
}
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
rmdir(filePath);
fs.rmdirSync(filePath);
} else {
fs.unlinkSync(filePath);
}
}
}
rmdir(DESTINATION_DIR);
setImmediate(cb);
}
function build(cb) {
spawn('npm', [ 'run', 'build' ], {
stdio: 'inherit',
cwd: path.join(__dirname, 'server')
}).on('close', (code) => {
if (code) {
cb(`Could not build server`);
return;
}
spawn('npm', [ 'run', 'build' ], {
stdio: 'inherit',
cwd: path.join(__dirname, 'client')
}).on('close', (code) => {
if (code) {
cb(`Could not build client`);
return;
}
cb();
});
});
}
function assemble(cb) {
const fileList = [
`${__dirname}/.gitignore`,
`${__dirname}/server/dist`,
`${__dirname}/server/views`,
`${__dirname}/server/package.json`,
`${__dirname}/server/package-lock.json`,
];
spawn('cp', [ '-r',
...fileList,
DESTINATION_DIR
], {
stdio: 'inherit',
cwd: __dirname
}).on('close', (code) => {
if (code) {
cb('Could not assemble server');
return;
}
spawn('cp', [ '-r', `${__dirname}/client/dist`, `${DESTINATION_DIR}/client` ], {
stdio: 'inherit',
cwd: __dirname
}).on('close', (code) => {
if (code) {
cb('Could not assemble client');
return;
}
cb();
});
});
cb();
}