Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 18a0032

Browse files
committedNov 18, 2017
remove process.exit when no callback passed and remove optimist help when in module mode
Fixes #516
1 parent 4de822b commit 18a0032

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed
 

‎api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ function dbmigrate (plugins, isModule, options, callback) {
2424
onComplete: onComplete,
2525
migrationProtocol: 1
2626
};
27+
if (typeof isModule !== 'function') {
28+
this.internals.isModule = isModule;
29+
}
2730
var internals = this.internals;
2831

2932
this.internals.plugins = load('fn/plugin')(plugins);

‎lib/commands/create-migration.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ function executeCreateMigration (internals, config, callback) {
3131

3232
if (internals.argv._.length === 0) {
3333
log.error("'migrationName' is required.");
34-
optimist.showHelp();
35-
process.exit(1);
34+
if (!internals.isModule) {
35+
optimist.showHelp();
36+
}
37+
38+
if (typeof callback !== 'function') {
39+
process.exit(1);
40+
} else {
41+
return callback(new Error("'migrationName' is required."));
42+
}
3643
}
3744

3845
createMigrationDir(migrationsDir, function (err) {
@@ -41,7 +48,11 @@ function executeCreateMigration (internals, config, callback) {
4148

4249
if (err) {
4350
log.error('Failed to create migration directory at ', migrationsDir, err);
44-
process.exit(1);
51+
if (typeof callback !== 'function') {
52+
process.exit(1);
53+
} else {
54+
return callback(new Error('Failed to create migration directory.'));
55+
}
4556
}
4657

4758
internals.argv.title = internals.argv._.shift();
@@ -88,7 +99,7 @@ function executeCreateMigration (internals, config, callback) {
8899
createSqlFiles(internals, config, callback);
89100
} else {
90101
if (typeof callback === 'function') {
91-
callback();
102+
return callback();
92103
}
93104
}
94105
}

0 commit comments

Comments
 (0)
Please sign in to comment.