Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of general
donejs add
.
- Loading branch information
Manuel Mujica
committed
Mar 31, 2016
1 parent
e5a605e
commit 80c956e
Showing
6 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var Q = require('q'); | ||
var runBinary = require('./run-binary'); | ||
|
||
// `donejs add app [folder]` => `donejs-cli init [folder]` | ||
// `donejs add plugin [folder]` => `donejs-cli init [folder] --type=plugin` | ||
// `donejs add generator [name]` => `donejs-cli init [folder] --type=generator` | ||
module.exports = function(type, folder, options) { | ||
if (!isValidType(type)) { | ||
var msg = 'Invalid [type] value `' + type + '`'; | ||
return Q.reject(new Error(msg)); | ||
} | ||
|
||
if (type !== 'app') { | ||
options.type = type; | ||
} | ||
|
||
return runBinary(['init', folder], options); | ||
}; | ||
|
||
function isValidType(type) { | ||
var types = ['app', 'plugin', 'generator']; | ||
return types.indexOf(type) !== -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
var Q = require('q'); | ||
var assert = require('assert'); | ||
var mockery = require('mockery'); | ||
|
||
describe('cmd add test', function() { | ||
var add; | ||
var binaryArgs; | ||
|
||
beforeEach(function() { | ||
var cmdAddPath = '../lib/cli/cmd-add'; | ||
|
||
mockery.enable({ | ||
useCleanCache: true, | ||
warnOnUnregistered: false | ||
}); | ||
|
||
mockery.registerAllowable(cmdAddPath); | ||
|
||
mockery.registerMock('./run-binary', function() { | ||
binaryArgs = arguments; | ||
return Q(true); | ||
}); | ||
|
||
add = require(cmdAddPath); | ||
}); | ||
|
||
afterEach(function() { | ||
mockery.disable(); | ||
mockery.deregisterAll(); | ||
}); | ||
|
||
it('rejects when [type] value is invalid', function(done) { | ||
var folder; | ||
|
||
add('foo', folder, {}) | ||
.then(function() { | ||
assert(false, 'should have failed!'); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
assert(err.message, 'Invalid [type] value `foo`'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('when type is "app", runs binary with the right args', function() { | ||
var folder = 'my-awesome-app'; | ||
|
||
return add('app', folder, {}) | ||
.then(function() { | ||
assert.deepEqual(binaryArgs[0], ['init', folder]); | ||
}); | ||
}); | ||
|
||
it('when type is "plugin", runs binary with the right args', function() { | ||
var folder = 'my-awesome-app'; | ||
|
||
return add('plugin', folder, {}) | ||
.then(function() { | ||
assert.deepEqual(binaryArgs[0], ['init', folder]); | ||
assert.deepEqual(binaryArgs[1].type, 'plugin'); | ||
}); | ||
}); | ||
|
||
it('when type is "generator", runs binary with the right args', function() { | ||
var name = 'donejs-jshint'; | ||
|
||
return add('generator', name, {}) | ||
.then(function() { | ||
assert.deepEqual(binaryArgs[0], ['init', name]); | ||
assert.deepEqual(binaryArgs[1].type, 'generator'); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
require('./run-binary-test'); | ||
require('./cmd-init-test'); | ||
require('./cmd-help-test'); | ||
require('./cmd-add-test'); | ||
|
||
require('./utils-test'); |