File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ function add(options, done) {
86
86
) ;
87
87
}
88
88
89
+ var oldPackage = JSON . parse ( fs . readFileSync ( packagePath ) ) ;
90
+
89
91
async . eachSeries (
90
92
services ,
91
93
function ( service , next ) {
@@ -95,12 +97,18 @@ function add(options, done) {
95
97
return next ( err ) ;
96
98
}
97
99
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 ] ;
101
109
102
110
// add service to bitcore-node.json
103
- addConfig ( bitcoreConfigPath , service , next ) ;
111
+ addConfig ( bitcoreConfigPath , serviceName , next ) ;
104
112
} ) ;
105
113
} , done
106
114
) ;
Original file line number Diff line number Diff line change @@ -91,6 +91,13 @@ describe('#add', function() {
91
91
} ) ;
92
92
93
93
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
+ } ;
94
101
var spawn = sinon . stub ( ) . returns ( {
95
102
stdout : {
96
103
on : sinon . stub ( )
@@ -103,6 +110,19 @@ describe('#add', function() {
103
110
var addtest = proxyquire ( '../../lib/scaffold/add' , {
104
111
'child_process' : {
105
112
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
+ }
106
126
}
107
127
} ) ;
108
128
addtest ( {
You can’t perform that action at this time.
0 commit comments