-
Notifications
You must be signed in to change notification settings - Fork 214
/
develop.js
93 lines (80 loc) · 2.48 KB
/
develop.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const WebpackDevServer = require("webpack-dev-server");
const webpack = require("webpack");
const [mainConfig, rendererConfig] = require("./webpack.config.js")(null, {mode: "development"});
const childProcess = require("child_process");
const weblog = require("webpack-log");
const log = weblog({name: "develop"});
async function main() {
process.on("unhandledRejection", (e) => {
log.error(`Unhandled rejection `, e.stack || e);
process.exit(1);
});
process.on("uncaughtException", (e) => {
log.error(`Uncaught exception `, e.stack || e);
process.exit(1);
});
const mainPromise = new Promise((resolve, reject) => {
webpack(mainConfig, (err, stats) => {
if (err) {
reject(err);
} else {
resolve(stats);
}
});
});
rendererConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
const devServerOptions = Object.assign({}, rendererConfig.devServer, {
stats: {
colors: true,
}
});
WebpackDevServer.addDevServerEntrypoints(rendererConfig, devServerOptions);
const rendererCompiler = webpack(rendererConfig);
const server = new WebpackDevServer(rendererCompiler, devServerOptions);
const serverPromise = new Promise((resolve, reject) => {
let port = 9000;
try {
server.listen(port, "127.0.0.1", resolve(port));
} catch (e) {
reject(e);
}
})
log.info(`Main building...`);
const stats = await mainPromise;
{
const info = stats.toJson();
if (stats.hasErrors()) {
log.error("Main: ", info.errors.join("\n\n"));
process.exit(1);
}
if (stats.hasWarnings()) {
log.warn("Main: ", info.warnings.join("\n\n"));
}
log.info(`Main built!`);
}
log.info(`Renderer building...`)
const electronBinaryPath = require("electron")
log.info(`Will start app with ${electronBinaryPath}`);
const port = await serverPromise;
log.info(`...off content on localhost:${port}`);
await new Promise((resolve, reject) => {
let inspectArg = process.env.ITCH_BREAK === "1" ? "inspect-brk" : "inspect";
const proc = childProcess.spawn(electronBinaryPath, [
".", `--${inspectArg}=9222`, "--color"
], {
env: {
...process.env,
ELECTRON_WEBPACK_WDS_PORT: port,
},
stdio: ['ignore', 'inherit', 'inherit'],
});
log.info(`Should've started the app now...`);
proc.on("close", () => {
log.info(`App closed`);
server.close();
resolve();
})
proc.on("error", (e) => reject(e))
});
}
main();