Skip to content

Commit 9a8a688

Browse files
wip. refactor
1 parent 201e632 commit 9a8a688

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ module.exports = function(commandName, args = [], customConfig = {}) {
2121

2222
const promise = new Promise((resolve, reject) => {
2323
proc.on('exit', (code) => {
24-
console.log('----runCommand exit------>', code);
25-
code ? reject(code) : resolve(proc);
24+
code ? reject(code) : resolve({ proc });
2625
});
2726

28-
if(config.noExit) {
29-
console.log('----runCommand resolve------>');
30-
resolve(proc);
27+
if(config.detached) {
28+
resolve({ proc });
3129
}
3230
});
3331

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
11
const fs = require('fs');
22
const path = require('path');
33
const WebServer = require('./web-server');
4+
const NextJsServer = require('./nextjs-server');
45

56
const runCommand = require('../src/utility/run-command');
67
const { themes, swatchModes, baseFontFamily } = require('./constants');
78

8-
class nextJsServer {
9-
constructor(env) {
10-
this.proc = null;
11-
this.env = env;
12-
}
13-
14-
async start() {
15-
this.proc = runCommand('npm', ['run', 'start'], {
16-
cwd: this.env.appPath,
17-
noExit: true,
18-
detached: true,
19-
// https://github.com/facebook/create-react-app/issues/3657
20-
env: Object.assign(process.env, { CI: false })
21-
});
22-
23-
await this.proc;
24-
}
25-
26-
stop() {
27-
if(this.proc) {
28-
this.proc.kill();
29-
}
30-
}
31-
}
32-
339
module.exports = class DevServer {
3410
isNextJs() {
3511
return this.env.engine.indexOf('nextjs') === 0;
@@ -38,7 +14,7 @@ module.exports = class DevServer {
3814
constructor(env) {
3915
this.env = env;
4016
this.server = this.isNextJs()
41-
? new nextJsServer(this.env)
17+
? new NextJsServer(this.env)
4218
: new WebServer();
4319
}
4420

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const runCommand = require('../src/utility/run-command');
2+
3+
module.exports = class NextJsServer {
4+
constructor(env) {
5+
this.proc = null;
6+
this.env = env;
7+
}
8+
9+
async start() {
10+
({ proc: this.proc } = await runCommand('npm', ['run', 'start'], {
11+
cwd: this.env.appPath,
12+
detached: true,
13+
// https://github.com/facebook/create-react-app/issues/3657
14+
env: Object.assign(process.env, { CI: false })
15+
}));
16+
}
17+
18+
stop() {
19+
if(this.proc) {
20+
this.proc.kill('SIGTERM');
21+
}
22+
}
23+
};
24+

0 commit comments

Comments
 (0)