diff --git a/Commands/init.js b/Commands/init.js index 1ea0ae9..71c019f 100644 --- a/Commands/init.js +++ b/Commands/init.js @@ -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(); }); } diff --git a/Commands/laravelConfig.js b/Commands/laravelConfig.js index 49ea96d..60bc928 100644 --- a/Commands/laravelConfig.js +++ b/Commands/laravelConfig.js @@ -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); } diff --git a/Commands/makeCommand.js b/Commands/makeCommand.js index 6698003..9098b8e 100644 --- a/Commands/makeCommand.js +++ b/Commands/makeCommand.js @@ -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'); @@ -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) @@ -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(); }); } }; diff --git a/Commands/missingJob.js b/Commands/missingJob.js index 977278c..bebb3e0 100644 --- a/Commands/missingJob.js +++ b/Commands/missingJob.js @@ -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'); @@ -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); @@ -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); @@ -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'); @@ -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 = {}; @@ -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(); }); diff --git a/Commands/modelsCreator.js b/Commands/modelsCreator.js index 0cb71c6..c993986 100644 --- a/Commands/modelsCreator.js +++ b/Commands/modelsCreator.js @@ -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', @@ -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(); }); diff --git a/bootstrap/config.js b/bootstrap/config.js index 92852ef..3e12f51 100644 --- a/bootstrap/config.js +++ b/bootstrap/config.js @@ -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; } diff --git a/lib/shell/lib/Shell.js b/lib/shell/lib/Shell.js index 3a64a1f..bceb56a 100644 --- a/lib/shell/lib/Shell.js +++ b/lib/shell/lib/Shell.js @@ -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'); @@ -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(); @@ -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) { @@ -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) { @@ -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; } @@ -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(); };