ee-bin 4.1.10 → 4.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tools/serve.js CHANGED
@@ -1,346 +1,346 @@
1
- 'use strict';
2
-
3
- const debug = require('debug')('ee-bin:serve');
4
- const path = require('path');
5
- const fsPro = require('fs-extra');
6
- const { loadConfig, isWindows, getArgumentByName, readJsonSync, writeJsonSync } = require('../lib/utils');
7
- const is = require('is-type-of');
8
- const chalk = require('chalk');
9
- const crossSpawn = require('cross-spawn');
10
- const { buildSync } = require('esbuild');
11
- const chokidar = require('chokidar');
12
- const kill = require('tree-kill');
13
- const process = require("process");
14
-
15
- class ServeProcess {
16
-
17
- constructor() {
18
- process.env.NODE_ENV = 'prod'; // dev / prod
19
- this.execProcess = {};
20
- this.electronDir = './electron';
21
- this.bundleDir = './public/electron';
22
- this.pkgPath = './package.json';
23
- this._init();
24
- }
25
-
26
- /**
27
- * init
28
- */
29
- _init() {
30
- // process manager
31
- // Monitor SIGINT signal(Ctrl + C)
32
- process.on('SIGINT', () => {
33
- console.log(chalk.blue('[ee-bin] ') + `Received SIGINT. Closing processes...`);
34
- this._closeProcess();
35
- });
36
-
37
- // Monitor SIGTERM signal
38
- process.on('SIGTERM', () => {
39
- console.log(chalk.blue('[ee-bin] ') + `Received SIGTERM. Closing processes...`);
40
- this._closeProcess();
41
- });
42
- }
43
-
44
- // Close process
45
- async _closeProcess() {
46
- const currentProcess = [];
47
- const keys = Object.keys(this.execProcess);
48
- const len = keys.length;
49
- for (let i = 0; i < len; i++) {
50
- const key = keys[i];
51
- const p = this.execProcess[key];
52
- currentProcess.push({
53
- name: key,
54
- pid: p.pid,
55
- });
56
- }
57
-
58
- // Cleaning work before the end of the process
59
- await this.sleep(500);
60
- currentProcess.forEach((p) => {
61
- kill(p.pid);
62
- debug(`Kill ${chalk.blue(p.name)} server, pid: ${p.pid}`);
63
- });
64
- process.exit(0);
65
- }
66
-
67
- /**
68
- * Start frontend and main process services
69
- */
70
- dev(options = {}) {
71
- // Set an environment variable
72
- process.env.NODE_ENV = 'dev';
73
- const { config, serve } = options;
74
- const binCfg = loadConfig(config);
75
- const binCmd = 'dev';
76
- const binCmdConfig = binCfg[binCmd];
77
-
78
- let command = serve;
79
- if (!command) {
80
- command = Object.keys(binCmdConfig).join();
81
- }
82
- const opt = {
83
- binCmd,
84
- binCmdConfig,
85
- command,
86
- }
87
-
88
- // build electron main code
89
- const cmds = this._formatCmds(command);
90
- if (cmds.indexOf("electron") !== -1) {
91
- const electronConfig = binCmdConfig.electron;
92
-
93
- // Debugging source code
94
- const debugging = getArgumentByName('debuger', electronConfig.args) == 'true'? true : false;
95
- this._switchPkgMain(debugging);
96
-
97
- // watche electron main code
98
- if (electronConfig.watch) {
99
- let debounceTimer = null;
100
- const cmd = 'electron';
101
- const watcher = chokidar.watch([this.electronDir], {
102
- persistent: true
103
- });
104
- watcher.on('change', async (f) => {
105
- //console.log(chalk.blue('[ee-bin] [dev] ') + 'File ' + chalk.cyan(`[${f}]`) + 'has been changed');
106
- console.log(chalk.blue('[ee-bin] [dev] ') + `File [${chalk.cyan(f)}] has been changed`);
107
-
108
- // 防抖
109
- if (debounceTimer) {
110
- clearTimeout(debounceTimer);
111
- }
112
- debounceTimer = setTimeout(async () => {
113
- // rebuild code
114
- console.log(chalk.blue('[ee-bin] [dev] ') + `Restart ${cmd}`);
115
- this.bundle(binCfg.build.electron);
116
- let subPorcess = this.execProcess[cmd];
117
- kill(subPorcess.pid, 'SIGKILL', (err) => {
118
- if (err) {
119
- console.log(chalk.red('[ee-bin] [dev] ') + `Restart failed, error: ${err}`);
120
- process.exit(-1);
121
- }
122
- delete this.execProcess[cmd];
123
-
124
- // restart electron command
125
- let onlyElectronOpt = {
126
- binCmd,
127
- binCmdConfig,
128
- command: cmd,
129
- }
130
- this.multiExec(onlyElectronOpt);
131
- })
132
- }, electronConfig.delay);
133
- });
134
- }
135
-
136
- // When starting for the first time, build the code for the electron directory
137
- this.bundle(binCfg.build.electron);
138
- }
139
-
140
- this.multiExec(opt);
141
- }
142
-
143
- /**
144
- * Start the main process service
145
- */
146
- start(options = {}) {
147
- const { config } = options;
148
- const binCfg = loadConfig(config);
149
- const binCmd = 'start';
150
- const binCmdConfig = {
151
- start: binCfg[binCmd]
152
- };
153
-
154
- const opt = {
155
- binCmd,
156
- binCmdConfig,
157
- command: binCmd,
158
- }
159
- this.multiExec(opt);
160
- }
161
-
162
- sleep(ms) {
163
- return new Promise(resolve => setTimeout(resolve, ms));
164
- }
165
-
166
- /**
167
- * build
168
- */
169
- build(options = {}) {
170
- const { config, env } = options;
171
- let { cmds } = options;
172
- process.env.NODE_ENV = env;
173
- const binCfg = loadConfig(config);
174
- const binCmd = 'build';
175
- const binCmdConfig = binCfg[binCmd];
176
-
177
- if (!cmds || cmds == "") {
178
- const tip = chalk.bgYellow('Warning') + ' Please modify the ' + chalk.blue('build') + ' property in the bin file';
179
- console.log(tip);
180
- return
181
- }
182
-
183
- // [todo] If there is 'electron' , then execute 'electron' first and recycle other commands
184
- // should it be placed in multiExec() and maintain the execution order
185
- const commands = this._formatCmds(cmds);
186
- if (commands.indexOf("electron") !== -1) {
187
- this.bundle(binCmdConfig.electron);
188
- // Remove electron cmd and execute others
189
- const index = commands.indexOf("electron");
190
- commands.splice(index, 1);
191
- cmds = commands.join();
192
-
193
- // switch pkg.main
194
- this._switchPkgMain(false)
195
- }
196
-
197
- const opt = {
198
- binCmd,
199
- binCmdConfig,
200
- command: cmds,
201
- }
202
- this.multiExec(opt);
203
- }
204
-
205
- /**
206
- * Execute custom commands
207
- */
208
- exec(options = {}) {
209
- const { config, cmds } = options;
210
- const binCfg = loadConfig(config);
211
- const binCmd = 'exec';
212
- const binCmdConfig = binCfg[binCmd];
213
-
214
- const opt = {
215
- binCmd,
216
- binCmdConfig,
217
- command: cmds,
218
- }
219
- this.multiExec(opt);
220
- }
221
-
222
- /**
223
- * Support multiple commands
224
- */
225
- multiExec(opt = {}) {
226
- //console.log('multiExec opt:', opt)
227
- const { binCmd, binCmdConfig, command } = opt;
228
- const commands = this._formatCmds(command);
229
-
230
- for (let i = 0; i < commands.length; i++) {
231
- let cmd = commands[i];
232
- const cfg = binCmdConfig[cmd];
233
-
234
- if (!cfg) {
235
- // Running the build electron code separately may be empty
236
- //console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.yellow(`Warning: [${cmd}] config does not exist` ));
237
- continue;
238
- }
239
-
240
- // frontend 如果是 file:// 协议,则不启动
241
- if (binCmd == 'dev' && cmd == 'frontend' && cfg.protocol == 'file://') {
242
- continue;
243
- }
244
-
245
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `Run ${chalk.green(cmd)} command`);
246
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.magenta('Config:'), JSON.stringify(cfg));
247
-
248
- const execDir = path.join(process.cwd(), cfg.directory);
249
- const execArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
250
- const stdio = cfg.stdio ? cfg.stdio: 'inherit';
251
-
252
- const handler = cfg.sync ? crossSpawn.sync : crossSpawn;
253
-
254
- this.execProcess[cmd] = handler(
255
- cfg.cmd,
256
- execArgs,
257
- { stdio: stdio, cwd: execDir, maxBuffer: 1024 * 1024 * 1024 },
258
- );
259
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`${cmd}`) + ` command is ${cfg.sync ? 'run completed' : 'running'}`);
260
-
261
- if(!cfg.sync) {
262
- this.execProcess[cmd].on('exit', () => {
263
- if (binCmd == 'dev') {
264
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `The ${chalk.green(cmd)} process is exiting`);
265
- if (isWindows() && cmd == 'electron') {
266
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('Press "CTRL+C" to exit'));
267
- }
268
- return
269
- }
270
- console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `The ${chalk.green(cmd)} command has been executed and exited`);
271
- });
272
- }
273
- }
274
- }
275
-
276
- // esbuild
277
- bundle(bundleConfig) {
278
- const { bundleType } = bundleConfig;
279
- if (bundleType == 'copy') {
280
- const srcResource = path.join(process.cwd(), this.electronDir);
281
- const destResource = path.join(process.cwd(), this.bundleDir);
282
- fsPro.removeSync(destResource);
283
- fsPro.copySync(srcResource, destResource);
284
- } else {
285
- const esbuildOptions = bundleConfig[bundleConfig.type];
286
- // todo 不压缩
287
- // if (this.isDev()) {
288
- // esbuildOptions.minify = false;
289
- // }
290
- debug('esbuild options:%O', esbuildOptions);
291
- buildSync(esbuildOptions);
292
- }
293
- }
294
-
295
- // format commands
296
- _formatCmds(command) {
297
- let cmds;
298
- const cmdString = command.trim();
299
- if (cmdString.indexOf(',') !== -1) {
300
- cmds = cmdString.split(',');
301
- } else {
302
- cmds = [cmdString];
303
- }
304
-
305
- return cmds;
306
- }
307
-
308
- // Modify the main attribute in package.json
309
- _switchPkgMain(isDebugger = false) {
310
- let mainFile = 'main.js';
311
- const pkgPath = path.join(process.cwd(), this.pkgPath);
312
- const pkg = readJsonSync(pkgPath);
313
- const maints = path.join(process.cwd(), this.electronDir, 'main.ts');
314
- if (fsPro.existsSync(maints)) {
315
- mainFile = 'main.ts'
316
- }
317
-
318
- // [todo] Currently only supports JS
319
- // [todo] Do not use path. join() to ensure consistent performance between Windows and macOS
320
- if (isDebugger && mainFile == 'main.js') {
321
- //pkg.main = path.join(this.electronDir, mainFile);
322
- pkg.main =this.electronDir + '/' + mainFile;
323
- writeJsonSync(pkgPath, pkg);
324
- } else {
325
- // only load main.js file
326
- // const bundleMainPath = path.join(this.bundleDir, 'main.js');
327
- const bundleMainPath = this.bundleDir + '/' + 'main.js';
328
-
329
- // Modify when the path is incorrect to reduce unnecessary operations
330
- if (pkg.main != bundleMainPath) {
331
- pkg.main = bundleMainPath;
332
- writeJsonSync(pkgPath, pkg);
333
- }
334
- }
335
- }
336
-
337
- // env
338
- isDev() {
339
- return process.env.NODE_ENV === 'dev';
340
- }
341
- }
342
-
343
- module.exports = {
344
- ServeProcess,
345
- serveProcess: new ServeProcess()
346
- }
1
+ 'use strict';
2
+
3
+ const debug = require('debug')('ee-bin:serve');
4
+ const path = require('path');
5
+ const fsPro = require('fs-extra');
6
+ const { loadConfig, isWindows, getArgumentByName, readJsonSync, writeJsonSync } = require('../lib/utils');
7
+ const is = require('is-type-of');
8
+ const chalk = require('chalk');
9
+ const crossSpawn = require('cross-spawn');
10
+ const { buildSync } = require('esbuild');
11
+ const chokidar = require('chokidar');
12
+ const kill = require('tree-kill');
13
+ const process = require("process");
14
+
15
+ class ServeProcess {
16
+
17
+ constructor() {
18
+ process.env.NODE_ENV = 'prod'; // dev / prod
19
+ this.execProcess = {};
20
+ this.electronDir = './electron';
21
+ this.bundleDir = './public/electron';
22
+ this.pkgPath = './package.json';
23
+ this._init();
24
+ }
25
+
26
+ /**
27
+ * init
28
+ */
29
+ _init() {
30
+ // process manager
31
+ // Monitor SIGINT signal(Ctrl + C)
32
+ process.on('SIGINT', () => {
33
+ console.log(chalk.blue('[ee-bin] ') + `Received SIGINT. Closing processes...`);
34
+ this._closeProcess();
35
+ });
36
+
37
+ // Monitor SIGTERM signal
38
+ process.on('SIGTERM', () => {
39
+ console.log(chalk.blue('[ee-bin] ') + `Received SIGTERM. Closing processes...`);
40
+ this._closeProcess();
41
+ });
42
+ }
43
+
44
+ // Close process
45
+ async _closeProcess() {
46
+ const currentProcess = [];
47
+ const keys = Object.keys(this.execProcess);
48
+ const len = keys.length;
49
+ for (let i = 0; i < len; i++) {
50
+ const key = keys[i];
51
+ const p = this.execProcess[key];
52
+ currentProcess.push({
53
+ name: key,
54
+ pid: p.pid,
55
+ });
56
+ }
57
+
58
+ // Cleaning work before the end of the process
59
+ await this.sleep(500);
60
+ currentProcess.forEach((p) => {
61
+ kill(p.pid);
62
+ debug(`Kill ${chalk.blue(p.name)} server, pid: ${p.pid}`);
63
+ });
64
+ process.exit(0);
65
+ }
66
+
67
+ /**
68
+ * Start frontend and main process services
69
+ */
70
+ dev(options = {}) {
71
+ // Set an environment variable
72
+ process.env.NODE_ENV = 'dev';
73
+ const { config, serve } = options;
74
+ const binCfg = loadConfig(config);
75
+ const binCmd = 'dev';
76
+ const binCmdConfig = binCfg[binCmd];
77
+
78
+ let command = serve;
79
+ if (!command) {
80
+ command = Object.keys(binCmdConfig).join();
81
+ }
82
+ const opt = {
83
+ binCmd,
84
+ binCmdConfig,
85
+ command,
86
+ }
87
+
88
+ // build electron main code
89
+ const cmds = this._formatCmds(command);
90
+ if (cmds.indexOf("electron") !== -1) {
91
+ const electronConfig = binCmdConfig.electron;
92
+
93
+ // Debugging source code
94
+ const debugging = getArgumentByName('debuger', electronConfig.args) == 'true'? true : false;
95
+ this._switchPkgMain(debugging);
96
+
97
+ // watche electron main code
98
+ if (electronConfig.watch) {
99
+ let debounceTimer = null;
100
+ const cmd = 'electron';
101
+ const watcher = chokidar.watch([this.electronDir], {
102
+ persistent: true
103
+ });
104
+ watcher.on('change', async (f) => {
105
+ //console.log(chalk.blue('[ee-bin] [dev] ') + 'File ' + chalk.cyan(`[${f}]`) + 'has been changed');
106
+ console.log(chalk.blue('[ee-bin] [dev] ') + `File [${chalk.cyan(f)}] has been changed`);
107
+
108
+ // 防抖
109
+ if (debounceTimer) {
110
+ clearTimeout(debounceTimer);
111
+ }
112
+ debounceTimer = setTimeout(async () => {
113
+ // rebuild code
114
+ console.log(chalk.blue('[ee-bin] [dev] ') + `Restart ${cmd}`);
115
+ this.bundle(binCfg.build.electron);
116
+ let subPorcess = this.execProcess[cmd];
117
+ kill(subPorcess.pid, 'SIGKILL', (err) => {
118
+ if (err) {
119
+ console.log(chalk.red('[ee-bin] [dev] ') + `Restart failed, error: ${err}`);
120
+ process.exit(-1);
121
+ }
122
+ delete this.execProcess[cmd];
123
+
124
+ // restart electron command
125
+ let onlyElectronOpt = {
126
+ binCmd,
127
+ binCmdConfig,
128
+ command: cmd,
129
+ }
130
+ this.multiExec(onlyElectronOpt);
131
+ })
132
+ }, electronConfig.delay);
133
+ });
134
+ }
135
+
136
+ // When starting for the first time, build the code for the electron directory
137
+ this.bundle(binCfg.build.electron);
138
+ }
139
+
140
+ this.multiExec(opt);
141
+ }
142
+
143
+ /**
144
+ * Start the main process service
145
+ */
146
+ start(options = {}) {
147
+ const { config } = options;
148
+ const binCfg = loadConfig(config);
149
+ const binCmd = 'start';
150
+ const binCmdConfig = {
151
+ start: binCfg[binCmd]
152
+ };
153
+
154
+ const opt = {
155
+ binCmd,
156
+ binCmdConfig,
157
+ command: binCmd,
158
+ }
159
+ this.multiExec(opt);
160
+ }
161
+
162
+ sleep(ms) {
163
+ return new Promise(resolve => setTimeout(resolve, ms));
164
+ }
165
+
166
+ /**
167
+ * build
168
+ */
169
+ build(options = {}) {
170
+ const { config, env } = options;
171
+ let { cmds } = options;
172
+ process.env.NODE_ENV = env;
173
+ const binCfg = loadConfig(config);
174
+ const binCmd = 'build';
175
+ const binCmdConfig = binCfg[binCmd];
176
+
177
+ if (!cmds || cmds == "") {
178
+ const tip = chalk.bgYellow('Warning') + ' Please modify the ' + chalk.blue('build') + ' property in the bin file';
179
+ console.log(tip);
180
+ return
181
+ }
182
+
183
+ // [todo] If there is 'electron' , then execute 'electron' first and recycle other commands
184
+ // should it be placed in multiExec() and maintain the execution order
185
+ const commands = this._formatCmds(cmds);
186
+ if (commands.indexOf("electron") !== -1) {
187
+ this.bundle(binCmdConfig.electron);
188
+ // Remove electron cmd and execute others
189
+ const index = commands.indexOf("electron");
190
+ commands.splice(index, 1);
191
+ cmds = commands.join();
192
+
193
+ // switch pkg.main
194
+ this._switchPkgMain(false)
195
+ }
196
+
197
+ const opt = {
198
+ binCmd,
199
+ binCmdConfig,
200
+ command: cmds,
201
+ }
202
+ this.multiExec(opt);
203
+ }
204
+
205
+ /**
206
+ * Execute custom commands
207
+ */
208
+ exec(options = {}) {
209
+ const { config, cmds } = options;
210
+ const binCfg = loadConfig(config);
211
+ const binCmd = 'exec';
212
+ const binCmdConfig = binCfg[binCmd];
213
+
214
+ const opt = {
215
+ binCmd,
216
+ binCmdConfig,
217
+ command: cmds,
218
+ }
219
+ this.multiExec(opt);
220
+ }
221
+
222
+ /**
223
+ * Support multiple commands
224
+ */
225
+ multiExec(opt = {}) {
226
+ //console.log('multiExec opt:', opt)
227
+ const { binCmd, binCmdConfig, command } = opt;
228
+ const commands = this._formatCmds(command);
229
+
230
+ for (let i = 0; i < commands.length; i++) {
231
+ let cmd = commands[i];
232
+ const cfg = binCmdConfig[cmd];
233
+
234
+ if (!cfg) {
235
+ // Running the build electron code separately may be empty
236
+ //console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.yellow(`Warning: [${cmd}] config does not exist` ));
237
+ continue;
238
+ }
239
+
240
+ // frontend 如果是 file:// 协议,则不启动
241
+ if (binCmd == 'dev' && cmd == 'frontend' && cfg.protocol == 'file://') {
242
+ continue;
243
+ }
244
+
245
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `Run ${chalk.green(cmd)} command`);
246
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.magenta('Config:'), JSON.stringify(cfg));
247
+
248
+ const execDir = path.join(process.cwd(), cfg.directory);
249
+ const execArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
250
+ const stdio = cfg.stdio ? cfg.stdio: 'inherit';
251
+
252
+ const handler = cfg.sync ? crossSpawn.sync : crossSpawn;
253
+
254
+ this.execProcess[cmd] = handler(
255
+ cfg.cmd,
256
+ execArgs,
257
+ { stdio: stdio, cwd: execDir, maxBuffer: 1024 * 1024 * 1024 },
258
+ );
259
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`${cmd}`) + ` command is ${cfg.sync ? 'run completed' : 'running'}`);
260
+
261
+ if(!cfg.sync) {
262
+ this.execProcess[cmd].on('exit', () => {
263
+ if (binCmd == 'dev') {
264
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `The ${chalk.green(cmd)} process is exiting`);
265
+ if (isWindows() && cmd == 'electron') {
266
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('Press "CTRL+C" to exit'));
267
+ }
268
+ return
269
+ }
270
+ console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + `The ${chalk.green(cmd)} command has been executed and exited`);
271
+ });
272
+ }
273
+ }
274
+ }
275
+
276
+ // esbuild
277
+ bundle(bundleConfig) {
278
+ const { bundleType } = bundleConfig;
279
+ if (bundleType == 'copy') {
280
+ const srcResource = path.join(process.cwd(), this.electronDir);
281
+ const destResource = path.join(process.cwd(), this.bundleDir);
282
+ fsPro.removeSync(destResource);
283
+ fsPro.copySync(srcResource, destResource);
284
+ } else {
285
+ const esbuildOptions = bundleConfig[bundleConfig.type];
286
+ // todo 不压缩
287
+ // if (this.isDev()) {
288
+ // esbuildOptions.minify = false;
289
+ // }
290
+ debug('esbuild options:%O', esbuildOptions);
291
+ buildSync(esbuildOptions);
292
+ }
293
+ }
294
+
295
+ // format commands
296
+ _formatCmds(command) {
297
+ let cmds;
298
+ const cmdString = command.trim();
299
+ if (cmdString.indexOf(',') !== -1) {
300
+ cmds = cmdString.split(',');
301
+ } else {
302
+ cmds = [cmdString];
303
+ }
304
+
305
+ return cmds;
306
+ }
307
+
308
+ // Modify the main attribute in package.json
309
+ _switchPkgMain(isDebugger = false) {
310
+ let mainFile = 'main.js';
311
+ const pkgPath = path.join(process.cwd(), this.pkgPath);
312
+ const pkg = readJsonSync(pkgPath);
313
+ const maints = path.join(process.cwd(), this.electronDir, 'main.ts');
314
+ if (fsPro.existsSync(maints)) {
315
+ mainFile = 'main.ts'
316
+ }
317
+
318
+ // [todo] Currently only supports JS
319
+ // [todo] Do not use path. join() to ensure consistent performance between Windows and macOS
320
+ if (isDebugger && mainFile == 'main.js') {
321
+ //pkg.main = path.join(this.electronDir, mainFile);
322
+ pkg.main =this.electronDir + '/' + mainFile;
323
+ writeJsonSync(pkgPath, pkg);
324
+ } else {
325
+ // only load main.js file
326
+ // const bundleMainPath = path.join(this.bundleDir, 'main.js');
327
+ const bundleMainPath = this.bundleDir + '/' + 'main.js';
328
+
329
+ // Modify when the path is incorrect to reduce unnecessary operations
330
+ if (pkg.main != bundleMainPath) {
331
+ pkg.main = bundleMainPath;
332
+ writeJsonSync(pkgPath, pkg);
333
+ }
334
+ }
335
+ }
336
+
337
+ // env
338
+ isDev() {
339
+ return process.env.NODE_ENV === 'dev';
340
+ }
341
+ }
342
+
343
+ module.exports = {
344
+ ServeProcess,
345
+ serveProcess: new ServeProcess()
346
+ }