2021-06-19 20:21:32 +02:00
|
|
|
/**
|
|
|
|
* 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) => {
|
2021-07-13 00:28:11 +02:00
|
|
|
const buildProcess = exec('npm run build'); // Trigger the build command
|
2021-06-19 20:21:32 +02:00
|
|
|
|
2021-07-13 00:28:11 +02:00
|
|
|
let output = ''; // Will store console output
|
2021-06-19 20:21:32 +02:00
|
|
|
|
2021-07-13 00:28:11 +02:00
|
|
|
// Write output to console, and append to var for returning
|
2021-06-19 20:21:32 +02:00
|
|
|
buildProcess.stdout.on('data', (data) => {
|
|
|
|
process.stdout.write(data);
|
|
|
|
output += data;
|
|
|
|
});
|
|
|
|
|
2021-07-13 00:28:11 +02:00
|
|
|
// Handle errors, by sending the reject
|
2021-06-19 20:21:32 +02:00
|
|
|
buildProcess.on('error', (error) => {
|
|
|
|
reject(Error({
|
|
|
|
success: false,
|
|
|
|
error,
|
|
|
|
output,
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2021-07-13 00:28:11 +02:00
|
|
|
// When finished, check success, make message and resolve response
|
2021-06-19 20:21:32 +02:00
|
|
|
buildProcess.on('exit', (response) => {
|
|
|
|
const success = response === 0;
|
|
|
|
const message = `Build process exited with ${response}: `
|
|
|
|
+ `${success ? 'Success' : 'Possible Error'}`;
|
|
|
|
resolve({ success, message, output });
|
|
|
|
});
|
|
|
|
});
|