@@ -5,6 +5,7 @@ import shell = require("shelljs");
5
5
import util = require( "util" ) ;
6
6
import constants = require( "./../constants" ) ;
7
7
import helpers = require( "./../common/helpers" ) ;
8
+ import options = require( "./../options" ) ;
8
9
9
10
class PlatformsData implements IPlatformsData {
10
11
private platformsData : { [ index : string ] : any } = { } ;
@@ -34,7 +35,8 @@ export class PlatformService implements IPlatformService {
34
35
private $logger : ILogger ,
35
36
private $npm : INodePackageManager ,
36
37
private $projectData : IProjectData ,
37
- private $platformsData : IPlatformsData ) { }
38
+ private $platformsData : IPlatformsData ,
39
+ private $devicesServices : Mobile . IDevicesServices ) { }
38
40
39
41
public addPlatforms ( platforms : string [ ] ) : IFuture < void > {
40
42
return ( ( ) => {
@@ -138,17 +140,9 @@ export class PlatformService implements IPlatformService {
138
140
var platformProjectService = platformData . platformProjectService ;
139
141
140
142
var appFilesLocation = platformProjectService . prepareProject ( platformData ) . wait ( ) ;
141
- var files = helpers . enumerateFilesInDirectorySync ( appFilesLocation ) ;
142
143
143
- _ . each ( files , fileName => {
144
- var platformInfo = PlatformService . parsePlatformSpecificFileName ( path . basename ( fileName ) , this . $platformsData . platformsNames ) ;
145
- var shouldExcludeFile = platformInfo && platformInfo . platform !== platform ;
146
- if ( shouldExcludeFile ) {
147
- this . $fs . deleteFile ( fileName ) . wait ( ) ;
148
- } else if ( platformInfo && platformInfo . onDeviceName ) {
149
- this . $fs . rename ( fileName , path . join ( path . dirname ( fileName ) , platformInfo . onDeviceName ) ) . wait ( ) ;
150
- }
151
- } ) ;
144
+ this . processPlatformSpecificFiles ( platform , helpers . enumerateFilesInDirectorySync ( path . join ( appFilesLocation , constants . APP_FOLDER_NAME ) ) ) . wait ( ) ;
145
+ this . processPlatformSpecificFiles ( platform , helpers . enumerateFilesInDirectorySync ( path . join ( appFilesLocation , constants . TNS_MODULES_FOLDER_NAME ) ) ) . wait ( ) ;
152
146
153
147
} ) . future < void > ( ) ( ) ;
154
148
}
@@ -170,7 +164,14 @@ export class PlatformService implements IPlatformService {
170
164
platform = platform . toLowerCase ( ) ;
171
165
172
166
this . preparePlatform ( platform ) . wait ( ) ;
167
+
168
+ // We need to set device option here
169
+ var cachedDeviceOption = options . device ;
170
+ options . device = true ;
173
171
this . buildPlatform ( platform ) . wait ( ) ;
172
+ options . device = cachedDeviceOption ;
173
+
174
+ this . deploy ( platform ) . wait ( ) ;
174
175
} ) . future < void > ( ) ( ) ;
175
176
}
176
177
@@ -190,6 +191,44 @@ export class PlatformService implements IPlatformService {
190
191
} ) . future < void > ( ) ( ) ;
191
192
}
192
193
194
+ public deploy ( platform : string ) : IFuture < void > {
195
+ return ( ( ) => {
196
+ platform = platform . toLowerCase ( ) ;
197
+
198
+ this . validatePlatformInstalled ( platform ) ;
199
+
200
+ var platformData = this . $platformsData . getPlatformData ( platform ) ;
201
+
202
+ // Get latest package that is produced from build
203
+ var candidates = this . $fs . readDirectory ( platformData . buildOutputPath ) . wait ( ) ;
204
+ var packages = _ . filter ( candidates , candidate => {
205
+ return _ . contains ( platformData . validPackageNames , candidate ) ;
206
+ } ) . map ( currentPackage => {
207
+ currentPackage = path . join ( platformData . buildOutputPath , currentPackage ) ;
208
+
209
+ return {
210
+ pkg : currentPackage ,
211
+ time : this . $fs . getFsStats ( currentPackage ) . wait ( ) . mtime
212
+ } ;
213
+ } ) ;
214
+
215
+ packages = _ . sortBy ( packages , pkg => pkg . time ) . reverse ( ) ; // We need to reverse because sortBy always sorts in ascending order
216
+
217
+ if ( packages . length === 0 ) {
218
+ var packageExtName = path . extname ( platformData . validPackageNames [ 0 ] ) ;
219
+ this . $errors . fail ( "No %s found in %s directory" , packageExtName , platformData . buildOutputPath )
220
+ }
221
+
222
+ var packageFile = packages [ 0 ] . pkg ;
223
+ this . $logger . out ( "Using " , packageFile ) ;
224
+
225
+ this . $devicesServices . initialize ( platform , options . device ) . wait ( ) ;
226
+ var action = ( device : Mobile . IDevice ) : IFuture < void > => { return device . deploy ( packageFile , this . $projectData . projectId ) ; } ;
227
+ this . $devicesServices . execute ( action ) . wait ( ) ;
228
+
229
+ } ) . future < void > ( ) ( ) ;
230
+ }
231
+
193
232
private validatePlatform ( platform : string ) : void {
194
233
if ( ! platform ) {
195
234
this . $errors . fail ( "No platform specified." )
@@ -245,5 +284,20 @@ export class PlatformService implements IPlatformService {
245
284
}
246
285
return undefined ;
247
286
}
287
+
288
+ private processPlatformSpecificFiles ( platform : string , files : string [ ] ) : IFuture < void > {
289
+ // Renames the files that have `platform` as substring and removes the files from other platform
290
+ return ( ( ) => {
291
+ _ . each ( files , fileName => {
292
+ var platformInfo = PlatformService . parsePlatformSpecificFileName ( path . basename ( fileName ) , this . $platformsData . platformsNames ) ;
293
+ var shouldExcludeFile = platformInfo && platformInfo . platform !== platform ;
294
+ if ( shouldExcludeFile ) {
295
+ this . $fs . deleteFile ( fileName ) . wait ( ) ;
296
+ } else if ( platformInfo && platformInfo . onDeviceName ) {
297
+ this . $fs . rename ( fileName , path . join ( path . dirname ( fileName ) , platformInfo . onDeviceName ) ) . wait ( ) ;
298
+ }
299
+ } ) ;
300
+ } ) . future < void > ( ) ( ) ;
301
+ }
248
302
}
249
303
$injector . register ( "platformService" , PlatformService ) ;
0 commit comments