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