2020-06-01 23:08:34 +00:00
|
|
|
const fs = require('fs');
|
2020-07-10 21:48:50 +00:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2019-06-02 20:03:03 +00:00
|
|
|
|
2020-07-10 21:48:50 +00:00
|
|
|
const configPath = process.argv[2];
|
|
|
|
const outPath = path.resolve(process.argv[3]);
|
|
|
|
const config = require(configPath);
|
2019-06-02 20:03:03 +00:00
|
|
|
config.output = {
|
|
|
|
path: path.dirname(outPath),
|
|
|
|
filename: path.basename(outPath)
|
2020-07-10 21:48:50 +00:00
|
|
|
};
|
2019-06-02 20:03:03 +00:00
|
|
|
|
2020-09-04 21:53:49 +00:00
|
|
|
const { wrapInitWithProfilingTimeout, wrapInitWithTryCatch, ...webpackConfig } = config;
|
2020-06-01 23:08:34 +00:00
|
|
|
|
2020-09-04 21:53:49 +00:00
|
|
|
webpack(webpackConfig, (err, stats) => {
|
2019-06-02 20:03:03 +00:00
|
|
|
if (err) {
|
2020-07-10 21:48:50 +00:00
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
2019-06-02 20:03:03 +00:00
|
|
|
} else if (stats.hasErrors()) {
|
2020-07-10 21:48:50 +00:00
|
|
|
console.error(stats.toString('normal'));
|
|
|
|
process.exit(1);
|
2019-06-02 20:03:03 +00:00
|
|
|
} else {
|
2020-09-04 21:53:49 +00:00
|
|
|
let contents = fs.readFileSync(outPath, 'utf8');
|
|
|
|
if (wrapInitWithTryCatch) {
|
|
|
|
contents = `try {
|
|
|
|
${contents}
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Electron ${webpackConfig.output.filename} script failed to run');
|
|
|
|
console.error(err);
|
|
|
|
}`;
|
|
|
|
}
|
2020-06-01 23:08:34 +00:00
|
|
|
if (wrapInitWithProfilingTimeout) {
|
2020-09-04 21:53:49 +00:00
|
|
|
contents = `function ___electron_webpack_init__() {
|
2020-06-01 23:08:34 +00:00
|
|
|
${contents}
|
|
|
|
};
|
|
|
|
if ((globalThis.process || binding.process).argv.includes("--profile-electron-init")) {
|
|
|
|
setTimeout(___electron_webpack_init__, 0);
|
|
|
|
} else {
|
|
|
|
___electron_webpack_init__();
|
|
|
|
}`;
|
|
|
|
}
|
2020-09-04 21:53:49 +00:00
|
|
|
fs.writeFileSync(outPath, contents);
|
2020-07-10 21:48:50 +00:00
|
|
|
process.exit(0);
|
2019-06-02 20:03:03 +00:00
|
|
|
}
|
2020-07-10 21:48:50 +00:00
|
|
|
});
|