Skip to content

Commit

Permalink
Merge pull request #9 from carrot/upgrade
Browse files Browse the repository at this point in the history
Upgrade to latest sprout version, swap out bluebird
  • Loading branch information
Jeff Escalante committed Mar 28, 2016
2 parents 60c3bc3 + 6c81df1 commit 735dc66
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 62 deletions.
10 changes: 4 additions & 6 deletions lib/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
12 changes: 5 additions & 7 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
18 changes: 7 additions & 11 deletions lib/commands/list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Promise = require('bluebird')
var W = require('when')
var _ = require('lodash')

module.exports = (function () {
Expand All @@ -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))
8 changes: 3 additions & 5 deletions lib/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
8 changes: 3 additions & 5 deletions lib/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
32 changes: 15 additions & 17 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Promise = require('bluebird')
var W = require('when')
var path = require('path')
var fs = require('fs')
var mkdirp = require('mkdirp')
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ module.exports = (function () {
console.log(chalk.grey('▸ ' + message.toString()))
})

sprout.emitter.on('msg', function (message) {
sprout.on('msg', function (message) {
emitter.emit('msg', message)
})

emitter.on('cmd', function (cmd, cwd) {
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)
})
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
"bugs": "https://github.com/carrot/sprout-cli/issues",
"contributors": [
"Noah Portes Chaikin <[email protected]>",
"Kyle MacDonald <[email protected]>"
"Kyle MacDonald <[email protected]>",
"Jeff Escalante <[email protected]"
],
"dependencies": {
"argparse": "^1.0.2",
"bluebird": "^3.3.4",
"chalk": "^1.0.0",
"inquirer": "^0.12.0",
"lodash": "^4.6.1",
"mkdirp": "^0.5.0",
"osenv": "^0.1.0",
"sprout": "^0.4.1"
"sprout": "^1.0.0",
"when": "^3.7.7"
},
"devDependencies": {
"chai": "^3.5.0",
Expand Down
12 changes: 6 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var fs = require('fs')
var path = require('path')
var rimraf = require('rimraf')
var exec = require('child_process').exec
var Promise = require('bluebird')
var node = require('when/node')

chai.should()

Expand Down Expand Up @@ -286,7 +286,7 @@ describe('commands',
}
).then(
function () {
return InitCommand(cli, {name: 'commands.init.config', target: target, config: path.join(fixture, 'config.json')})
return InitCommand(cli, {name: 'commands.init.config', target: target, configPath: path.join(fixture, 'config.json')})
}
).then(
function () {
Expand Down Expand Up @@ -434,18 +434,18 @@ describe('commands',

describe('helpers',
function () {
describe('isGitURL',
describe('isGitUrl',
function () {
it('should determine is git url',
function (done) {
helpers.isGitURL('[email protected]:foo/bar').should.be.true
helpers.isGitUrl('[email protected]:foo/bar').should.be.true
done()
}
)

it('should determine is not git url',
function (done) {
helpers.isGitURL('asdfadsfasdf').should.be.false
helpers.isGitUrl('asdfadsfasdf').should.be.false
done()
}
)
Expand Down Expand Up @@ -508,5 +508,5 @@ describe('helpers',
*/

var gitInit = function (dir) {
return Promise.promisify(exec)('git init .', { cwd: dir })
return node.call(exec, 'git init .', { cwd: dir })
}

0 comments on commit 735dc66

Please sign in to comment.