Skip to content

Commit

Permalink
[fix] Remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
icfr committed Sep 22, 2016
1 parent 3f73836 commit 0f38d18
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ engines:
languages:
javascript:
mass_threshold: 70
exclude_paths:
- test/
eslint:
enabled: true
channel: eslint-2
Expand All @@ -18,3 +20,4 @@ ratings:
- "**.js"
exclude_paths:
- node_modules/
- test/data/
13 changes: 2 additions & 11 deletions Commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,8 @@ module.exports = {

})

.catch(function catchError(err) {
res.red(err.message).ln();
/* istanbul ignore if*/
if (typeof app.config.app !== "undefined" && app.config.app.debug) {
res.red(err.stack.replace(err.message, ''));
}
/* istanbul ignore if*/
if (bug) {
bug.captureException(err);
}
res.prompt();
.catch(function catchError(error) {
utils.displayError(error, res);
});

}
Expand Down
15 changes: 3 additions & 12 deletions Commands/laravelConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
/* global app,appdir,bug */
/* global app,appdir */
/* eslint global-require: 0 */
var Promise = require('bluebird');
var shelljs = require('shelljs');
Expand Down Expand Up @@ -232,17 +232,8 @@ module.exports = {
utils.displayMessage(result, res);
res.prompt();
})
.catch(function laravelConfigError(err) {
res.red(err.message).ln();
/* istanbul ignore if*/
if (typeof app.config.app !== "undefined" && app.config.app.debug) {
res.red(err.stack.replace(err.message, ''));
}
/* istanbul ignore if*/
if (bug) {
bug.captureException(err);
}
res.prompt();
.catch(function catchError(error) {
utils.displayError(error, res);
});
}
};
Expand Down
16 changes: 4 additions & 12 deletions Commands/makeCommand.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
/* global app,appdir,Promise,bug */
/* global appdir,Promise */

var jsBeautify = require('js-beautify').js_beautify;
var fs = require('fs-promise');
var utils = require('../lib/utilsCmd');

var createCommand = function createCommand(cmdName) {
return new Promise(function promiseCreateCommand(resolve, reject) {
Expand Down Expand Up @@ -34,17 +35,8 @@ module.exports = {
res.prompt();

})
.catch(function catchError(err) {
res.red(err.message).ln();
/* istanbul ignore if*/
if (typeof app.config.app !== "undefined" && app.config.app.debug) {
res.red(err.stack.replace(err.message, ''));
}
/* istanbul ignore if*/
if (bug) {
bug.captureException(err);
}
res.prompt();
.catch(function catchError(error) {
utils.displayError(error, res);
});
}
};
Expand Down
15 changes: 3 additions & 12 deletions Commands/missingJob.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
/* global config,appdir,Promise,logger,app,bug */
/* global config,appdir,Promise,logger */
var console = logger(config.core.log.prefix + ':missingJob');
global.Queue = require('../lib/queue');
var jsBeautify = require('js-beautify').js_beautify;
Expand Down Expand Up @@ -117,17 +117,8 @@ module.exports = {
res.prompt();
// res.prompt();
});
}).catch(function allWriteKo(err) {
res.red(err.message).ln();
/* istanbul ignore if*/
if (typeof app.config.app !== "undefined" && app.config.app.debug) {
res.red(err.stack.replace(err.message, ''));
}
/* istanbul ignore if*/
if (bug) {
bug.captureException(err);
}
res.prompt();
}).catch(function catchError(error) {
utils.displayError(error, res);
});

}
Expand Down
15 changes: 3 additions & 12 deletions Commands/modelsCreator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
/* global app,bug */
/* global app */
/* eslint global-require: 0 */
var utils = require('../lib/utilsCmd');

Expand All @@ -17,17 +17,8 @@ module.exports = {
utils.displayMessage(result, res);
res.prompt();

}).catch(function modelCreatorError(err) {
res.red(err.message).ln();
/* istanbul ignore if*/
if (typeof app.config.app !== "undefined" && app.config.app.debug) {
res.red(err.stack.replace(err.message, ''));
}
/* istanbul ignore if*/
if (bug) {
bug.captureException(err);
}
res.prompt();
}).catch(function catchError(error) {
utils.displayError(error, res);
});

}
Expand Down
14 changes: 14 additions & 0 deletions lib/utilsCmd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';
/* global app,bug */
/* eslint no-invalid-this:0*/

var jsBeautify = require('js-beautify').js_beautify;
var each = require('lodash/each');

Expand Down Expand Up @@ -30,6 +32,18 @@ module.exports = {
each(result, function eachMessage(message) {
res.green(message).ln();
});
},
displayError: function catchError(err, res) {
res.red(err.message).ln();
/* istanbul ignore if*/
if (typeof app.config.app !== "undefined" && app.config.app.debug) {
res.red(err.stack.replace(err.message, ''));
}
/* istanbul ignore if*/
if (bug) {
bug.captureException(err);
}
res.prompt();
}
};

0 comments on commit 0f38d18

Please sign in to comment.