Skip to content

Commit

Permalink
[feat] Add debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
icfr committed Sep 22, 2016
1 parent 97180a6 commit d2461a9
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 21 deletions.
12 changes: 10 additions & 2 deletions Commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,16 @@ module.exports = {
})

.catch(function catchError(err) {
console.log(err);
res.prompt();
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();
});

}
Expand Down
2 changes: 2 additions & 0 deletions Commands/laravelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ module.exports = {
})
.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);
}
Expand Down
15 changes: 12 additions & 3 deletions Commands/makeCommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
/* global appdir,Promise */
/* global app,appdir,Promise,bug */

var jsBeautify = require('js-beautify').js_beautify;
var fs = require('fs-promise');
Expand All @@ -25,7 +25,7 @@ var createCommand = function createCommand(cmdName) {
};

module.exports = {
pattern: 'make-commande :command_name',
pattern: 'make-command :command_name',
help: 'Make a commande file',
function: function run(req, res) {
createCommand(req.params.command_name)
Expand All @@ -35,7 +35,16 @@ module.exports = {

})
.catch(function catchError(err) {
console.log(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();
});
}
};
Expand Down
26 changes: 20 additions & 6 deletions Commands/missingJob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
/* global config,appdir,Promise */
global.Queue = require('bee-queue');
/* global config,appdir,Promise,logger,app,bug */
var console = logger(config.core.log.prefix + ':missingJob');
global.Queue = require('../lib/queue');
var jsBeautify = require('js-beautify').js_beautify;
var fs = require('fs-promise');
var each = require('lodash/each');
Expand All @@ -11,6 +12,7 @@ var noJob = [];
var Job;

var getNoJob = function getNoJob(jobs) {
console.debug('collect job not created');
each(jobs, function eachJob(job) {
if (typeof job !== 'string') {
getNoJob(job);
Expand All @@ -22,11 +24,13 @@ var getNoJob = function getNoJob(jobs) {
};

var updateLaravelConf = function updateLaravelConf() {
console.debug('Update laravel config');
return new Promise(function sauvConf(resolve, reject) {
var laravelConfig = config.laravel;
laravelConfig.addToApp.job = merge.recursive(true, laravelConfig.addToApp.job, config.app.job);
fs.writeFile(appdir + '/Config/laravel.js', utils.formatConfig(laravelConfig))
.then(function sauvOk() {
console.debug('config updated');
resolve('config updated');
})
.catch(reject);
Expand Down Expand Up @@ -70,6 +74,7 @@ var createJob = function createJob(jobName) {
jobFile += "module.exports.add = add;\n";

return new Promise(function writeJob(resolve, reject) {
console.debug('write job ', jobName);
fs.writeFile(appdir + '/Jobs/' + jobName + '.js', jsBeautify(jobFile))
.then(function jobCreated() {
resolve(jobName + ' created');
Expand All @@ -87,8 +92,8 @@ module.exports = {
res.yellow('see manual for setup config from laravel').ln();
return res.prompt();
}
if (Object.keys(config.app.job).length === 0) {
res.yellow('no job in Config/app.js');
if (!config.app.job || Object.keys(config.app.job).length === 0) {
res.yellow('no job in Config/app.js').ln();
return res.prompt();
}
global.queueOption = {};
Expand All @@ -107,12 +112,21 @@ module.exports = {
return toWrite;
}).then(function writeJobs(write) {
Promise.all(write).then(function allWriteOk(result) {
console.debug('All write ok');
utils.displayMessage(result, res);
res.prompt();
// res.prompt();
});
}).catch(function allWriteKo(err) {
console.log(err);
console.trace(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();
});

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

module.exports = {
pattern: 'model-creator',
help: 'Create model from database',
Expand All @@ -17,9 +18,14 @@ module.exports = {
res.prompt();

}).catch(function modelCreatorError(err) {
res.red(err);
if (app.config.app.debug) {
res.red(err.stack);
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();
});
Expand Down
10 changes: 7 additions & 3 deletions bootstrap/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
'use strict';
/* global appdir */

/* global appdir,logger */
var include = require('include-all');
module.exports = function config() {
return include({
module.exports = function exportConfig() {
var config = include({
dirname: appdir + '/Config',
filter: /(.+)\.js$/
});
var console = logger(config.core.log.prefix + ':config');
console.debug('config loaded');
return config;
}

18 changes: 15 additions & 3 deletions lib/shell/lib/Shell.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict';
/* global config,logger */
/*eslint no-unused-vars: [2, { "args": "none" }]*/
/*eslint no-process-exit: 0 */
/*eslint no-magic-numbers: 0 */
var EventEmitter, Interface, Request, Response, shell, events, readline, styles;

var console = logger(config.core.log.prefix + ':shell');
readline = require('readline');
events = require('events');
EventEmitter = events.EventEmitter;
var utilsCmd = require('../../utilsCmd');
var utils = require('../../utils');
var util = require('util');
styles = require('./Styles');
Request = require('./Request');
Response = require('./Response');
Expand Down Expand Up @@ -61,6 +63,7 @@ shell = (function exportShell(_super) {
process.on('beforeExit', function beforeExit() {
return self.emit('exit');
});
/* istanbul ignore next */
process.on('uncaughtException', function processUncaughtException(error) {
self.emit('exit', [error]);
self.styles.red().ln();
Expand Down Expand Up @@ -101,7 +104,7 @@ shell = (function exportShell(_super) {
return this;
}

utilsCmd._extends(Shell, _super);
util.inherits(Shell, _super);

Shell.prototype.interface = function shellInterface() {
if (this._interface) {
Expand Down Expand Up @@ -148,6 +151,10 @@ shell = (function exportShell(_super) {
});
index = 0;
next = function runNext(err) {
console.debug('run next');
if (err) {
console.debug('error', typeof err, err);
}
var arity, layer, text;
layer = self.stack[index++];
if (!layer) {
Expand Down Expand Up @@ -180,6 +187,7 @@ shell = (function exportShell(_super) {

Shell.prototype.set = function set(setting, val) {
if (val) {
console.debug('set', setting, 'to', val);
this.settings[setting] = val;
return this;
}
Expand All @@ -193,21 +201,25 @@ shell = (function exportShell(_super) {

Shell.prototype.prompt = function prompt() {
var text;
this.set('prompt_type', 'prompt');

if (this.isShell) {
this.set('prompt_type', 'prompt');
text = this.styles.raw(this.settings.prompt, {
color: 'green'
});
return this.interface().question(text, this.run.bind(this));
}
console.debug('not in shell, exit...');
this.styles.ln();
return this.quit();

};

Shell.prototype.quit = function quit() {

this.emit('quit');
this.interface().close();
console.debug('quit');
return this.settings.stdin.destroy();
};

Expand Down

0 comments on commit d2461a9

Please sign in to comment.