2
2
"use strict" ;
3
3
4
4
import * as path from "path" ;
5
+ import * as temp from "temp" ;
5
6
import future = require( "fibers/future" ) ;
6
7
7
8
export class AndroidDeviceFileSystem implements Mobile . IDeviceFileSystem {
8
9
constructor ( private adb : Mobile . IAndroidDebugBridge ,
9
10
private identifier : string ,
10
11
private $fs : IFileSystem ,
11
12
private $logger : ILogger ,
12
- private $deviceAppDataFactory : Mobile . IDeviceAppDataFactory ) { }
13
+ private $deviceAppDataFactory : Mobile . IDeviceAppDataFactory ,
14
+ private $mobileHelper : Mobile . IMobileHelper ) { }
13
15
14
16
public listFiles ( devicePath : string ) : IFuture < void > {
15
17
return future . fromResult ( ) ;
@@ -45,8 +47,10 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
45
47
return ( ( ) => {
46
48
this . adb . executeCommand ( [ "push" , projectFilesPath , deviceAppData . deviceProjectRootPath ] ) . wait ( ) ;
47
49
48
- let command = _ . map ( localToDevicePaths , ( localToDevicePathData ) => localToDevicePathData . getDevicePath ( ) ) . join ( " " ) ;
49
- this . adb . executeCommand ( [ "chmod" , "0777" , command ] ) . wait ( ) ;
50
+ let command = _ . map ( localToDevicePaths , ( localToDevicePathData ) => `"${ localToDevicePathData . getDevicePath ( ) } "` ) . join ( " " ) ;
51
+ let commandsDeviceFilePath = this . $mobileHelper . buildDevicePath ( deviceAppData . deviceProjectRootPath , "nativescript.commands.sh" ) ;
52
+ this . createFileOnDevice ( commandsDeviceFilePath , command ) . wait ( ) ;
53
+ this . adb . executeShellCommand ( [ commandsDeviceFilePath ] ) . wait ( ) ;
50
54
} ) . future < void > ( ) ( ) ;
51
55
}
52
56
@@ -61,4 +65,22 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
61
65
}
62
66
} ) . future < void > ( ) ( ) ;
63
67
}
68
+
69
+ public createFileOnDevice ( deviceFilePath : string , fileContent : string ) : IFuture < void > {
70
+ return ( ( ) => {
71
+ let hostTmpDir = this . getTempDir ( ) ;
72
+ let commandsFileHostPath = path . join ( hostTmpDir , "temp.commands.file" ) ;
73
+ this . $fs . writeFile ( commandsFileHostPath , fileContent ) . wait ( ) ;
74
+
75
+ // copy it to the device
76
+ this . transferFile ( commandsFileHostPath , deviceFilePath ) . wait ( ) ;
77
+ this . adb . executeShellCommand ( [ "chmod" , "0777" , deviceFilePath ] ) . wait ( ) ;
78
+ } ) . future < void > ( ) ( ) ;
79
+ }
80
+
81
+ private getTempDir ( ) : string {
82
+ temp . track ( ) ;
83
+ return temp . mkdirSync ( "application-" ) ;
84
+ }
85
+
64
86
}
0 commit comments