@@ -4,26 +4,43 @@ import path = require("path");
4
4
import util = require( "util" ) ;
5
5
import helpers = require( "./../common/helpers" ) ;
6
6
7
- export class PlatformService implements IPlatformService {
8
- private platformCapabilities : { [ key : string ] : IPlatformCapabilities } = {
7
+ class PlatformsData implements IPlatformsData {
8
+ private platformsData : { [ key : string ] : IPlatformData } = {
9
9
ios : {
10
+ frameworkPackageName : "tns-ios" ,
11
+ platformProjectService : $injector . resolve ( "iOSProjectService" ) ,
12
+ projectRoot : "" ,
10
13
targetedOS : [ 'darwin' ]
11
14
} ,
12
15
android : {
16
+ frameworkPackageName : "tns-android" ,
17
+ platformProjectService : $injector . resolve ( "androidProjectService" ) ,
18
+ projectRoot : ""
13
19
}
14
20
} ;
15
21
16
- private platformNames = [ ] ;
22
+ constructor ( $projectData : IProjectData ) {
23
+ this . platformsData [ "ios" ] . projectRoot = "" ;
24
+ this . platformsData [ "android" ] . projectRoot = path . join ( $projectData . platformsDir , "android" ) ;
25
+ }
26
+
27
+ public get platformsNames ( ) {
28
+ return Object . keys ( this . platformsData ) ;
29
+ }
30
+
31
+ public getPlatformData ( platform ) : IPlatformData {
32
+ return this . platformsData [ platform ] ;
33
+ }
34
+ }
35
+ $injector . register ( "platformsData" , PlatformsData ) ;
17
36
37
+ export class PlatformService implements IPlatformService {
18
38
constructor ( private $errors : IErrors ,
19
39
private $fs : IFileSystem ,
20
40
private $projectService : IProjectService ,
21
- private $projectData : IProjectData ) {
22
- this . platformNames = Object . keys ( this . platformCapabilities ) ;
23
- }
24
-
25
- public getCapabilities ( platform : string ) : IPlatformCapabilities {
26
- return this . platformCapabilities [ platform ] ;
41
+ private $platformProjectService : IPlatformProjectService ,
42
+ private $projectData : IProjectData ,
43
+ private $platformsData : IPlatformsData ) {
27
44
}
28
45
29
46
public addPlatforms ( platforms : string [ ] ) : IFuture < void > {
@@ -59,7 +76,7 @@ export class PlatformService implements IPlatformService {
59
76
}
60
77
61
78
// Copy platform specific files in platforms dir
62
- this . $projectService . createPlatformSpecificProject ( platform ) . wait ( ) ;
79
+ this . $platformProjectService . createProject ( platform ) . wait ( ) ;
63
80
64
81
} ) . future < void > ( ) ( ) ;
65
82
}
@@ -71,14 +88,14 @@ export class PlatformService implements IPlatformService {
71
88
}
72
89
73
90
var subDirs = this . $fs . readDirectory ( this . $projectData . platformsDir ) . wait ( ) ;
74
- return _ . filter ( subDirs , p => { return this . platformNames . indexOf ( p ) > - 1 ; } ) ;
91
+ return _ . filter ( subDirs , p => { return this . $platformsData . platformsNames . indexOf ( p ) > - 1 ; } ) ;
75
92
} ) . future < string [ ] > ( ) ( ) ;
76
93
}
77
94
78
95
public getAvailablePlatforms ( ) : IFuture < string [ ] > {
79
96
return ( ( ) => {
80
97
var installedPlatforms = this . getInstalledPlatforms ( ) . wait ( ) ;
81
- return _ . filter ( this . platformNames , p => {
98
+ return _ . filter ( this . $platformsData . platformsNames , p => {
82
99
return installedPlatforms . indexOf ( p ) < 0 && this . isPlatformSupportedForOS ( p ) ; // Only those not already installed
83
100
} ) ;
84
101
} ) . future < string [ ] > ( ) ( ) ;
@@ -96,7 +113,7 @@ export class PlatformService implements IPlatformService {
96
113
this . validatePlatform ( platform ) ;
97
114
var normalizedPlatformName = this . normalizePlatformName ( platform ) ;
98
115
99
- this . $projectService . prepareProject ( normalizedPlatformName , this . platformNames ) . wait ( ) ;
116
+ // this.$projectService.prepareProject(normalizedPlatformName, this.platformNames).wait();
100
117
} ) . future < void > ( ) ( ) ;
101
118
}
102
119
@@ -105,13 +122,13 @@ export class PlatformService implements IPlatformService {
105
122
platform = platform . toLocaleLowerCase ( ) ;
106
123
this . validatePlatform ( platform ) ;
107
124
108
- this . $projectService . buildProject ( platform ) . wait ( ) ;
125
+ this . $platformProjectService . buildProject ( platform ) . wait ( ) ;
109
126
} ) . future < void > ( ) ( ) ;
110
127
}
111
128
112
129
private validatePlatform ( platform : string ) : void {
113
130
if ( ! this . isValidPlatform ( platform ) ) {
114
- this . $errors . fail ( "Invalid platform %s. Valid platforms are %s." , platform , helpers . formatListOfNames ( this . platformNames ) ) ;
131
+ this . $errors . fail ( "Invalid platform %s. Valid platforms are %s." , platform , helpers . formatListOfNames ( this . $platformsData . platformsNames ) ) ;
115
132
}
116
133
117
134
if ( ! this . isPlatformSupportedForOS ( platform ) ) {
@@ -120,12 +137,11 @@ export class PlatformService implements IPlatformService {
120
137
}
121
138
122
139
private isValidPlatform ( platform : string ) {
123
- return this . platformCapabilities [ platform ] ;
140
+ return this . $platformsData . getPlatformData ( platform ) ;
124
141
}
125
142
126
143
private isPlatformSupportedForOS ( platform : string ) : boolean {
127
- var platformCapabilities = this . getCapabilities ( platform ) ;
128
- var targetedOS = platformCapabilities . targetedOS ;
144
+ var targetedOS = this . $platformsData . getPlatformData ( platform ) . targetedOS ;
129
145
130
146
if ( ! targetedOS || targetedOS . indexOf ( "*" ) >= 0 || targetedOS . indexOf ( process . platform ) >= 0 ) {
131
147
return true ;
@@ -145,4 +161,4 @@ export class PlatformService implements IPlatformService {
145
161
return undefined ;
146
162
}
147
163
}
148
- $injector . register ( "platformService" , PlatformService ) ;
164
+ $injector . register ( "platformService" , PlatformService ) ;
0 commit comments