process.exit() with proper statusCode

One thing to take into account when making command lines
is to exit with the proper code so that grunt-tasks works as expected
when failing.
This commit is contained in:
vvo 2014-01-14 15:47:42 +01:00
parent 17fcaf4019
commit 05efb708d1

View File

@ -25,8 +25,8 @@ module.exports = function(commands) {
log.join('\n').cyan); log.join('\n').cyan);
} }
}) })
.catch(logError) .catch(failure)
.finally(exit); .then(success);
}; };
commands['migrate:latest'].help = 'runs migrations that have not run yet'; commands['migrate:latest'].help = 'runs migrations that have not run yet';
@ -39,8 +39,8 @@ module.exports = function(commands) {
}).then(function(filename) { }).then(function(filename) {
console.log(('Migration ' + filename + ' created!').green); console.log(('Migration ' + filename + ' created!').green);
}) })
.catch(logError) .catch(failure)
.finally(exit); .then(success);
}; };
commands['migrate:make'].help = 'generates a new migration'; commands['migrate:make'].help = 'generates a new migration';
@ -57,8 +57,8 @@ module.exports = function(commands) {
log.join('\n').cyan); log.join('\n').cyan);
} }
}) })
.catch(logError) .catch(failure)
.finally(exit); .then(success);
}; };
commands['migrate:rollback'].help = 'rolls back the latest migration group'; commands['migrate:rollback'].help = 'rolls back the latest migration group';
@ -70,8 +70,8 @@ module.exports = function(commands) {
.then(function(version) { .then(function(version) {
console.log('Current Version: '.green + version.blue); console.log('Current Version: '.green + version.blue);
}) })
.catch(logError) .catch(failure)
.finally(exit); .then(success);
}; };
}; };
@ -112,9 +112,15 @@ var err = function(msg) {
console.error(msg.red); console.error(msg.red);
}; };
var exit = function() { var exit = function(statusCode) {
if (knex && knex.client) { if (knex && knex.client) {
knex.client.pool.destroy(); knex.client.pool.destroy();
} }
process.exit(); process.exit(statusCode);
}; };
var success = _.partial(exit, 0);
var failure = function(err) {
logError(err);
exit(1);
}