forked from Lissy93/dashy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild-app.js
34 lines (29 loc) · 1.01 KB
/
rebuild-app.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
/**
* This script programmatically triggers a production build
* and responds with the status, message and full output
*/
const { exec } = require('child_process');
module.exports = () => new Promise((resolve, reject) => {
const buildProcess = exec('NODE_OPTIONS="--max-old-space-size=512" npm run build'); // Trigger the build command
let output = ''; // Will store console output
// Write output to console, and append to var for returning
buildProcess.stdout.on('data', (data) => {
process.stdout.write(data);
output += data;
});
// Handle errors, by sending the reject
buildProcess.on('error', (error) => {
reject(Error({
success: false,
error,
output,
}));
});
// When finished, check success, make message and resolve response
buildProcess.on('exit', (response) => {
const success = response === 0;
const message = `Build process exited with ${response}: `
+ `${success ? 'Success' : 'Possible Error'}`;
resolve({ success, message, output });
});
});