hoodie-cli
Advanced tools
Comparing version 0.4.10 to 0.4.11
@@ -5,12 +5,21 @@ /*global module:false*/ | ||
"use strict"; | ||
'use strict'; | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-simple-mocha'); | ||
require('load-grunt-tasks')(grunt); | ||
// Project configuration. | ||
grunt.initConfig({ | ||
bump: { | ||
options: { | ||
commitMessage: 'chore(release): v%VERSION%', | ||
files: ['package.json'], | ||
commitFiles: [ | ||
'package.json', | ||
'CHANGELOG.md' | ||
], | ||
pushTo: 'origin master' | ||
} | ||
}, | ||
jshint: { | ||
@@ -43,6 +52,20 @@ files: [ | ||
grunt.registerTask('release', function() { | ||
// Forward arguments to the bump-only task | ||
this.args.unshift('bump-only'); | ||
grunt.task.run([ | ||
'test', | ||
this.args.join(':'), | ||
'changelog', | ||
'bump-commit' | ||
]); | ||
}); | ||
// Default task. | ||
grunt.registerTask('default', ['jshint', 'simplemocha:full']); | ||
grunt.registerTask('test', ['jshint', 'simplemocha:full']); | ||
grunt.registerTask('default', ['test']); | ||
}; |
@@ -108,6 +108,8 @@ var Command = require('./util/command'); | ||
async.map(pluginsArr, function (p, cb) { | ||
var pluginName = p.trim(); | ||
if (pluginName.match('hoodie-plugin-')) { | ||
pluginName = pluginName.split('-')[2]; | ||
pluginName = pluginName.replace('hoodie-plugin-', ''); | ||
} | ||
@@ -114,0 +116,0 @@ |
@@ -19,2 +19,5 @@ var Command = require('./util/command'); | ||
function appDir(options) { | ||
return path.join(options.cwd, options.name); | ||
} | ||
@@ -41,14 +44,15 @@ // | ||
// defaults, defaults, heaps of defaults | ||
var originalTmpl = options.template || 'my-first-hoodie'; | ||
var customTmpl = options.template; | ||
delete options.template; | ||
var defaultTmpl = 'my-first-hoodie'; | ||
if (!options.name) { | ||
options.name = 'my-first-hoodie'; | ||
options.name = defaultTmpl; | ||
} | ||
options.template = { | ||
template: originalTmpl, | ||
template: customTmpl || defaultTmpl, | ||
entity: 'hoodiehq', | ||
repo: 'my-first-hoodie', | ||
repo: defaultTmpl, | ||
branch: undefined, | ||
@@ -58,13 +62,16 @@ uri: undefined | ||
if (originalTmpl.match('/')) { | ||
if (customTmpl) { | ||
var slug = customTmpl.split('/'); | ||
if (!!originalTmpl.split('/')) { | ||
options.template.entity = originalTmpl.split('/')[0]; | ||
options.template.repo = originalTmpl.split('/')[1].split('#')[0]; | ||
if (customTmpl.indexOf('/') < 0 || slug.length > 2) { | ||
this.hoodie.emit('err', 'The provided template "' + customTmpl + '" is not a valid GitHub slug.'); | ||
return callback(new Error()); | ||
} | ||
if (!!originalTmpl.split('#')[1]) { | ||
options.template.branch = originalTmpl.split('#')[1]; | ||
} | ||
options.template.entity = slug[0]; | ||
slug = slug[1].split('#'); | ||
options.template.repo = slug[0]; | ||
options.template.branch = slug[1]; | ||
} | ||
@@ -101,4 +108,2 @@ | ||
options.rmArg = options.cacheDir + options.template.repo + '/.git'; | ||
// optional callback | ||
@@ -150,4 +155,30 @@ callback = callback || function() {}; | ||
// | ||
// Copy template directory to target location. | ||
// | ||
Command.prototype.copyToCwd = function (options, ctx, callback) { | ||
var self = ctx; | ||
var srcDir = options.cacheDir + options.template.repo; | ||
var targetDir = appDir(options); | ||
try { | ||
shell.mkdir('-p', path.dirname(targetDir)); | ||
} catch(e) { | ||
self.hoodie.emit('err', 'directory already exists'); | ||
return callback(new Error()); | ||
} | ||
try { | ||
self.hoodie.emit('info', 'preparing ' + options.name + ' ...'); | ||
shell.cp('-R', srcDir + '/.', targetDir); | ||
} catch(err) { | ||
callback(err); | ||
return; | ||
} | ||
callback(null); | ||
}; | ||
// | ||
@@ -162,3 +193,4 @@ // cleanup after 'git clone' - removes .git folder. | ||
rmrf(options.rmArg, function(err) { | ||
var dotGit = appDir(options) + '/.git'; | ||
rmrf(dotGit, function(err) { | ||
@@ -187,6 +219,7 @@ if (err) { | ||
process.chdir(options.cacheDir + options.template.repo); | ||
process.chdir(appDir(options)); | ||
// Replace {{hoodie_appname}} in package.json and www/index.html | ||
var readFile = function(file) { | ||
return fs.readFileSync(file) | ||
@@ -200,6 +233,6 @@ .toString() | ||
}; | ||
var files = [ | ||
'package.json', | ||
'./www/index.html' | ||
path.normalize('./www/index.html') | ||
]; | ||
@@ -217,3 +250,2 @@ | ||
// | ||
@@ -226,3 +258,3 @@ // Install npm dependencies | ||
process.chdir(options.cacheDir + options.template.repo); | ||
process.chdir(appDir(options)); | ||
@@ -248,33 +280,3 @@ self.hoodie.emit('info', 'fetching npm dependencies'); | ||
// | ||
// Move template to cwd. | ||
// | ||
Command.prototype.copyToCwd = function (options, ctx, callback) { | ||
var self = ctx; | ||
var srcDir = options.cacheDir + options.template.repo + '/'; | ||
var targetDir = options.cwd + '/' + options.name + '/'; | ||
try { | ||
shell.mkdir('-p', path.dirname(targetDir)); | ||
} catch(e) { | ||
self.hoodie.emit('err', 'directory already exists'); | ||
return callback(new Error()); | ||
} | ||
try { | ||
self.hoodie.emit('info', 'preparing ' + options.name + ' ...'); | ||
shell.cp('-R', srcDir + '/.', targetDir); | ||
} catch(err) { | ||
callback(err); | ||
return; | ||
} | ||
callback(null); | ||
}; | ||
// | ||
// Execute. | ||
@@ -289,6 +291,6 @@ // | ||
self.fetch, | ||
self.copyToCwd, | ||
self.cleanup, | ||
self.rename, | ||
self.deps, | ||
self.copyToCwd | ||
self.deps | ||
], options, self, function (err) { | ||
@@ -298,12 +300,12 @@ | ||
var errStr = '\nSomething\'s wrong here...\n'; | ||
errStr += '\n'; | ||
errStr += 'Try running the following commands to resolve possible issues:\n'; | ||
errStr += '\n'; | ||
errStr += ' hoodie cache clean\n'; | ||
errStr += '\n'; | ||
errStr += ' npm cache clean\n'; | ||
errStr += '\n'; | ||
errStr += 'If none of the above works, run \"hoodie new ' + options.name + ' --verbose\"\n'; | ||
errStr += 'and come talk to us on freenode #hoodie \n'; | ||
var errStr = '\nSomething\'s wrong here...\n' + | ||
'\n' + | ||
'Try running the following commands to resolve possible issues:\n' + | ||
'\n' + | ||
' hoodie cache clean\n' + | ||
'\n' + | ||
' npm cache clean\n' + | ||
'\n' + | ||
'If none of the above works, run \"hoodie new ' + options.name + ' --verbose\"\n' + | ||
'and come talk to us on freenode #hoodie \n'; | ||
@@ -315,9 +317,9 @@ self.hoodie.emit('error', errStr); | ||
self.hoodie.emit('info', 'created project at', options.cwd + '/' + options.name + '/'); | ||
self.hoodie.emit('info', 'created project at', path.join(options.cwd, options.name)); | ||
var sucStr = 'Installed all dependencies\n'; | ||
sucStr += '\nYou can now start using your hoodie app\n'; | ||
sucStr += '\n'; | ||
sucStr += ' cd ' + options.name + '\n'; | ||
sucStr += ' hoodie start\n'; | ||
var sucStr = 'Installed all dependencies\n' + | ||
'\nYou can now start using your hoodie app\n' + | ||
'\n' + | ||
' cd ' + options.name + '\n' + | ||
' hoodie start\n'; | ||
@@ -330,3 +332,2 @@ self.hoodie.emit('info', sucStr); | ||
module.exports = { | ||
@@ -333,0 +334,0 @@ exec: function (hoodie) { |
var Command = require('./util/command'); | ||
var util = require('util'); | ||
var fs = require('fs'); | ||
var ini = require('ini'); | ||
var path = require('path'); | ||
var util = require('util'); | ||
@@ -51,3 +53,3 @@ | ||
var self = this; | ||
var couchIniPath = process.cwd() + '/data/couch.ini'; | ||
var couchIniPath = path.join(process.cwd(), 'data/couch.ini'); | ||
var config = ini.parse(fs.readFileSync(couchIniPath, 'utf-8')); | ||
@@ -54,0 +56,0 @@ |
@@ -33,6 +33,6 @@ var Command = require('./util/command'); | ||
var info = 'Version: ' + pkg.version; | ||
info += ' (node ' + process.version; | ||
info += ', npm ' + npmversion; | ||
info += ', platform: ' + process.platform + ')\n'; | ||
var info = 'Version: ' + pkg.version + | ||
' (node ' + process.version + | ||
', npm ' + npmversion + | ||
', platform: ' + process.platform + ')\n'; | ||
@@ -39,0 +39,0 @@ console.log(info); |
{ | ||
"name": "hoodie-cli", | ||
"description": "Hoodie command-line interface.", | ||
"version": "0.4.10", | ||
"version": "0.4.11", | ||
"preferGlobal": true, | ||
@@ -52,4 +52,7 @@ "dependencies": { | ||
"sinon": "~1.7.3", | ||
"grunt-simple-mocha": "~0.4.0" | ||
"grunt-simple-mocha": "~0.4.0", | ||
"load-grunt-tasks": "^0.4.0", | ||
"grunt-conventional-changelog": "^1.1.0", | ||
"grunt-bump": "0.0.13" | ||
} | ||
} |
@@ -69,2 +69,10 @@ var hoodie = require('../../lib/main'); | ||
describe('$ hoodie install hoodie-plugin-users', function() { | ||
it('should try to install a plugin', function() { | ||
cli.argv({ _: ['install', 'hoodie-plugin-users'] }); | ||
args.plugins = 'hoodie-plugin-users'; | ||
expect(hoodie.install.calledWith(args)).to.be.ok(); | ||
}); | ||
}); | ||
describe('$ hoodie install --plugin users', function() { | ||
@@ -71,0 +79,0 @@ it('should try to install a plugin', function() { |
@@ -52,4 +52,24 @@ var Hoodie = require('../../lib/hoodie'); | ||
}); | ||
describe('rejected invalid slug', function() { | ||
it('should trigger callback with an error', function() { | ||
options.template = '50/yo-dawg/i-heard-yo-like#some-test'; | ||
hoodie.new(options, function(e) { | ||
expect(e instanceof Error).to.be(true); | ||
}); | ||
options.template = 'yo-dawg'; | ||
hoodie.new(options, function(e) { | ||
expect(e instanceof Error).to.be(true); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
84535
67
2366
10