@@ -14,18 +14,16 @@ export class TypingsCommand implements ICommand {
14
14
private $projectData : IProjectData ,
15
15
private $mobileHelper : Mobile . IMobileHelper ,
16
16
private $childProcess : IChildProcess ,
17
- private $hostInfo : IHostInfo ,
17
+ private $hostInfo : IHostInfo
18
18
) { }
19
19
20
20
public async execute ( args : string [ ] ) : Promise < void > {
21
21
const platform = args [ 0 ] ;
22
-
22
+ let result ;
23
23
if ( this . $mobileHelper . isAndroidPlatform ( platform ) ) {
24
- await this . handleAndroidTypings ( ) ;
25
- }
26
-
27
- if ( this . $mobileHelper . isiOSPlatform ( platform ) ) {
28
- await this . handleiOSTypings ( ) ;
24
+ result = await this . handleAndroidTypings ( ) ;
25
+ } else if ( this . $mobileHelper . isiOSPlatform ( platform ) ) {
26
+ result = await this . handleiOSTypings ( ) ;
29
27
}
30
28
let typingsFolder = "./typings" ;
31
29
if ( this . $options . copyTo ) {
@@ -35,10 +33,13 @@ export class TypingsCommand implements ICommand {
35
33
) ;
36
34
typingsFolder = this . $options . copyTo ;
37
35
}
38
- this . $logger . info (
39
- "Typings have been generated in the following directory:" ,
40
- typingsFolder
41
- ) ;
36
+
37
+ if ( result !== false ) {
38
+ this . $logger . info (
39
+ "Typings have been generated in the following directory:" ,
40
+ typingsFolder
41
+ ) ;
42
+ }
42
43
}
43
44
44
45
public async canExecute ( args : string [ ] ) : Promise < boolean > {
@@ -48,17 +49,15 @@ export class TypingsCommand implements ICommand {
48
49
}
49
50
50
51
private async handleAndroidTypings ( ) {
51
- if ( this . $options . aar ) {
52
- return this . $logger . warn ( `Open the .aar archive
53
- Extract the classes.jar and any dependencies it may have inside libs/
54
- Rename classes.jar if necessary
55
-
56
- ns typings android --jar classes.jar --jar dependency-of-classes-jar.jar
57
- ` ) ;
58
- } else if ( ! this . $options . jar ) {
59
- return this . $logger . warn (
60
- "No .jar file specified. Please specify a .jar file with --jar <Jar>."
52
+ if ( ! ( this . $options . jar || this . $options . aar ) ) {
53
+ this . $logger . warn (
54
+ [
55
+ "No .jar or .aar file specified. Please specify at least one of the following:" ,
56
+ " - path to .jar file with --jar <jar>" ,
57
+ " - path to .aar file with --aar <aar>" ,
58
+ ] . join ( "\n" )
61
59
) ;
60
+ return false ;
62
61
}
63
62
64
63
this . $fs . ensureDirectoryExists (
@@ -82,25 +81,36 @@ ns typings android --jar classes.jar --jar dependency-of-classes-jar.jar
82
81
) ;
83
82
}
84
83
85
- if ( this . $options . jar ) {
86
- const jars : string [ ] =
87
- typeof this . $options . jar === "string"
88
- ? [ this . $options . jar ]
89
- : this . $options . jar ;
90
- await this . $childProcess . spawnFromEvent (
91
- "java" ,
92
- [
93
- "-jar" ,
94
- dtsGeneratorPath ,
95
- "-input" ,
96
- ...jars ,
97
- "-output" ,
98
- path . resolve ( this . $projectData . projectDir , "typings" , "android" ) ,
99
- ] ,
100
- "exit" ,
101
- { stdio : "inherit" }
102
- ) ;
103
- }
84
+ const asArray = ( input : string | string [ ] ) => {
85
+ if ( ! input ) {
86
+ return [ ] ;
87
+ }
88
+
89
+ if ( typeof input === "string" ) {
90
+ return [ input ] ;
91
+ }
92
+
93
+ return input ;
94
+ } ;
95
+
96
+ const inputs : string [ ] = [
97
+ ...asArray ( this . $options . jar ) ,
98
+ ...asArray ( this . $options . aar ) ,
99
+ ] ;
100
+
101
+ await this . $childProcess . spawnFromEvent (
102
+ "java" ,
103
+ [
104
+ "-jar" ,
105
+ dtsGeneratorPath ,
106
+ "-input" ,
107
+ ...inputs ,
108
+ "-output" ,
109
+ path . resolve ( this . $projectData . projectDir , "typings" , "android" ) ,
110
+ ] ,
111
+ "exit" ,
112
+ { stdio : "inherit" }
113
+ ) ;
104
114
}
105
115
106
116
private async handleiOSTypings ( ) {
0 commit comments