-
-
Notifications
You must be signed in to change notification settings - Fork 197
Android releated commands - platform add, prepare, build and platform list #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
f1d2736
21edafb
e5b34ff
15087bb
dbe8f77
e826c30
806aa30
604f2ae
ae84178
480b882
efa6d6b
3481c75
6cf93fd
d17afa9
69f54b0
6053ed4
9bb0c15
6b9dc0f
c35e02c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
///<reference path="../.d.ts"/> | ||
import helpers = require("./../common/helpers"); | ||
|
||
export class ListPlatformsCommand implements ICommand { | ||
constructor(private $platformService: IPlatformService, | ||
private $logger: ILogger) { } | ||
|
||
execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
var availablePlatforms = this.$platformService.getAvailablePlatforms().wait(); | ||
this.$logger.out("Available platforms: %s", helpers.formatListOfNames(availablePlatforms)); | ||
|
||
var installedPlatforms = this.$platformService.getInstalledPlatforms().wait(); | ||
this.$logger.out("Installed platforms %s", helpers.formatListOfNames(installedPlatforms)); | ||
}).future<void>()(); | ||
} | ||
} | ||
$injector.registerCommand("platform|*list", ListPlatformsCommand); | ||
|
||
export class AddPlatformCommand implements ICommand { | ||
constructor(private $platformService: IPlatformService) { } | ||
|
||
execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
this.$platformService.addPlatforms(args).wait(); | ||
}).future<void>()(); | ||
} | ||
} | ||
$injector.registerCommand("platform|add", AddPlatformCommand); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
///<reference path="../.d.ts"/> | ||
|
||
export class RunCommand implements ICommand { | ||
constructor(private $platformService: IPlatformService) { } | ||
|
||
execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
this.$platformService.runPlatform(args[0]).wait(); | ||
}).future<void>()(); | ||
} | ||
} | ||
$injector.registerCommand("run", RunCommand); | ||
|
||
export class PrepareCommand implements ICommand { | ||
constructor(private $platformService: IPlatformService) { } | ||
|
||
execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
this.$platformService.preparePlatform(args[0]).wait(); | ||
}).future<void>()(); | ||
} | ||
} | ||
$injector.registerCommand("prepare", PrepareCommand); | ||
|
||
export class BuildCommand implements ICommand { | ||
constructor(private $platformService: IPlatformService) { } | ||
|
||
execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
this.$platformService.buildPlatform(args[0]).wait(); | ||
}).future<void>()(); | ||
} | ||
} | ||
$injector.registerCommand("build", BuildCommand); |
+1 −0 | bootstrap.ts | |
+22 −0 | child-process.ts | |
+5 −0 | declarations.d.ts | |
+2 −0 | errors.ts | |
+8 −0 | helpers.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
interface IPlatformService { | ||
addPlatforms(platforms: string[]): IFuture<void>; | ||
getInstalledPlatforms(): IFuture<string[]>; | ||
getAvailablePlatforms(): IFuture<string[]>; | ||
runPlatform(platform: string): IFuture<void>; | ||
preparePlatform(platform: string): IFuture<void>; | ||
buildPlatform(platform: string): IFuture<void>; | ||
} | ||
|
||
interface IPlatformCapabilities { | ||
targetedOS?: string[]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
interface IProjectService { | ||
createProject(projectName: string, projectId: string): IFuture<void>; | ||
createPlatformSpecificProject(platform: string): IFuture<void>; | ||
prepareProject(platform: string): IFuture<void>; | ||
buildProject(platform: string): IFuture<void>; | ||
ensureProject(): void; | ||
projectData: IProjectData; | ||
} | ||
|
||
interface IAndroidProjectService { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need separate interfaces for Android and iOS or just a common There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a common is better :) |
||
createProject(projectData: IProjectData): IFuture<void>; | ||
prepareProject(projectData: IProjectData): IFuture<void>; | ||
buildProject(projectData: IProjectData): IFuture<void>; | ||
} | ||
|
||
interface IiOSProjectService { | ||
createProject(projectData: IProjectData): IFuture<void>; | ||
} | ||
|
||
interface IProjectData { | ||
projectDir: string; | ||
platformsDir: string; | ||
projectFilePath: string; | ||
projectId?: string; | ||
projectName?: string; | ||
} | ||
|
||
interface IProjectTemplatesService { | ||
defaultTemplatePath: IFuture<string>; | ||
androidFrameworkPath: IFuture<string>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
///<reference path=".d.ts"/> | ||
"use strict"; | ||
|
||
import Fiber = require("fibers"); | ||
import Future = require("fibers/future"); | ||
import path = require("path"); | ||
|
||
require("./common/extensions"); | ||
require("./bootstrap"); | ||
require("./options"); | ||
|
||
import errors = require("./common/errors"); | ||
errors.installUncaughtExceptionListener(); | ||
|
||
$injector.register("config", {"CI_LOGGER": false}); | ||
$injector.register("config", {"CI_LOGGER": false, PROJECT_FILE_NAME: ".tnsproject", "DEBUG": true}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't ship with |
||
|
||
var dispatcher = $injector.resolve("dispatcher"); | ||
dispatcher.runMainFiber(); | ||
dispatcher.runMainFiber(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
///<reference path="../.d.ts"/> | ||
|
||
import path = require("path"); | ||
import helpers = require("./../common/helpers"); | ||
|
||
export class PlatformService implements IPlatformService { | ||
constructor(private $errors: IErrors, | ||
private $fs: IFileSystem, | ||
private $projectService: IProjectService) { } | ||
|
||
private platformCapabilities: { [key: string]: IPlatformCapabilities } = { | ||
ios: { | ||
targetedOS: ['darwin'] | ||
}, | ||
android: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing OS'es? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
}; | ||
|
||
public getCapabilities(platform: string): IPlatformCapabilities { | ||
return this.platformCapabilities[platform]; | ||
} | ||
|
||
public addPlatforms(platforms: string[]): IFuture<void> { | ||
return (() => { | ||
this.$projectService.ensureProject(); | ||
|
||
if(!platforms || platforms.length === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check should be the first one to do in this function. |
||
this.$errors.fail("No platform specified. Please specify a platform to add"); | ||
} | ||
|
||
var platformsDir = this.$projectService.projectData.platformsDir; | ||
if(!this.$fs.exists(platformsDir).wait()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not extract an |
||
this.$fs.createDirectory(platformsDir).wait(); | ||
} | ||
|
||
_.each(platforms, platform => { | ||
this.addPlatform(platform.toLowerCase()).wait(); | ||
}); | ||
|
||
}).future<void>()(); | ||
} | ||
|
||
private addPlatform(platform: string): IFuture<void> { | ||
return(() => { | ||
platform = platform.split("@")[0]; | ||
var platformPath = path.join(this.$projectService.projectData.platformsDir, platform); | ||
|
||
// TODO: Check for version compatability if the platform is in format platform@version. This should be done in PR for semanting versioning | ||
|
||
this.validatePlatform(platform); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check can be done on the 2nd line of this method. |
||
|
||
if (this.$fs.exists(platformPath).wait()) { | ||
this.$errors.fail("Platform %s already added", platform); | ||
} | ||
|
||
// Copy platform specific files in platforms dir | ||
this.$projectService.createPlatformSpecificProject(platform).wait(); | ||
|
||
}).future<void>()(); | ||
} | ||
|
||
public getInstalledPlatforms(): IFuture<string[]> { | ||
return(() => { | ||
if(!this.$fs.exists(this.$projectService.projectData.platformsDir).wait()) { | ||
return []; | ||
} | ||
|
||
var subDirs = this.$fs.readDirectory(this.$projectService.projectData.platformsDir).wait(); | ||
return _.filter(subDirs, p => { return Object.keys(this.platformCapabilities).indexOf(p) > -1; }); | ||
}).future<string[]>()(); | ||
} | ||
|
||
public getAvailablePlatforms(): IFuture<string[]> { | ||
return (() => { | ||
var installedPlatforms = this.getInstalledPlatforms().wait(); | ||
return _.filter(_.keys(this.platformCapabilities), p => { | ||
return installedPlatforms.indexOf(p) < 0 && this.isPlatformSupportedForOS(p); // Only those not already installed | ||
}); | ||
}).future<string[]>()(); | ||
} | ||
|
||
public runPlatform(platform: string): IFuture<void> { | ||
return (() => { | ||
|
||
}).future<void>()(); | ||
} | ||
|
||
public preparePlatform(platform: string): IFuture<void> { | ||
return (() => { | ||
this.validatePlatform(platform); | ||
|
||
this.$projectService.prepareProject(platform).wait(); | ||
}).future<void>()(); | ||
} | ||
|
||
public buildPlatform(platform: string): IFuture<void> { | ||
return (() => { | ||
this.$projectService.buildProject(platform); | ||
}).future<void>()(); | ||
} | ||
|
||
private validatePlatform(platform): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (!this.isValidPlatform(platform)) { | ||
this.$errors.fail("Invalid platform %s. Valid platforms are %s.", platform, helpers.formatListOfNames(_.keys(this.platformCapabilities))); | ||
} | ||
|
||
if (!this.isPlatformSupportedForOS(platform)) { | ||
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", platform, process.platform); | ||
} | ||
} | ||
|
||
private isValidPlatform(platform: string) { | ||
return this.platformCapabilities[platform]; | ||
} | ||
|
||
private isPlatformSupportedForOS(platform: string): boolean { | ||
var platformCapabilities = this.getCapabilities(platform); | ||
var targetedOS = platformCapabilities.targetedOS; | ||
|
||
if(!targetedOS || targetedOS.indexOf("*") >= 0 || targetedOS.indexOf(process.platform) >= 0) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
$injector.register("platformService", PlatformService); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should't this be in a separate file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Javascript is module oriented and I think we should combine all platform releated commands into one file :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you put yourself in the foots of the JS VM and the context of CLI it does not make sense because we will only every execute a single command from the command line. There is no need to parse the whole file just to execute a portion of it 😄