@@ -2,59 +2,59 @@ import * as path from "path";
2
2
import * as shell from "shelljs" ;
3
3
4
4
export class ProjectV4MigrationService implements IProjectV4MigrationService {
5
- private static ANDROID_DIR = "Android" ;
6
- private static ANDROID_DIR_TEMP = "Android-Updated" ;
7
- private static ANDROID_DIR_OLD = "Android-Pre-v4" ;
8
-
9
- constructor ( private $fs : IFileSystem ,
10
- private $logger : ILogger ,
11
- private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ) { }
12
-
13
- canMigrate ( platformString : string ) : boolean {
14
- if ( platformString . toLowerCase ( ) === this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) {
15
- return false ;
16
- }
17
-
18
- return true ;
19
- }
20
-
21
- hasMigrated ( appResourcesDir : string ) : boolean {
22
- return this . $fs . exists ( path . join ( appResourcesDir , ProjectV4MigrationService . ANDROID_DIR , "src" , "main" ) ) ;
23
- }
24
-
25
- async migrate ( appResourcesDir : string ) : Promise < void > {
26
- const originalAppResources = path . join ( appResourcesDir , ProjectV4MigrationService . ANDROID_DIR ) ;
27
- const appResourcesDestination = path . join ( appResourcesDir , ProjectV4MigrationService . ANDROID_DIR_TEMP ) ;
28
- const appMainSourceSet = path . join ( appResourcesDestination , "src" , "main" ) ;
29
- const appResourcesMainSourceSetResourcesDestination = path . join ( appMainSourceSet , "res" ) ;
30
-
31
- this . $fs . ensureDirectoryExists ( appResourcesDestination ) ;
32
- this . $fs . ensureDirectoryExists ( appMainSourceSet ) ;
33
- // create /java, /res and /assets in the App_Resources/Android/src/main directory
34
- this . $fs . ensureDirectoryExists ( appResourcesMainSourceSetResourcesDestination ) ;
35
- this . $fs . ensureDirectoryExists ( path . join ( appMainSourceSet , "java" ) ) ;
36
- this . $fs . ensureDirectoryExists ( path . join ( appMainSourceSet , "assets" ) ) ;
37
-
38
- const isDirectory = ( source : string ) => this . $fs . getLsStats ( source ) . isDirectory ( )
39
- const getDirectories = ( source : string ) =>
40
- this . $fs . readDirectory ( source ) . map ( name => path . join ( source , name ) ) . filter ( isDirectory )
41
-
42
- shell . cp ( path . join ( originalAppResources , "app.gradle" ) , path . join ( appResourcesDestination , "app.gradle" ) ) ;
43
- shell . cp ( path . join ( originalAppResources , "AndroidManifest.xml" ) , path . join ( appMainSourceSet , "AndroidManifest.xml" ) ) ;
44
-
45
- let resourceDirectories = getDirectories ( originalAppResources ) ;
46
-
47
- resourceDirectories . forEach ( dir => {
48
- shell . cp ( "-Rf" , dir , appResourcesMainSourceSetResourcesDestination ) ;
49
- } ) ;
50
-
51
- // rename the pre-v4 app_resources to ANDROID_DIR_OLD
52
- shell . mv ( originalAppResources , path . join ( appResourcesDir , ProjectV4MigrationService . ANDROID_DIR_OLD ) ) ;
53
- // move the new, updated app_resources to App_Resources/Android, as the de facto resources
54
- shell . mv ( appResourcesDestination , originalAppResources )
55
-
56
- this . $logger . out ( `Successfully updated your project's App_Resources/Android directory structure.\nThe previous version of App_Resources/Android has been renamed to App_Resources/${ ProjectV4MigrationService . ANDROID_DIR_OLD } ` ) ;
57
- }
5
+ private static ANDROID_DIR = "Android" ;
6
+ private static ANDROID_DIR_TEMP = "Android-Updated" ;
7
+ private static ANDROID_DIR_OLD = "Android-Pre-v4" ;
8
+
9
+ constructor ( private $fs : IFileSystem ,
10
+ private $logger : ILogger ,
11
+ private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ) { }
12
+
13
+ canMigrate ( platformString : string ) : boolean {
14
+ if ( platformString . toLowerCase ( ) === this . $devicePlatformsConstants . iOS . toLowerCase ( ) ) {
15
+ return false ;
16
+ }
17
+
18
+ return true ;
19
+ }
20
+
21
+ hasMigrated ( appResourcesDir : string ) : boolean {
22
+ return this . $fs . exists ( path . join ( appResourcesDir , ProjectV4MigrationService . ANDROID_DIR , "src" , "main" ) ) ;
23
+ }
24
+
25
+ async migrate ( appResourcesDir : string ) : Promise < void > {
26
+ const originalAppResources = path . join ( appResourcesDir , ProjectV4MigrationService . ANDROID_DIR ) ;
27
+ const appResourcesDestination = path . join ( appResourcesDir , ProjectV4MigrationService . ANDROID_DIR_TEMP ) ;
28
+ const appMainSourceSet = path . join ( appResourcesDestination , "src" , "main" ) ;
29
+ const appResourcesMainSourceSetResourcesDestination = path . join ( appMainSourceSet , "res" ) ;
30
+
31
+ this . $fs . ensureDirectoryExists ( appResourcesDestination ) ;
32
+ this . $fs . ensureDirectoryExists ( appMainSourceSet ) ;
33
+ // create /java, /res and /assets in the App_Resources/Android/src/main directory
34
+ this . $fs . ensureDirectoryExists ( appResourcesMainSourceSetResourcesDestination ) ;
35
+ this . $fs . ensureDirectoryExists ( path . join ( appMainSourceSet , "java" ) ) ;
36
+ this . $fs . ensureDirectoryExists ( path . join ( appMainSourceSet , "assets" ) ) ;
37
+
38
+ const isDirectory = ( source : string ) => this . $fs . getLsStats ( source ) . isDirectory ( ) ;
39
+ const getDirectories = ( source : string ) =>
40
+ this . $fs . readDirectory ( source ) . map ( name => path . join ( source , name ) ) . filter ( isDirectory ) ;
41
+
42
+ shell . cp ( path . join ( originalAppResources , "app.gradle" ) , path . join ( appResourcesDestination , "app.gradle" ) ) ;
43
+ shell . cp ( path . join ( originalAppResources , "AndroidManifest.xml" ) , path . join ( appMainSourceSet , "AndroidManifest.xml" ) ) ;
44
+
45
+ const resourceDirectories = getDirectories ( originalAppResources ) ;
46
+
47
+ resourceDirectories . forEach ( dir => {
48
+ shell . cp ( "-Rf" , dir , appResourcesMainSourceSetResourcesDestination ) ;
49
+ } ) ;
50
+
51
+ // rename the pre-v4 app_resources to ANDROID_DIR_OLD
52
+ shell . mv ( originalAppResources , path . join ( appResourcesDir , ProjectV4MigrationService . ANDROID_DIR_OLD ) ) ;
53
+ // move the new, updated app_resources to App_Resources/Android, as the de facto resources
54
+ shell . mv ( appResourcesDestination , originalAppResources ) ;
55
+
56
+ this . $logger . out ( `Successfully updated your project's App_Resources/Android directory structure.\nThe previous version of App_Resources/Android has been renamed to App_Resources/${ ProjectV4MigrationService . ANDROID_DIR_OLD } ` ) ;
57
+ }
58
58
}
59
59
60
- $injector . register ( "projectV4MigrationService" , ProjectV4MigrationService ) ;
60
+ $injector . register ( "projectV4MigrationService" , ProjectV4MigrationService ) ;
0 commit comments