Skip to content

Commit 9e4af36

Browse files
wip. refactor
1 parent 6ec8fed commit 9e4af36

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

packages/devextreme-cli/src/utility/run-command.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ module.exports = function(commandName, args = [], customConfig = {}) {
2020
const proc = spawn(command, args, config);
2121

2222
const promise = new Promise((resolve, reject) => {
23-
if(!config.noExit) {
24-
proc.on('exit', (code) => {
25-
console.log('----runCommand exit------>', code);
26-
code ? reject(code) : resolve();
27-
});
28-
} else {
29-
console.log('----runCommand resolve------>');
30-
resolve();
31-
}
23+
proc.on('exit', (code) => {
24+
console.log('----runCommand exit------>', code);
25+
code ? reject(code) : resolve(proc);
26+
});
3227
});
3328

3429
promise.kill = (signal = 'SIGTERM') => {

packages/devextreme-cli/testing/dev-server.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,51 @@ const WebServer = require('./web-server');
55
const webServer = new WebServer();
66
const runCommand = require('../src/utility/run-command');
77
const { themes, swatchModes, baseFontFamily } = require('./constants');
8-
let startedPromise = null;
98

10-
module.exports = class DevServer {
11-
constructor(env) {
12-
this.env = env;
9+
class nextJsState {
10+
async start(env) {
11+
this.proc = runCommand('npm', ['run', 'start'], {
12+
cwd: this.env.appPath,
13+
noExit: true,
14+
detached: true,
15+
// https://github.com/facebook/create-react-app/issues/3657
16+
env: Object.assign(process.env, { CI: false })
17+
});
18+
19+
await this.proc;
1320
}
1421

15-
async start() {
16-
if(this.env.engine.indexOf('nextjs') === 0) {
17-
/* if(startedPromise) {
18-
await startedPromise.kill();
19-
} */
22+
stop() {
23+
if(this.proc) {
24+
this.proc.kill();
25+
}
26+
}
27+
}
2028

21-
console.log('-----start----->', this.env.appPath);
29+
module.exports = class DevServer {
30+
isNextJs() {
31+
return this.env.engine.indexOf('nextjs') === 0;
32+
}
2233

23-
startedPromise = runCommand('npm', ['run', 'start'], {
24-
cwd: this.env.appPath,
25-
noExit: true,
26-
detached: true,
27-
// https://github.com/facebook/create-react-app/issues/3657
28-
env: Object.assign(process.env, { CI: false })
29-
});
34+
constructor(env) {
35+
this.env = env;
3036

31-
await startedPromise;
37+
if(this.isNextJs()) {
38+
this.nextJsState = new nextJsState();
39+
}
40+
}
3241

33-
console.log('-----start--runCommand-executed-->');
42+
async start() {
43+
if(this.isNextJs()) {
44+
await this.nextJsState.start();
3445
} else {
3546
await webServer.start(this.env.deployPath);
3647
}
3748
}
3849

3950
async stop() {
40-
if(this.env.engine.indexOf('nextjs') === 0) {
41-
if(startedPromise) {
42-
console.log('----server.stop()------>');
43-
await startedPromise.kill();
44-
startedPromise = null;
45-
}
51+
if(this.isNextJs()) {
52+
await this.nextJsState.stop();
4653
} else {
4754
await webServer.stop();
4855
}

0 commit comments

Comments
 (0)