3
3
4
4
import * as os from "os" ;
5
5
import * as osenv from "osenv" ;
6
- import Future = require( "fibers/future" ) ;
7
6
import * as path from "path" ;
8
7
import { quoteString } from "./helpers" ;
9
8
10
9
export class SysInfoBase implements ISysInfo {
11
10
constructor ( protected $childProcess : IChildProcess ,
12
11
protected $hostInfo : IHostInfo ,
13
12
protected $iTunesValidator : Mobile . IiTunesValidator ,
14
- protected $logger : ILogger ) { }
13
+ protected $logger : ILogger ,
14
+ protected $winreg : IWinReg ) { }
15
15
16
- private static monoVerRegExp = / v e r s i o n ( \d + [ . ] \d + [ . ] \d + ) / gm;
16
+ private monoVerRegExp = / v e r s i o n ( \d + [ . ] \d + [ . ] \d + ) / gm;
17
17
private sysInfoCache : ISysInfoData = undefined ;
18
18
19
- public getSysInfo ( androidToolsInfo ?: { pathToAdb : string , pathToAndroid : string } ) : IFuture < ISysInfoData > {
19
+ public getSysInfo ( pathToPackageJson : string , androidToolsInfo ?: { pathToAdb : string , pathToAndroid : string } ) : IFuture < ISysInfoData > {
20
20
return ( ( ) : ISysInfoData => {
21
21
if ( ! this . sysInfoCache ) {
22
22
let res : ISysInfoData = Object . create ( null ) ;
23
23
let procOutput : string ;
24
24
25
- let packageJson = require ( "../../package.json" ) ;
25
+ let packageJson = require ( pathToPackageJson ) ;
26
26
res . procInfo = packageJson . name + "/" + packageJson . version ;
27
27
28
28
// os stuff
@@ -39,7 +39,7 @@ export class SysInfoBase implements ISysInfo {
39
39
res . procArch = process . arch ;
40
40
res . nodeVer = process . version ;
41
41
42
- procOutput = this . $childProcess . exec ( "npm -v" ) . wait ( ) ;
42
+ procOutput = this . exec ( "npm -v" ) ;
43
43
res . npmVer = procOutput ? procOutput . split ( "\n" ) [ 0 ] : null ;
44
44
45
45
// dependencies
@@ -70,7 +70,7 @@ export class SysInfoBase implements ISysInfo {
70
70
71
71
procOutput = this . exec ( "mono --version" ) ;
72
72
if ( ! ! procOutput ) {
73
- let match = SysInfoBase . monoVerRegExp . exec ( procOutput ) ;
73
+ let match = this . monoVerRegExp . exec ( procOutput ) ;
74
74
res . monoVer = match ? match [ 1 ] : null ;
75
75
} else {
76
76
res . monoVer = null ;
@@ -115,30 +115,25 @@ export class SysInfoBase implements ISysInfo {
115
115
}
116
116
117
117
private winVer ( ) : string {
118
- return this . readRegistryValue ( "ProductName" ) . wait ( ) + " " +
119
- this . readRegistryValue ( "CurrentVersion" ) . wait ( ) + "." +
120
- this . readRegistryValue ( "CurrentBuild" ) . wait ( ) ;
118
+ try {
119
+ return this . readRegistryValue ( "ProductName" ) . wait ( ) + " " +
120
+ this . readRegistryValue ( "CurrentVersion" ) . wait ( ) + "." +
121
+ this . readRegistryValue ( "CurrentBuild" ) . wait ( ) ;
122
+ } catch ( err ) {
123
+ this . $logger . trace ( err ) ;
124
+ }
125
+
126
+ return null ;
121
127
}
122
128
123
129
private readRegistryValue ( valueName : string ) : IFuture < string > {
124
- let future = new Future < string > ( ) ;
125
- let Winreg = require ( "winreg" ) ;
126
- let regKey = new Winreg ( {
127
- hive : Winreg . HKLM ,
128
- key : '\\Software\\Microsoft\\Windows NT\\CurrentVersion'
129
- } ) ;
130
- regKey . get ( valueName , ( err : Error , value : any ) => {
131
- if ( err ) {
132
- future . throw ( err ) ;
133
- } else {
134
- future . return ( value . value ) ;
135
- }
136
- } ) ;
137
- return future ;
130
+ return ( ( ) : string => {
131
+ return this . $winreg . getRegistryValue ( valueName , this . $winreg . registryKeys . HKLM , '\\Software\\Microsoft\\Windows NT\\CurrentVersion' ) . wait ( ) . value ;
132
+ } ) . future < string > ( ) ( ) ;
138
133
}
139
134
140
135
private unixVer ( ) : string {
141
- return this . $childProcess . exec ( "uname -a" ) . wait ( ) ;
136
+ return this . exec ( "uname -a" ) ;
142
137
}
143
138
144
139
private getJavaCompilerVersion ( ) : IFuture < string > {
@@ -156,13 +151,15 @@ export class SysInfoBase implements ISysInfo {
156
151
private getCocoapodVersion ( ) : string {
157
152
if ( this . $hostInfo . isDarwin ) {
158
153
let cocoapodVersion = this . exec ( "pod --version" ) ;
159
- // Output of pod --version could contain some warnings. Find the version in it.
160
- let cocoapodVersionMatch = cocoapodVersion . match ( / ^ ( (?: \d + \. ) { 2 } \d + .* ?) $ / gm) ;
161
- if ( cocoapodVersionMatch && cocoapodVersionMatch [ 0 ] ) {
162
- cocoapodVersion = cocoapodVersionMatch [ 0 ] . trim ( ) ;
163
- }
154
+ if ( cocoapodVersion ) {
155
+ // Output of pod --version could contain some warnings. Find the version in it.
156
+ let cocoapodVersionMatch = cocoapodVersion . match ( / ^ ( (?: \d + \. ) { 2 } \d + .* ?) $ / gm) ;
157
+ if ( cocoapodVersionMatch && cocoapodVersionMatch [ 0 ] ) {
158
+ cocoapodVersion = cocoapodVersionMatch [ 0 ] . trim ( ) ;
159
+ }
164
160
165
- return cocoapodVersion ;
161
+ return cocoapodVersion ;
162
+ }
166
163
}
167
164
168
165
return null ;
0 commit comments