@@ -158,7 +158,7 @@ function getJson(urlOrPath, callback) {
158158 }
159159 if ( callback ) callback ( sources , urlOrPath ) ;
160160 } else {
161- console . log ( 'Json file not found: ' + urlOrPath ) ;
161+ //if (urlOrPath.indexOf('/example/') == -1) console.log('Json file not found: ' + urlOrPath);
162162 if ( callback ) callback ( null , urlOrPath ) ;
163163 return ;
164164 }
@@ -169,7 +169,10 @@ function getJson(urlOrPath, callback) {
169169// Get list of all installed adapters and controller version on this host
170170function getInstalledInfo ( hostRunningVersion ) {
171171 var result = { } ;
172- var ioPackage = JSON . parse ( fs . readFileSync ( __dirname + '/../io-package.json' ) ) ;
172+ var path = __dirname + '/../' ;
173+ // Get info about host
174+ var ioPackage = JSON . parse ( fs . readFileSync ( path + 'io-package.json' ) ) ;
175+ var package = fs . existsSync ( path + 'package.json' ) ? JSON . parse ( fs . readFileSync ( path + 'package.json' ) ) : { } ;
173176 result [ ioPackage . common . name ] = {
174177 controller : true ,
175178 version : ioPackage . common . version ,
@@ -179,13 +182,17 @@ function getInstalledInfo(hostRunningVersion) {
179182 platform : ioPackage . common . platform ,
180183 keywords : ioPackage . common . keywords ,
181184 readme : ioPackage . common . readme ,
182- runningVersion : hostRunningVersion
185+ runningVersion : hostRunningVersion ,
186+ license : ioPackage . common . license ? ioPackage . common . license : ( ( package . licenses && package . licenses . length ) ? package . licenses [ 0 ] . type : '' ) ,
187+ licenseUrl : ( package . licenses && package . licenses . length ) ? package . licenses [ 0 ] . url : ''
183188 } ;
184189 var dirs = fs . readdirSync ( __dirname + '/../adapter' ) ;
185190 for ( var i = 0 ; i < dirs . length ; i ++ ) {
186191 try {
187- if ( fs . existsSync ( __dirname + '/../adapter/' + dirs [ i ] + '/io-package.json' ) ) {
188- ioPackage = JSON . parse ( fs . readFileSync ( __dirname + '/../adapter/' + dirs [ i ] + '/io-package.json' ) ) ;
192+ path = __dirname + '/../adapter/' + dirs [ i ] + '/' ;
193+ if ( fs . existsSync ( path + 'io-package.json' ) ) {
194+ ioPackage = JSON . parse ( fs . readFileSync ( path + 'io-package.json' ) ) ;
195+ package = fs . existsSync ( path + 'package.json' ) ? JSON . parse ( fs . readFileSync ( path + 'package.json' ) ) : { } ;
189196 result [ ioPackage . common . name ] = {
190197 controller : false ,
191198 version : ioPackage . common . version ,
@@ -195,8 +202,9 @@ function getInstalledInfo(hostRunningVersion) {
195202 platform : ioPackage . common . platform ,
196203 keywords : ioPackage . common . keywords ,
197204 readme : ioPackage . common . readme ,
198- license : ioPackage . common . license ,
199- type : ioPackage . common . type
205+ type : ioPackage . common . type ,
206+ license : ioPackage . common . license ? ioPackage . common . license : ( ( package . licenses && package . licenses . length ) ? package . licenses [ 0 ] . type : '' ) ,
207+ licenseUrl : ( package . licenses && package . licenses . length ) ? package . licenses [ 0 ] . url : ''
200208 } ;
201209 }
202210 } catch ( e ) {
@@ -206,8 +214,10 @@ function getInstalledInfo(hostRunningVersion) {
206214 dirs = fs . readdirSync ( __dirname + '/../node_modules' ) ;
207215 for ( i = 0 ; i < dirs . length ; i ++ ) {
208216 try {
209- if ( dirs [ i ] . match ( / ^ i o b r o k e r \. / i) && fs . existsSync ( __dirname + '/../node_modules/' + dirs [ i ] + '/io-package.json' ) ) {
210- ioPackage = JSON . parse ( fs . readFileSync ( __dirname + '/../node_modules/' + dirs [ i ] + '/io-package.json' ) ) ;
217+ path = __dirname + '/../node_modules/' + dirs [ i ] + '/' ;
218+ if ( dirs [ i ] . match ( / ^ i o b r o k e r \. / i) && fs . existsSync ( path + 'io-package.json' ) ) {
219+ ioPackage = JSON . parse ( fs . readFileSync ( path + 'io-package.json' ) ) ;
220+ package = fs . existsSync ( path + 'package.json' ) ? JSON . parse ( fs . readFileSync ( path + 'package.json' ) ) : { } ;
211221 result [ ioPackage . common . name ] = {
212222 controller : false ,
213223 version : ioPackage . common . version ,
@@ -217,7 +227,9 @@ function getInstalledInfo(hostRunningVersion) {
217227 platform : ioPackage . common . platform ,
218228 keywords : ioPackage . common . keywords ,
219229 readme : ioPackage . common . readme ,
220- type : ioPackage . common . type
230+ type : ioPackage . common . type ,
231+ license : ioPackage . common . license ? ioPackage . common . license : ( ( package . licenses && package . licenses . length ) ? package . licenses [ 0 ] . type : '' ) ,
232+ licenseUrl : ( package . licenses && package . licenses . length ) ? package . licenses [ 0 ] . url : ''
221233 } ;
222234 }
223235 } catch ( e ) {
@@ -229,9 +241,11 @@ function getInstalledInfo(hostRunningVersion) {
229241 dirs = fs . readdirSync ( __dirname + '/../..' ) ;
230242 for ( i = 0 ; i < dirs . length ; i ++ ) {
231243 try {
244+ path = __dirname + '/../../' + dirs [ i ] + '/' ;
232245 if ( dirs [ i ] . match ( / ^ i o b r o k e r \. / i) && dirs [ i ] . substring ( 'iobroker.' . length ) != 'js-controller' &&
233- fs . existsSync ( __dirname + '/../../' + dirs [ i ] + '/io-package.json' ) ) {
234- ioPackage = JSON . parse ( fs . readFileSync ( __dirname + '/../../' + dirs [ i ] + '/io-package.json' ) ) ;
246+ fs . existsSync ( path + 'io-package.json' ) ) {
247+ ioPackage = JSON . parse ( fs . readFileSync ( path + 'io-package.json' ) ) ;
248+ package = fs . existsSync ( path + 'package.json' ) ? JSON . parse ( fs . readFileSync ( path + 'package.json' ) ) : { } ;
235249 result [ ioPackage . common . name ] = {
236250 controller : false ,
237251 version : ioPackage . common . version ,
@@ -240,7 +254,9 @@ function getInstalledInfo(hostRunningVersion) {
240254 desc : ioPackage . common . desc ,
241255 platform : ioPackage . common . platform ,
242256 keywords : ioPackage . common . keywords ,
243- readme : ioPackage . common . readme
257+ readme : ioPackage . common . readme ,
258+ license : ioPackage . common . license ? ioPackage . common . license : ( ( package . licenses && package . licenses . length ) ? package . licenses [ 0 ] . type : '' ) ,
259+ licenseUrl : ( package . licenses && package . licenses . length ) ? package . licenses [ 0 ] . url : ''
244260 } ;
245261 }
246262 } catch ( e ) {
@@ -320,26 +336,41 @@ function getNpmVersion(adapter, callback) {
320336
321337function getIoPack ( sources , name , callback ) {
322338 getJson ( sources [ name ] . meta , function ( ioPack ) {
323- // If installed from git or something else
324- // js-controller is exception, because can be installed from npm and from git
325- if ( sources [ name ] . url && name != 'js-controller' ) {
326- if ( ioPack && ioPack . common ) sources [ name ] = extend ( true , sources [ name ] , ioPack . common ) ;
339+ var packUrl = sources [ name ] . meta . replace ( 'io-package.json' , 'package.json' ) ;
340+ getJson ( packUrl , function ( pack ) {
341+ // If installed from git or something else
342+ // js-controller is exception, because can be installed from npm and from git
343+ if ( sources [ name ] . url && name != 'js-controller' ) {
344+ if ( ioPack && ioPack . common ) {
345+ sources [ name ] = extend ( true , sources [ name ] , ioPack . common ) ;
346+ if ( pack && pack . licenses && pack . licenses . length ) {
347+ if ( ! sources [ name ] . license ) sources [ name ] . license = pack . licenses [ 0 ] . type ;
348+ if ( ! sources [ name ] . licenseUrl ) sources [ name ] . licenseUrl = pack . licenses [ 0 ] . url ;
349+ }
350+ }
327351
328- if ( callback ) callback ( sources , name ) ;
329- } else {
330- if ( ioPack && ioPack . common ) sources [ name ] = extend ( true , sources [ name ] , ioPack . common ) ;
352+ if ( callback ) callback ( sources , name ) ;
353+ } else {
354+ if ( ioPack && ioPack . common ) {
355+ sources [ name ] = extend ( true , sources [ name ] , ioPack . common ) ;
356+ if ( pack && pack . licenses && pack . licenses . length ) {
357+ if ( ! sources [ name ] . license ) sources [ name ] . license = pack . licenses [ 0 ] . type ;
358+ if ( ! sources [ name ] . licenseUrl ) sources [ name ] . licenseUrl = pack . licenses [ 0 ] . url ;
359+ }
360+ }
331361
332- if ( sources [ name ] . meta . substring ( 0 , 'http://' . length ) == 'http://' ||
333- sources [ name ] . meta . substring ( 0 , 'https://' . length ) == 'https://' ) {
334- //installed from npm
335- getNpmVersion ( name , function ( err , version ) {
336- if ( version ) sources [ name ] . version = version ;
362+ if ( sources [ name ] . meta . substring ( 0 , 'http://' . length ) == 'http://' ||
363+ sources [ name ] . meta . substring ( 0 , 'https://' . length ) == 'https://' ) {
364+ //installed from npm
365+ getNpmVersion ( name , function ( err , version ) {
366+ if ( version ) sources [ name ] . version = version ;
367+ if ( callback ) callback ( sources , name ) ;
368+ } ) ;
369+ } else {
337370 if ( callback ) callback ( sources , name ) ;
338- } ) ;
339- } else {
340- if ( callback ) callback ( sources , name ) ;
371+ }
341372 }
342- }
373+ } ) ;
343374 } ) ;
344375}
345376
0 commit comments