diff --git a/lib/commands/add.js b/lib/commands/add.js index 68320ae..eb54f1d 100644 --- a/lib/commands/add.js +++ b/lib/commands/add.js @@ -9,11 +9,9 @@ module.exports = (function () { */ return function (cli, args) { var name = args.name - var src = helpers.isGitURL(args.src) ? args.src : path.resolve(cli.cwd, args.src) - return cli.sprout.add(name, src).then( - function () { - return cli.emitter.emit('success', 'template `' + name + '` from ' + src + ' added!') - } - ) + var src = helpers.isGitUrl(args.src) ? args.src : path.resolve(cli.cwd, args.src) + return cli.sprout.add(name, src).then(function () { + return cli.emitter.emit('success', 'template `' + name + '` from ' + src + ' added!') + }) } }.call(this)) diff --git a/lib/commands/init.js b/lib/commands/init.js index b24a7c1..7cb6183 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -15,14 +15,12 @@ module.exports = (function () { if (_.isArray(args.locals)) { args.locals = helpers.parseKeyValuesArray(args.locals) } - if (args.config) { - args.config = path.resolve(cli.cwd, args.config) + if (args.configPath) { + args.configPath = path.resolve(cli.cwd, args.configPath) } args.questionnaire = helpers.questionnaire - return cli.sprout.init(name, target, _.omit(args, 'name', 'target')).then( - function () { - return cli.emitter.emit('success', 'template `' + name + '` initialized at ' + target + '!') - } - ) + return cli.sprout.init(name, target, _.omit(args, 'name', 'target')).then(function () { + return cli.emitter.emit('success', 'template `' + name + '` initialized at ' + target + '!') + }) } }.call(this)) diff --git a/lib/commands/list.js b/lib/commands/list.js index 74686fa..1c4407f 100644 --- a/lib/commands/list.js +++ b/lib/commands/list.js @@ -1,4 +1,4 @@ -var Promise = require('bluebird') +var W = require('when') var _ = require('lodash') module.exports = (function () { @@ -8,15 +8,11 @@ module.exports = (function () { */ return function (cli) { - return new Promise( - function (resolve, reject) { - if (_.isEmpty(cli.sprout.templates)) { - cli.emitter.emit('error', new Error('no templates exist!')) - } else { - cli.emitter.emit('list', _.keys(cli.sprout.templates)) - } - return resolve() - } - ) + if (_.isEmpty(cli.sprout.templates)) { + cli.emitter.emit('error', new Error('no templates exist!')) + } else { + cli.emitter.emit('list', _.keys(cli.sprout.templates)) + } + return W.resolve() } }.call(this)) diff --git a/lib/commands/remove.js b/lib/commands/remove.js index 75929a7..5aca56b 100644 --- a/lib/commands/remove.js +++ b/lib/commands/remove.js @@ -7,10 +7,8 @@ module.exports = (function () { return function (cli, args) { var name = args.name - return cli.sprout.remove(name).then( - function () { - return cli.emitter.emit('success', 'template `' + name + '` removed!') - } - ) + return cli.sprout.remove(name).then(function () { + return cli.emitter.emit('success', 'template `' + name + '` removed!') + }) } }.call(this)) diff --git a/lib/commands/run.js b/lib/commands/run.js index fde3308..f57af40 100644 --- a/lib/commands/run.js +++ b/lib/commands/run.js @@ -11,10 +11,8 @@ module.exports = (function () { var name = args.name var generator = args.generator var target = args.target ? path.resolve(cli.cwd, args.target) : cli.cwd - return cli.sprout.run(name, target, generator, args.args).then( - function () { - return cli.emitter.emit('success', 'template `' + name + '` ran generator `' + generator + '` at ' + target + '!') - } - ) + return cli.sprout.run(name, target, generator, args.args).then(function () { + return cli.emitter.emit('success', 'template `' + name + '` ran generator `' + generator + '` at ' + target + '!') + }) } }.call(this)) diff --git a/lib/helpers.js b/lib/helpers.js index 627e82e..415830d 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,4 +1,4 @@ -var Promise = require('bluebird') +var W = require('when') var path = require('path') var fs = require('fs') var mkdirp = require('mkdirp') @@ -31,7 +31,7 @@ exports.sproutPath = function () { * @return {Boolean} - is `str` a git URL */ -exports.isGitURL = function (str) { +exports.isGitUrl = function (str) { return /(?:[A-Za-z0-9]+@|https?:\/\/)[A-Za-z0-9.]+(?::|\/)[A-Za-z0-9\/]+(?:\.git)?/.test(str) } @@ -72,23 +72,21 @@ exports.parseKeyValuesArray = function (arr) { */ exports.questionnaire = function (questions, skip) { - return new Promise( - function (resolve) { - var qs = [] - var question - for (var i = 0; i < questions.length; i++) { - question = questions[i] - if (!_.contains(skip, question.name)) { - qs.push(question) - } + return W.promise(function (resolve) { + var qs = [] + var question + for (var i = 0; i < questions.length; i++) { + question = questions[i] + if (!_.contains(skip, question.name)) { + qs.push(question) } - return inquirer.prompt(qs, - function (answers) { - return resolve(answers) - } - ) } - ) + return inquirer.prompt(qs, + function (answers) { + return resolve(answers) + } + ) + }) } /* A private helper function for determining a diff --git a/lib/index.js b/lib/index.js index 2da63d5..d5b3c82 100644 --- a/lib/index.js +++ b/lib/index.js @@ -48,7 +48,7 @@ module.exports = (function () { console.log(chalk.grey('▸ ' + message.toString())) }) - sprout.emitter.on('msg', function (message) { + sprout.on('msg', function (message) { emitter.emit('msg', message) }) @@ -56,7 +56,7 @@ module.exports = (function () { console.log(chalk.grey('$ ' + cmd.toString() + (cwd ? ' (from ' + cwd + ')' : ''))) }) - sprout.emitter.on('cmd', function (cmd, cwd) { + sprout.on('cmd', function (cmd, cwd) { emitter.emit('cmd', cmd, cwd) }) } diff --git a/package.json b/package.json index 55b45c6..afdc3d7 100644 --- a/package.json +++ b/package.json @@ -9,17 +9,18 @@ "bugs": "https://github.com/carrot/sprout-cli/issues", "contributors": [ "Noah Portes Chaikin ", - "Kyle MacDonald " + "Kyle MacDonald ", + "Jeff Escalante