Skip to content

Commit 15087bb

Browse files
committed
Create project file, basic android project service + improvements
1 parent e5b34ff commit 15087bb

File tree

9 files changed

+206
-62
lines changed

9 files changed

+206
-62
lines changed

lib/bootstrap.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ require("./common/bootstrap");
33
$injector.require("nativescript-cli", "./nativescript-cli");
44

55
$injector.require("projectService", "./services/project-service");
6+
$injector.require("androidProjectService", "./services/project-service");
7+
$injector.require("iOSProjectService", "./services/project-service");
68
$injector.require("projectTemplatesService", "./services/project-templates-service");
9+
$injector.require("platformService", "./services/platform-service");
710

811
$injector.requireCommand("create", "./commands/create-project-command");
12+
$injector.requireCommand("platform|*list", "./commands/platform-command");
13+
$injector.requireCommand("platform|add", "./commands/platform-command");
914

1015
$injector.require("npm", "./node-package-manager");

lib/commands/platform-command.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
///<reference path="../.d.ts"/>
22

3+
export class ListPlatformsCommand implements ICommand {
4+
constructor(private $platformService: IPlatformService) { }
5+
6+
execute(args: string[]): IFuture<void> {
7+
return (() => {
8+
}).future<void>()();
9+
}
10+
}
11+
$injector.registerCommand("platform|*list", ListPlatformsCommand);
12+
313
export class AddPlatformCommand implements ICommand {
414
constructor(private $platformService: IPlatformService) { }
515

616
execute(args: string[]): IFuture<void> {
717
return (() => {
8-
this.$platformService.add(args[0]).wait();
18+
this.$platformService.addPlatforms(args).wait();
919
}).future<void>()();
1020
}
1121
}

lib/common

lib/definitions/platform.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
interface IPlatformService {
2-
addPlatforms(platforms: string[]): Future<any>;
2+
addPlatforms(platforms: string[]): IFuture<any>;
33
}
44

55
interface IPlatformCapabilities {
6-
targetedOS: string[];
6+
targetedOS?: string[];
77
frameworkUrl: string;
88
}

lib/definitions/project.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
interface IProjectService {
22
createProject(projectName: string, projectId: string): IFuture<void>;
3+
createPlatformSpecificProject(platform: string): IFuture<void>;
4+
ensureProject(): void;
35
projectData: IProjectData;
46
}
57

8+
interface IAndroidProjectService {
9+
createProject(projectData: IProjectData): IFuture<void>;
10+
}
11+
12+
interface IiOSProjectService {
13+
createProject(projectData: IProjectData): IFuture<void>;
14+
}
15+
616
interface IProjectData {
717
projectDir: string;
818
platformsDir: string;
19+
projectFilePath: string;
20+
projectId?: string;
21+
projectName?: string;
922
}
1023

1124
interface IProjectTemplatesService {

lib/definitions/shelljs.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ declare module "shelljs" {
22
function cp(arg: string, sourcePath: string, destinationPath: string): void;
33
function sed(arg: string, oldValue: any, newValue: string, filePath: string): void;
44
function mv(source: string[], destination: string);
5+
function grep(what: any, where: string): any;
56
}

lib/nativescript-cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
///<reference path=".d.ts"/>
2+
"use strict";
23

3-
import Fiber = require("fibers");
4-
import Future = require("fibers/future");
54
import path = require("path");
65

6+
require("./common/extensions");
77
require("./bootstrap");
88
require("./options");
99

1010
import errors = require("./common/errors");
1111
errors.installUncaughtExceptionListener();
1212

13-
$injector.register("config", {"CI_LOGGER": false});
13+
$injector.register("config", {"CI_LOGGER": false, PROJECT_FILE_NAME: ".tnsproject", "DEBUG": true});
1414

1515
var dispatcher = $injector.resolve("dispatcher");
1616
dispatcher.runMainFiber();

lib/services/platform-service.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
///<reference path="../.d.ts"/>
22

3+
import path = require("path");
4+
import helpers = require("./../common/helpers");
5+
36
export class PlatformService implements IPlatformService {
47
constructor(private $errors: IErrors,
58
private $fs: IFileSystem,
69
private $projectService: IProjectService) { }
710

8-
private platformCapabilities: {[key: string]: IPlatformCapabilities} = {
11+
private platformCapabilities: { [key: string]: IPlatformCapabilities } = {
912
ios: {
1013
targetedOS: ['darwin'],
1114
frameworkUrl: ""
@@ -19,52 +22,57 @@ export class PlatformService implements IPlatformService {
1922
return this.platformCapabilities[platform];
2023
}
2124

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> {
2726
return (() => {
28-
if(!platforms) {
27+
this.$projectService.ensureProject();
28+
29+
if(!platforms || platforms.length === 0) {
2930
this.$errors.fail("No platform specified. Please specify a platform to add");
3031
}
3132

3233
var platformsDir = this.$projectService.projectData.platformsDir;
3334
if(!this.$fs.exists(platformsDir).wait()) {
34-
this.$fs.createDirectory(platformsDir);
35+
this.$fs.createDirectory(platformsDir).wait();
3536
}
3637

3738
_.each(platforms, platform => {
38-
this.addPlatform(platform);
39+
this.addPlatform(platform.toLowerCase()).wait();
3940
});
4041

4142
}).future<any>()();
4243
}
4344

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);
4749

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
4951

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+
}
5355

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+
}
5759

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+
}
6163

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>()();
6468
}
6569

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);
6876
var targetedOS = platformCapabilities.targetedOS;
6977

7078
if(!targetedOS || targetedOS.indexOf("*") >= 0 || targetedOS.indexOf(process.platform) >= 0) {
@@ -73,4 +81,5 @@ export class PlatformService implements IPlatformService {
7381

7482
return false;
7583
}
76-
}
84+
}
85+
$injector.register("platformService", PlatformService);

0 commit comments

Comments
 (0)