Skip to content

Commit 21edafb

Browse files
committed
Platform command
1 parent f1d2736 commit 21edafb

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

lib/commands/platform-command.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
///<reference path="../.d.ts"/>
2+
3+
export class AddPlatformCommand implements ICommand {
4+
constructor(private $platformService: IPlatformService) { }
5+
6+
execute(args: string[]): IFuture<void> {
7+
return (() => {
8+
this.$platformService.add(args[0]).wait();
9+
}).future<void>()();
10+
}
11+
}
12+
$injector.registerCommand("platform|add", AddPlatformCommand);

lib/definitions/platform.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface IPlatformService {
2+
addPlatforms(platforms: string[]): Future<any>;
3+
}
4+
5+
interface IPlatformCapabilities {
6+
targetedOS: string[];
7+
frameworkUrl: string;
8+
}

lib/definitions/project.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
interface IProjectService {
22
createProject(projectName: string, projectId: string): IFuture<void>;
3+
projectData: IProjectData;
4+
}
5+
6+
interface IProjectData {
7+
projectDir: string;
8+
platformsDir: string;
39
}
410

511
interface IProjectTemplatesService {

lib/services/platform-service.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
}

lib/services/project-service.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export class ProjectService implements IProjectService {
1515
private $fs: IFileSystem,
1616
private $projectTemplatesService: IProjectTemplatesService) { }
1717

18+
public get projectData(): IProjectData {
19+
return {
20+
projectDir: "",
21+
platformsDir: ""
22+
};
23+
}
24+
1825
public createProject(projectName: string, projectId: string): IFuture<void> {
1926
return(() => {
2027
var projectDir = path.resolve(options.path || ".");
@@ -62,6 +69,18 @@ export class ProjectService implements IProjectService {
6269
}).future<void>()();
6370
}
6471

72+
public createAndroidProject(projectName: string): Future<any> {
73+
return (() => {
74+
75+
}).future<any>()();
76+
}
77+
78+
public createiOSProject(projectName: string): Future<any> {
79+
return (() => {
80+
81+
}).future<any>()();
82+
}
83+
6584
private createProjectCore(projectDir: string, appPath: string, symlink?: boolean): IFuture<void> {
6685
return (() => {
6786
if(!this.$fs.exists(projectDir).wait()) {

0 commit comments

Comments
 (0)