@@ -4,26 +4,43 @@ import path = require("path");
44import util = require( "util" ) ;
55import helpers = require( "./../common/helpers" ) ;
66
7- export class PlatformService implements IPlatformService {
8- private platformCapabilities : { [ key : string ] : IPlatformCapabilities } = {
7+ class PlatformsData implements IPlatformsData {
8+ private platformsData : { [ key : string ] : IPlatformData } = {
99 ios : {
10+ frameworkPackageName : "tns-ios" ,
11+ platformProjectService : $injector . resolve ( "iOSProjectService" ) ,
12+ projectRoot : "" ,
1013 targetedOS : [ 'darwin' ]
1114 } ,
1215 android : {
16+ frameworkPackageName : "tns-android" ,
17+ platformProjectService : $injector . resolve ( "androidProjectService" ) ,
18+ projectRoot : ""
1319 }
1420 } ;
1521
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 ) ;
1736
37+ export class PlatformService implements IPlatformService {
1838 constructor ( private $errors : IErrors ,
1939 private $fs : IFileSystem ,
2040 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 ) {
2744 }
2845
2946 public addPlatforms ( platforms : string [ ] ) : IFuture < void > {
@@ -59,7 +76,7 @@ export class PlatformService implements IPlatformService {
5976 }
6077
6178 // Copy platform specific files in platforms dir
62- this . $projectService . createPlatformSpecificProject ( platform ) . wait ( ) ;
79+ this . $platformProjectService . createProject ( platform ) . wait ( ) ;
6380
6481 } ) . future < void > ( ) ( ) ;
6582 }
@@ -71,14 +88,14 @@ export class PlatformService implements IPlatformService {
7188 }
7289
7390 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 ; } ) ;
7592 } ) . future < string [ ] > ( ) ( ) ;
7693 }
7794
7895 public getAvailablePlatforms ( ) : IFuture < string [ ] > {
7996 return ( ( ) => {
8097 var installedPlatforms = this . getInstalledPlatforms ( ) . wait ( ) ;
81- return _ . filter ( this . platformNames , p => {
98+ return _ . filter ( this . $platformsData . platformsNames , p => {
8299 return installedPlatforms . indexOf ( p ) < 0 && this . isPlatformSupportedForOS ( p ) ; // Only those not already installed
83100 } ) ;
84101 } ) . future < string [ ] > ( ) ( ) ;
@@ -96,7 +113,7 @@ export class PlatformService implements IPlatformService {
96113 this . validatePlatform ( platform ) ;
97114 var normalizedPlatformName = this . normalizePlatformName ( platform ) ;
98115
99- this . $projectService . prepareProject ( normalizedPlatformName , this . platformNames ) . wait ( ) ;
116+ // this.$projectService.prepareProject(normalizedPlatformName, this.platformNames).wait();
100117 } ) . future < void > ( ) ( ) ;
101118 }
102119
@@ -105,13 +122,13 @@ export class PlatformService implements IPlatformService {
105122 platform = platform . toLocaleLowerCase ( ) ;
106123 this . validatePlatform ( platform ) ;
107124
108- this . $projectService . buildProject ( platform ) . wait ( ) ;
125+ this . $platformProjectService . buildProject ( platform ) . wait ( ) ;
109126 } ) . future < void > ( ) ( ) ;
110127 }
111128
112129 private validatePlatform ( platform : string ) : void {
113130 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 ) ) ;
115132 }
116133
117134 if ( ! this . isPlatformSupportedForOS ( platform ) ) {
@@ -120,12 +137,11 @@ export class PlatformService implements IPlatformService {
120137 }
121138
122139 private isValidPlatform ( platform : string ) {
123- return this . platformCapabilities [ platform ] ;
140+ return this . $platformsData . getPlatformData ( platform ) ;
124141 }
125142
126143 private isPlatformSupportedForOS ( platform : string ) : boolean {
127- var platformCapabilities = this . getCapabilities ( platform ) ;
128- var targetedOS = platformCapabilities . targetedOS ;
144+ var targetedOS = this . $platformsData . getPlatformData ( platform ) . targetedOS ;
129145
130146 if ( ! targetedOS || targetedOS . indexOf ( "*" ) >= 0 || targetedOS . indexOf ( process . platform ) >= 0 ) {
131147 return true ;
@@ -145,4 +161,4 @@ export class PlatformService implements IPlatformService {
145161 return undefined ;
146162 }
147163}
148- $injector . register ( "platformService" , PlatformService ) ;
164+ $injector . register ( "platformService" , PlatformService ) ;
0 commit comments