Skip to content

Commit

Permalink
Updating version and more ES2015 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
redaktice committed Oct 7, 2020
1 parent cbc1f3e commit 4e7f9df
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 79 deletions.
44 changes: 25 additions & 19 deletions bin/express-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,20 +365,21 @@ function createApplication(name, dir) {

if (dir !== '.') {
console.log();
console.log(' change directory:');
console.log(' %s cd %s', prompt, dir);
console.log(`
change directory:
${prompt} cd ${dir}`);
}

console.log();
console.log(' install dependencies:');
console.log(' %s npm install', prompt);
console.log();
console.log(' run the app:');
console.log(`
install dependencies:
${prompt} npm install
run the app:`);

if (launchedFromCmd()) {
console.log(' %s SET DEBUG=%s:* & npm start', prompt, name);
console.log(` ${prompt} SET DEBUG=${name}:* & npm start'`);
} else {
console.log(' %s DEBUG=%s:* npm start', prompt, name);
console.log(` ${prompt} DEBUG=${name}:* npm start`);
}

console.log();
Expand Down Expand Up @@ -486,10 +487,15 @@ function main() {

// View engine
if (program.view === true) {
if (program.ejs) program.view = 'ejs';
if (program.hbs) program.view = 'hbs';
if (program.hogan) program.view = 'hjs';
if (program.pug) program.view = 'pug';
if (program.ejs) {
program.view = 'ejs';
} else if (program.hbs) {
program.view = 'hbs';
} else if (program.hogan) {
program.view = 'hjs';
} else if (program.pug) {
program.view = 'pug';
}
}

// Default view engine
Expand All @@ -502,7 +508,7 @@ function main() {
}

// Generate application
emptyDirectory(destinationPath, function (empty) {
emptyDirectory(destinationPath, (empty) => {
if (empty || program.force) {
createApplication(appName, destinationPath);
} else {
Expand All @@ -529,7 +535,7 @@ function main() {
function mkdir(base, dir) {
const loc = path.join(base, dir);

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

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

function renamedOption(originalName, newName) {
return function (val) {
return (val) => {
warning(
util.format(
"option `%s' has been renamed to `%s'",
Expand All @@ -561,8 +567,8 @@ function renamedOption(originalName, newName) {

function warning(message) {
console.error();
message.split('\n').forEach(function (line) {
console.error(' warning: %s', line);
message.split('\n').forEach((line) => {
console.error(` warning: ${line}`);
});
console.error();
}
Expand All @@ -576,5 +582,5 @@ function warning(message) {

function write(file, str, mode) {
fs.writeFileSync(file, str, { mode: mode || MODE_0666 });
console.log(' \x1b[36mcreate\x1b[0m : ' + file);
console.log(` \x1b[36mcreate\x1b[0m : ${file}`);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "express-generator",
"description": "Express' application generator",
"version": "4.16.1",
"version": "5.0.0",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"contributors": [
"Aaron Heckmann <aaron.heckmann+github@gmail.com>",
Expand Down
119 changes: 60 additions & 59 deletions test/support/app-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,83 @@ const kill = require('tree-kill');
const net = require('net');
const utils = require('./utils');

module.exports = AppRunner;
class AppRunner {
constructor(dir) {
this.child = null;
this.dir = dir;
this.host = '127.0.0.1';
this.port = 3000;
}
address() {
return { port: this.port };
}

function AppRunner(dir) {
this.child = null;
this.dir = dir;
this.host = '127.0.0.1';
this.port = 3000;
}
start(callback) {
const app = this;
let done = false;
const env = utils.childEnvironment();

AppRunner.prototype.address = function address() {
return { port: this.port };
};
env.PORT = String(app.port);

AppRunner.prototype.start = function start(callback) {
const app = this;
let done = false;
const env = utils.childEnvironment();
this.child = exec('npm start', {
cwd: this.dir,
env: env,
});

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

this.child = exec('npm start', {
cwd: this.dir,
env: env,
});
this.child.on('exit', function onExit(code) {
app.child = null;

this.child.stderr.pipe(process.stderr, { end: false });
if (!done) {
done = true;
callback(new Error('Unexpected app exit with code ' + code));
}
});

this.child.on('exit', function onExit(code) {
app.child = null;
function tryConnect() {
if (done || !app.child) {
return;
}

if (!done) {
done = true;
callback(new Error('Unexpected app exit with code ' + code));
}
});
const socket = net.connect(app.port, app.host);

function tryConnect() {
if (done || !app.child) {
return;
}
socket.on('connect', function onConnect() {
socket.end();

const socket = net.connect(app.port, app.host);
if (!done) {
done = true;
callback(null);
}
});

socket.on('connect', function onConnect() {
socket.end();
socket.on('error', function onError(err) {
socket.destroy();

if (!done) {
done = true;
callback(null);
}
});

socket.on('error', function onError(err) {
socket.destroy();
if (err.syscall !== 'connect') {
return callback(err);
}

if (err.syscall !== 'connect') {
return callback(err);
}
setImmediate(tryConnect);
});
}

setImmediate(tryConnect);
});
setImmediate(tryConnect);
}

setImmediate(tryConnect);
};
stop(callback) {
if (!this.child) {
setImmediate(callback);
return;
}

AppRunner.prototype.stop = function stop(callback) {
if (!this.child) {
setImmediate(callback);
return;
}
this.child.stderr.unpipe();
this.child.removeAllListeners('exit');

this.child.stderr.unpipe();
this.child.removeAllListeners('exit');
kill(this.child.pid, 'SIGTERM', callback);

kill(this.child.pid, 'SIGTERM', callback);
this.child = null;
}
}

this.child = null;
};
module.exports = AppRunner;

0 comments on commit 4e7f9df

Please sign in to comment.