Enforce prod mode, return a Promise so it can be used programmatically

This commit is contained in:
Rich Harris
2018-01-14 13:45:01 -05:00
committed by GitHub
parent d6dda371ca
commit 6a4dc1901c

View File

@@ -1,3 +1,5 @@
process.env.NODE_ENV = 'production';
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const mkdirp = require('mkdirp'); const mkdirp = require('mkdirp');
@@ -14,15 +16,16 @@ module.exports = () => {
// create main.js and server-routes.js // create main.js and server-routes.js
create_app(); create_app();
return new Promise((fulfil, reject) => {
function handleErrors(err, stats) { function handleErrors(err, stats) {
if (err) { if (err) {
console.error(err ? err.details || err.stack || err.message || err : 'Unknown error'); reject(err);
process.exit(1); process.exit(1);
} }
if (stats.hasErrors()) { if (stats.hasErrors()) {
console.log(stats.toString({ colors: true })); console.error(stats.toString({ colors: true }));
process.exit(1); reject(new Error(`Encountered errors while building app`));
} }
} }
@@ -37,6 +40,8 @@ module.exports = () => {
fs.writeFileSync(path.join(dest, 'stats.server.json'), JSON.stringify(serverInfo, null, ' ')); fs.writeFileSync(path.join(dest, 'stats.server.json'), JSON.stringify(serverInfo, null, ' '));
generate_asset_cache(clientInfo, serverInfo); generate_asset_cache(clientInfo, serverInfo);
fulfil();
});
}); });
}); });
}; };