Adds an endpoint for rebuilding the app, so that it can be triggered from the UI

This commit is contained in:
Alicia Sykes
2021-06-19 19:21:32 +01:00
parent 6337e5d7e4
commit b0d5b63703
2 changed files with 44 additions and 3 deletions

31
services/rebuild-app.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* 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('npm run build');
let output = '';
buildProcess.stdout.on('data', (data) => {
process.stdout.write(data);
output += data;
});
buildProcess.on('error', (error) => {
reject(Error({
success: false,
error,
output,
}));
});
buildProcess.on('exit', (response) => {
const success = response === 0;
const message = `Build process exited with ${response}: `
+ `${success ? 'Success' : 'Possible Error'}`;
resolve({ success, message, output });
});
});