Skip to content

Commit

Permalink
Merge pull request #227 from braydonf/add-cmd-remote
Browse files Browse the repository at this point in the history
Bitcore Node Add Command with Remote URLS
  • Loading branch information
pnagurny committed Sep 16, 2015
2 parents 948f36d + 25e8011 commit aa9504a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/scaffold/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ function add(options, done) {
);
}

var oldPackage = JSON.parse(fs.readFileSync(packagePath));

async.eachSeries(
services,
function(service, next) {
Expand All @@ -95,12 +97,18 @@ function add(options, done) {
return next(err);
}

// TODO: get the name of the package from the updated package.json
// to be able to support other types of installation such as
// hosted git urls
// get the name of the service from package.json
var updatedPackage = JSON.parse(fs.readFileSync(packagePath));
var newDependencies = _.difference(
Object.keys(updatedPackage.dependencies),
Object.keys(oldPackage.dependencies)
);
$.checkState(newDependencies.length === 1);
oldPackage = updatedPackage;
var serviceName = newDependencies[0];

// add service to bitcore-node.json
addConfig(bitcoreConfigPath, service, next);
addConfig(bitcoreConfigPath, serviceName, next);
});
}, done
);
Expand Down
20 changes: 20 additions & 0 deletions test/scaffold/add.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ describe('#add', function() {
});

it('will update bitcore-node.json services', function(done) {
var callCount = 0;
var oldPackage = {
dependencies: {
'bitcore': '^v0.13.1',
'bitcore-node': '^v0.2.0'
}
};
var spawn = sinon.stub().returns({
stdout: {
on: sinon.stub()
Expand All @@ -103,6 +110,19 @@ describe('#add', function() {
var addtest = proxyquire('../../lib/scaffold/add', {
'child_process': {
spawn: spawn
},
'fs': {
readFileSync: function() {
if (callCount === 1){
oldPackage.dependencies.a = '^v0.1';
} else if (callCount === 2){
oldPackage.dependencies.b = '^v0.1';
} else if (callCount === 3){
oldPackage.dependencies.c = '^v0.1';
}
callCount++;
return JSON.stringify(oldPackage);
}
}
});
addtest({
Expand Down

0 comments on commit aa9504a

Please sign in to comment.