1
1
///<reference path="../.d.ts"/>
2
2
3
+ import path = require( "path" ) ;
4
+ import helpers = require( "./../common/helpers" ) ;
5
+
3
6
export class PlatformService implements IPlatformService {
4
7
constructor ( private $errors : IErrors ,
5
8
private $fs : IFileSystem ,
6
9
private $projectService : IProjectService ) { }
7
10
8
- private platformCapabilities : { [ key : string ] : IPlatformCapabilities } = {
11
+ private platformCapabilities : { [ key : string ] : IPlatformCapabilities } = {
9
12
ios : {
10
13
targetedOS : [ 'darwin' ] ,
11
14
frameworkUrl : ""
@@ -19,52 +22,57 @@ export class PlatformService implements IPlatformService {
19
22
return this . platformCapabilities [ platform ] ;
20
23
}
21
24
22
- private isValidPlatform ( platform : string ) {
23
- return ! this . platformCapabilities [ platform . toLowerCase ( ) ] ;
24
- }
25
-
26
- public addPlatforms ( platforms : string [ ] ) : Future < any > {
25
+ public addPlatforms ( platforms : string [ ] ) : IFuture < any > {
27
26
return ( ( ) => {
28
- if ( ! platforms ) {
27
+ this . $projectService . ensureProject ( ) ;
28
+
29
+ if ( ! platforms || platforms . length === 0 ) {
29
30
this . $errors . fail ( "No platform specified. Please specify a platform to add" ) ;
30
31
}
31
32
32
33
var platformsDir = this . $projectService . projectData . platformsDir ;
33
34
if ( ! this . $fs . exists ( platformsDir ) . wait ( ) ) {
34
- this . $fs . createDirectory ( platformsDir ) ;
35
+ this . $fs . createDirectory ( platformsDir ) . wait ( ) ;
35
36
}
36
37
37
38
_ . each ( platforms , platform => {
38
- this . addPlatform ( platform ) ;
39
+ this . addPlatform ( platform . toLowerCase ( ) ) . wait ( ) ;
39
40
} ) ;
40
41
41
42
} ) . future < any > ( ) ( ) ;
42
43
}
43
44
44
- private addPlatform ( platform : string ) {
45
- platform = platform . split ( "@" ) [ 0 ] ;
46
- var platformPath = path . join ( this . $projectService . projectData . platformsDir , platform ) ;
45
+ private addPlatform ( platform : string ) : IFuture < void > {
46
+ return ( ( ) => {
47
+ platform = platform . split ( "@" ) [ 0 ] ;
48
+ var platformPath = path . join ( this . $projectService . projectData . platformsDir , platform ) ;
47
49
48
- // TODO: Check for version compatability if the platform is in format platform@version . This should be done in PR for semanting versioning
50
+ // TODO: Check for version compatability if the platform is in format platform@version . This should be done in PR for semanting versioning
49
51
50
- if ( ! this . isValidPlatform ( platform ) ) {
51
- this . $errors . fail ( "" ) ;
52
- }
52
+ if ( ! this . isValidPlatform ( platform ) ) {
53
+ this . $errors . fail ( "Invalid platform %s. Valid platforms are %s." , platform , helpers . formatListOfNames ( _ . keys ( this . platformCapabilities ) ) ) ;
54
+ }
53
55
54
- if ( ! this . isPlatformSupportedForOS ( platform ) ) {
55
- this . $errors . fail ( "Applications for platform %s can not be built on this OS - %s" , platform , process . platform ) ;
56
- }
56
+ if ( ! this . isPlatformSupportedForOS ( platform ) ) {
57
+ this . $errors . fail ( "Applications for platform %s can not be built on this OS - %s" , platform , process . platform ) ;
58
+ }
57
59
58
- if ( this . $fs . exists ( platformPath ) ) {
59
- this . $errors . fail ( "Platform %s already added" , platform ) ;
60
- }
60
+ if ( this . $fs . exists ( platformPath ) . wait ( ) ) {
61
+ this . $errors . fail ( "Platform %s already added" , platform ) ;
62
+ }
61
63
62
- // TODO: This should be downloaded from npm
63
- // Copy platform specific files in platforms dir
64
+ // Copy platform specific files in platforms dir
65
+ this . $projectService . createPlatformSpecificProject ( platform ) . wait ( ) ;
66
+
67
+ } ) . future < void > ( ) ( ) ;
64
68
}
65
69
66
- private isPlatformSupportedForOS ( platform : string ) : boolean {
67
- var platformCapabilities = this . getCapabilities ( platform ) || { } ;
70
+ private isValidPlatform ( platform : string ) {
71
+ return this . platformCapabilities [ platform ] ;
72
+ }
73
+
74
+ private isPlatformSupportedForOS ( platform : string ) : boolean {
75
+ var platformCapabilities = this . getCapabilities ( platform ) ;
68
76
var targetedOS = platformCapabilities . targetedOS ;
69
77
70
78
if ( ! targetedOS || targetedOS . indexOf ( "*" ) >= 0 || targetedOS . indexOf ( process . platform ) >= 0 ) {
@@ -73,4 +81,5 @@ export class PlatformService implements IPlatformService {
73
81
74
82
return false ;
75
83
}
76
- }
84
+ }
85
+ $injector . register ( "platformService" , PlatformService ) ;
0 commit comments