@@ -16,6 +16,15 @@ class AndroidProjectService implements IPlatformProjectService {
1616 private $projectData : IProjectData ,
1717 private $propertiesParser : IPropertiesParser ) { }
1818
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+
1928 public validate ( ) : IFuture < void > {
2029 return ( ( ) => {
2130 this . validatePackageName ( this . $projectData . projectId ) ;
@@ -61,54 +70,49 @@ class AndroidProjectService implements IPlatformProjectService {
6170 } ) . future < void > ( ) ( ) ;
6271 }
6372
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 > ( ) ( ) ;
6879 }
6980
70- public prepareProject ( normalizedPlatformName : string , platforms : string [ ] ) : IFuture < void > {
81+ public prepareProject ( platformData : IPlatformData ) : IFuture < string > {
7182 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 ) ;
7688
89+ var appResourcesDirectoryPath = path . join ( assetsDirectory , constants . APP_FOLDER_NAME , constants . APP_RESOURCES_FOLDER_NAME ) ;
7790 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 ) ;
7992 this . $fs . deleteDirectory ( appResourcesDirectoryPath ) . wait ( ) ;
8093 }
8194
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 ) ;
8496
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 > ( ) ( ) ;
9598 }
9699
97100 public buildProject ( projectRoot : string ) : IFuture < void > {
98101 return ( ( ) => {
99102 var buildConfiguration = options . release ? "release" : "debug" ;
100103 var args = this . getAntArgs ( buildConfiguration , projectRoot ) ;
101- this . spawn ( 'ant' , args ) ;
104+ this . spawn ( 'ant' , args ) . wait ( ) ;
102105 } ) . future < void > ( ) ( ) ;
103106 }
104107
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 ( ) ) {
107110 args . unshift ( '/s' , '/c' , command ) ;
108111 command = 'cmd' ;
109112 }
110113
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" ) ;
112116 }
113117
114118 private getAntArgs ( configuration : string , projectRoot : string ) : string [ ] {
@@ -123,7 +127,7 @@ class AndroidProjectService implements IPlatformProjectService {
123127 "--target" , targetApi
124128 ] ;
125129
126- this . spawn ( "android update project" , args ) ;
130+ this . spawn ( "android" , [ ' update' , 'project' ] . concat ( args ) ) . wait ( ) ;
127131 } ) . future < void > ( ) ( ) ;
128132 }
129133
@@ -208,17 +212,5 @@ class AndroidProjectService implements IPlatformProjectService {
208212 }
209213 } ) . future < void > ( ) ( ) ;
210214 }
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- }
223215}
224216$injector . register ( "androidProjectService" , AndroidProjectService ) ;
0 commit comments