@@ -16,6 +16,15 @@ class AndroidProjectService implements IPlatformProjectService {
16
16
private $projectData : IProjectData ,
17
17
private $propertiesParser : IPropertiesParser ) { }
18
18
19
+ public get platformData ( ) : IPlatformData {
20
+ return {
21
+ frameworkPackageName : "tns-android" ,
22
+ normalizedPlatformName : "Android" ,
23
+ platformProjectService : this ,
24
+ projectRoot : path . join ( this . $projectData . platformsDir , "android" )
25
+ } ;
26
+ }
27
+
19
28
public validate ( ) : IFuture < void > {
20
29
return ( ( ) => {
21
30
this . validatePackageName ( this . $projectData . projectId ) ;
@@ -61,54 +70,49 @@ class AndroidProjectService implements IPlatformProjectService {
61
70
} ) . future < void > ( ) ( ) ;
62
71
}
63
72
64
- public afterCreateProject ( projectRoot : string ) {
65
- var targetApi = this . getTarget ( projectRoot ) . wait ( ) ;
66
- this . $logger . trace ( "Android target: %s" , targetApi ) ;
67
- this . runAndroidUpdate ( projectRoot , targetApi ) . wait ( ) ;
73
+ public afterCreateProject ( projectRoot : string ) : IFuture < void > {
74
+ return ( ( ) => {
75
+ var targetApi = this . getTarget ( projectRoot ) . wait ( ) ;
76
+ this . $logger . trace ( "Android target: %s" , targetApi ) ;
77
+ this . runAndroidUpdate ( projectRoot , targetApi ) . wait ( ) ;
78
+ } ) . future < void > ( ) ( ) ;
68
79
}
69
80
70
- public prepareProject ( normalizedPlatformName : string , platforms : string [ ] ) : IFuture < void > {
81
+ public prepareProject ( platformData : IPlatformData ) : IFuture < string > {
71
82
return ( ( ) => {
72
- var platform = normalizedPlatformName . toLowerCase ( ) ;
73
- var assetsDirectoryPath = path . join ( this . $projectData . platformsDir , platform , "assets" ) ;
74
- var appResourcesDirectoryPath = path . join ( assetsDirectoryPath , constants . APP_FOLDER_NAME , constants . APP_RESOURCES_FOLDER_NAME ) ;
75
- shell . cp ( "-r" , path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) , assetsDirectoryPath ) ;
83
+ var appSourceDirectory = path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ;
84
+ var assetsDirectory = path . join ( platformData . projectRoot , "assets" ) ;
85
+ var resDirectory = path . join ( platformData . projectRoot , "res" ) ;
86
+
87
+ shell . cp ( "-r" , appSourceDirectory , assetsDirectory ) ;
76
88
89
+ var appResourcesDirectoryPath = path . join ( assetsDirectory , constants . APP_FOLDER_NAME , constants . APP_RESOURCES_FOLDER_NAME ) ;
77
90
if ( this . $fs . exists ( appResourcesDirectoryPath ) . wait ( ) ) {
78
- shell . cp ( "-r" , path . join ( appResourcesDirectoryPath , normalizedPlatformName , "*" ) , path . join ( this . $projectData . platformsDir , platform , "res" ) ) ;
91
+ shell . cp ( "-r" , path . join ( appResourcesDirectoryPath , platformData . normalizedPlatformName , "*" ) , resDirectory ) ;
79
92
this . $fs . deleteDirectory ( appResourcesDirectoryPath ) . wait ( ) ;
80
93
}
81
94
82
- var files = helpers . enumerateFilesInDirectorySync ( path . join ( assetsDirectoryPath , constants . APP_FOLDER_NAME ) ) ;
83
- var platformsAsString = platforms . join ( "|" ) ;
95
+ return path . join ( assetsDirectory , constants . APP_FOLDER_NAME ) ;
84
96
85
- _ . each ( files , fileName => {
86
- var platformInfo = AndroidProjectService . parsePlatformSpecificFileName ( path . basename ( fileName ) , platformsAsString ) ;
87
- var shouldExcludeFile = platformInfo && platformInfo . platform !== platform ;
88
- if ( shouldExcludeFile ) {
89
- this . $fs . deleteFile ( fileName ) . wait ( ) ;
90
- } else if ( platformInfo && platformInfo . onDeviceName ) {
91
- this . $fs . rename ( fileName , path . join ( path . dirname ( fileName ) , platformInfo . onDeviceName ) ) . wait ( ) ;
92
- }
93
- } ) ;
94
- } ) . future < void > ( ) ( ) ;
97
+ } ) . future < string > ( ) ( ) ;
95
98
}
96
99
97
100
public buildProject ( projectRoot : string ) : IFuture < void > {
98
101
return ( ( ) => {
99
102
var buildConfiguration = options . release ? "release" : "debug" ;
100
103
var args = this . getAntArgs ( buildConfiguration , projectRoot ) ;
101
- this . spawn ( 'ant' , args ) ;
104
+ this . spawn ( 'ant' , args ) . wait ( ) ;
102
105
} ) . future < void > ( ) ( ) ;
103
106
}
104
107
105
- private spawn ( command : string , args : string [ ] , options ?: any ) : void {
106
- if ( helpers . isWindows ( ) ) {
108
+ private spawn ( command : string , args : string [ ] ) : IFuture < void > {
109
+ if ( helpers . isWindows ( ) ) {
107
110
args . unshift ( '/s' , '/c' , command ) ;
108
111
command = 'cmd' ;
109
112
}
110
113
111
- this . $childProcess . spawn ( command , args , { cwd : options , stdio : 'inherit' } ) ;
114
+ var child = this . $childProcess . spawn ( command , args , { stdio : "inherit" } ) ;
115
+ return this . $fs . futureFromEvent ( child , "close" ) ;
112
116
}
113
117
114
118
private getAntArgs ( configuration : string , projectRoot : string ) : string [ ] {
@@ -123,7 +127,7 @@ class AndroidProjectService implements IPlatformProjectService {
123
127
"--target" , targetApi
124
128
] ;
125
129
126
- this . spawn ( "android update project" , args ) ;
130
+ this . spawn ( "android" , [ ' update' , 'project' ] . concat ( args ) ) . wait ( ) ;
127
131
} ) . future < void > ( ) ( ) ;
128
132
}
129
133
@@ -208,17 +212,5 @@ class AndroidProjectService implements IPlatformProjectService {
208
212
}
209
213
} ) . future < void > ( ) ( ) ;
210
214
}
211
-
212
- private static parsePlatformSpecificFileName ( fileName : string , platforms : string ) : any {
213
- var regex = util . format ( "^(.+?)\.(%s)(\..+?)$" , platforms ) ;
214
- var parsed = fileName . toLowerCase ( ) . match ( new RegExp ( regex , "i" ) ) ;
215
- if ( parsed ) {
216
- return {
217
- platform : parsed [ 2 ] ,
218
- onDeviceName : parsed [ 1 ] + parsed [ 3 ]
219
- } ;
220
- }
221
- return undefined ;
222
- }
223
215
}
224
216
$injector . register ( "androidProjectService" , AndroidProjectService ) ;
0 commit comments