Skip to content

Commit 4e7f9df

Browse files
author
redaktice
committed
Updating version and more ES2015 conversion
1 parent cbc1f3e commit 4e7f9df

File tree

3 files changed

+86
-79
lines changed

3 files changed

+86
-79
lines changed

bin/express-cli.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -365,20 +365,21 @@ function createApplication(name, dir) {
365365

366366
if (dir !== '.') {
367367
console.log();
368-
console.log(' change directory:');
369-
console.log(' %s cd %s', prompt, dir);
368+
console.log(`
369+
change directory:
370+
${prompt} cd ${dir}`);
370371
}
371372

372-
console.log();
373-
console.log(' install dependencies:');
374-
console.log(' %s npm install', prompt);
375-
console.log();
376-
console.log(' run the app:');
373+
console.log(`
374+
install dependencies:
375+
${prompt} npm install
376+
377+
run the app:`);
377378

378379
if (launchedFromCmd()) {
379-
console.log(' %s SET DEBUG=%s:* & npm start', prompt, name);
380+
console.log(` ${prompt} SET DEBUG=${name}:* & npm start'`);
380381
} else {
381-
console.log(' %s DEBUG=%s:* npm start', prompt, name);
382+
console.log(` ${prompt} DEBUG=${name}:* npm start`);
382383
}
383384

384385
console.log();
@@ -486,10 +487,15 @@ function main() {
486487

487488
// View engine
488489
if (program.view === true) {
489-
if (program.ejs) program.view = 'ejs';
490-
if (program.hbs) program.view = 'hbs';
491-
if (program.hogan) program.view = 'hjs';
492-
if (program.pug) program.view = 'pug';
490+
if (program.ejs) {
491+
program.view = 'ejs';
492+
} else if (program.hbs) {
493+
program.view = 'hbs';
494+
} else if (program.hogan) {
495+
program.view = 'hjs';
496+
} else if (program.pug) {
497+
program.view = 'pug';
498+
}
493499
}
494500

495501
// Default view engine
@@ -502,7 +508,7 @@ function main() {
502508
}
503509

504510
// Generate application
505-
emptyDirectory(destinationPath, function (empty) {
511+
emptyDirectory(destinationPath, (empty) => {
506512
if (empty || program.force) {
507513
createApplication(appName, destinationPath);
508514
} else {
@@ -529,7 +535,7 @@ function main() {
529535
function mkdir(base, dir) {
530536
const loc = path.join(base, dir);
531537

532-
console.log(' \x1b[36mcreate\x1b[0m : ' + loc + path.sep);
538+
console.log(` \x1b[36mcreate\x1b[0m : ${loc}${path.sep}`);
533539
mkdirp.sync(loc, MODE_0755);
534540
}
535541

@@ -541,7 +547,7 @@ function mkdir(base, dir) {
541547
*/
542548

543549
function renamedOption(originalName, newName) {
544-
return function (val) {
550+
return (val) => {
545551
warning(
546552
util.format(
547553
"option `%s' has been renamed to `%s'",
@@ -561,8 +567,8 @@ function renamedOption(originalName, newName) {
561567

562568
function warning(message) {
563569
console.error();
564-
message.split('\n').forEach(function (line) {
565-
console.error(' warning: %s', line);
570+
message.split('\n').forEach((line) => {
571+
console.error(` warning: ${line}`);
566572
});
567573
console.error();
568574
}
@@ -576,5 +582,5 @@ function warning(message) {
576582

577583
function write(file, str, mode) {
578584
fs.writeFileSync(file, str, { mode: mode || MODE_0666 });
579-
console.log(' \x1b[36mcreate\x1b[0m : ' + file);
585+
console.log(` \x1b[36mcreate\x1b[0m : ${file}`);
580586
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "express-generator",
33
"description": "Express' application generator",
4-
"version": "4.16.1",
4+
"version": "5.0.0",
55
"author": "TJ Holowaychuk <tj@vision-media.ca>",
66
"contributors": [
77
"Aaron Heckmann <aaron.heckmann+github@gmail.com>",

test/support/app-runner.js

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,83 @@ const kill = require('tree-kill');
55
const net = require('net');
66
const utils = require('./utils');
77

8-
module.exports = AppRunner;
8+
class AppRunner {
9+
constructor(dir) {
10+
this.child = null;
11+
this.dir = dir;
12+
this.host = '127.0.0.1';
13+
this.port = 3000;
14+
}
15+
address() {
16+
return { port: this.port };
17+
}
918

10-
function AppRunner(dir) {
11-
this.child = null;
12-
this.dir = dir;
13-
this.host = '127.0.0.1';
14-
this.port = 3000;
15-
}
19+
start(callback) {
20+
const app = this;
21+
let done = false;
22+
const env = utils.childEnvironment();
1623

17-
AppRunner.prototype.address = function address() {
18-
return { port: this.port };
19-
};
24+
env.PORT = String(app.port);
2025

21-
AppRunner.prototype.start = function start(callback) {
22-
const app = this;
23-
let done = false;
24-
const env = utils.childEnvironment();
26+
this.child = exec('npm start', {
27+
cwd: this.dir,
28+
env: env,
29+
});
2530

26-
env.PORT = String(app.port);
31+
this.child.stderr.pipe(process.stderr, { end: false });
2732

28-
this.child = exec('npm start', {
29-
cwd: this.dir,
30-
env: env,
31-
});
33+
this.child.on('exit', function onExit(code) {
34+
app.child = null;
3235

33-
this.child.stderr.pipe(process.stderr, { end: false });
36+
if (!done) {
37+
done = true;
38+
callback(new Error('Unexpected app exit with code ' + code));
39+
}
40+
});
3441

35-
this.child.on('exit', function onExit(code) {
36-
app.child = null;
42+
function tryConnect() {
43+
if (done || !app.child) {
44+
return;
45+
}
3746

38-
if (!done) {
39-
done = true;
40-
callback(new Error('Unexpected app exit with code ' + code));
41-
}
42-
});
47+
const socket = net.connect(app.port, app.host);
4348

44-
function tryConnect() {
45-
if (done || !app.child) {
46-
return;
47-
}
49+
socket.on('connect', function onConnect() {
50+
socket.end();
4851

49-
const socket = net.connect(app.port, app.host);
52+
if (!done) {
53+
done = true;
54+
callback(null);
55+
}
56+
});
5057

51-
socket.on('connect', function onConnect() {
52-
socket.end();
58+
socket.on('error', function onError(err) {
59+
socket.destroy();
5360

54-
if (!done) {
55-
done = true;
56-
callback(null);
57-
}
58-
});
59-
60-
socket.on('error', function onError(err) {
61-
socket.destroy();
61+
if (err.syscall !== 'connect') {
62+
return callback(err);
63+
}
6264

63-
if (err.syscall !== 'connect') {
64-
return callback(err);
65-
}
65+
setImmediate(tryConnect);
66+
});
67+
}
6668

67-
setImmediate(tryConnect);
68-
});
69+
setImmediate(tryConnect);
6970
}
7071

71-
setImmediate(tryConnect);
72-
};
72+
stop(callback) {
73+
if (!this.child) {
74+
setImmediate(callback);
75+
return;
76+
}
7377

74-
AppRunner.prototype.stop = function stop(callback) {
75-
if (!this.child) {
76-
setImmediate(callback);
77-
return;
78-
}
78+
this.child.stderr.unpipe();
79+
this.child.removeAllListeners('exit');
7980

80-
this.child.stderr.unpipe();
81-
this.child.removeAllListeners('exit');
81+
kill(this.child.pid, 'SIGTERM', callback);
8282

83-
kill(this.child.pid, 'SIGTERM', callback);
83+
this.child = null;
84+
}
85+
}
8486

85-
this.child = null;
86-
};
87+
module.exports = AppRunner;

0 commit comments

Comments
 (0)