File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ function add(options, done) {
8686 ) ;
8787 }
8888
89+ var oldPackage = JSON . parse ( fs . readFileSync ( packagePath ) ) ;
90+
8991 async . eachSeries (
9092 services ,
9193 function ( service , next ) {
@@ -95,12 +97,18 @@ function add(options, done) {
9597 return next ( err ) ;
9698 }
9799
98- // TODO: get the name of the package from the updated package.json
99- // to be able to support other types of installation such as
100- // hosted git urls
100+ // get the name of the service from package.json
101+ var updatedPackage = JSON . parse ( fs . readFileSync ( packagePath ) ) ;
102+ var newDependencies = _ . difference (
103+ Object . keys ( updatedPackage . dependencies ) ,
104+ Object . keys ( oldPackage . dependencies )
105+ ) ;
106+ $ . checkState ( newDependencies . length === 1 ) ;
107+ oldPackage = updatedPackage ;
108+ var serviceName = newDependencies [ 0 ] ;
101109
102110 // add service to bitcore-node.json
103- addConfig ( bitcoreConfigPath , service , next ) ;
111+ addConfig ( bitcoreConfigPath , serviceName , next ) ;
104112 } ) ;
105113 } , done
106114 ) ;
Original file line number Diff line number Diff line change @@ -91,6 +91,13 @@ describe('#add', function() {
9191 } ) ;
9292
9393 it ( 'will update bitcore-node.json services' , function ( done ) {
94+ var callCount = 0 ;
95+ var oldPackage = {
96+ dependencies : {
97+ 'bitcore' : '^v0.13.1' ,
98+ 'bitcore-node' : '^v0.2.0'
99+ }
100+ } ;
94101 var spawn = sinon . stub ( ) . returns ( {
95102 stdout : {
96103 on : sinon . stub ( )
@@ -103,6 +110,19 @@ describe('#add', function() {
103110 var addtest = proxyquire ( '../../lib/scaffold/add' , {
104111 'child_process' : {
105112 spawn : spawn
113+ } ,
114+ 'fs' : {
115+ readFileSync : function ( ) {
116+ if ( callCount === 1 ) {
117+ oldPackage . dependencies . a = '^v0.1' ;
118+ } else if ( callCount === 2 ) {
119+ oldPackage . dependencies . b = '^v0.1' ;
120+ } else if ( callCount === 3 ) {
121+ oldPackage . dependencies . c = '^v0.1' ;
122+ }
123+ callCount ++ ;
124+ return JSON . stringify ( oldPackage ) ;
125+ }
106126 }
107127 } ) ;
108128 addtest ( {
You can’t perform that action at this time.
0 commit comments