Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 204
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f1d273621edafbe5b34ff15087bbdbe8f77e826c30806aa30604f2aeae84178480b882efa6d6b3481c756cf93fdd17afa969f54b06053ed49bb0c156b9dc0fc35e02cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ///<reference path="../.d.ts"/> | ||
| 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,12 @@ | ||
| ///<reference path="../.d.ts"/> | ||
| 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ///<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); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ///<reference path="../.d.ts"/> | ||
| 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ///<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); |
| +2 −0 | bootstrap.ts | |
| +22 −0 | child-process.ts | |
| +11 −0 | declarations.d.ts | |
| +2 −0 | errors.ts | |
| +31 −5 | file-system.ts | |
| +13 −1 | helpers.ts | |
| +40 −0 | project-helper.ts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| interface INodePackageManager { | ||
| cache: string; | ||
| load(config?: any): IFuture<void>; | ||
| install(where: string, what: string): IFuture<any>; | ||
| cache: string; | ||
| load(config?: any): IFuture<void>; | ||
| install(where: string, what: string): IFuture<any>; | ||
| } | ||
| interface IPropertiesParser { | ||
| createEditor(filePath: string): IFuture<any>; | ||
| } |
| 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,26 @@ | ||
| interface IProjectService { | ||
| createProject(projectName: string, projectId: string): IFuture<void>; | ||
| createPlatformSpecificProject(platform: string): IFuture<void>; | ||
| prepareProject(normalizedPlatformName: string, platforms: string[]): IFuture<void>; | ||
| buildProject(platform: string): IFuture<void>; | ||
| ensureProject(): void; | ||
| projectData: IProjectData; | ||
| } | ||
| interface IPlatformProjectService { | ||
| createProject(projectData: IProjectData): IFuture<void>; | ||
| buildProject(projectData: IProjectData): IFuture<void>; | ||
| } | ||
| interface IProjectData { | ||
| projectDir: string; | ||
| platformsDir: string; | ||
| projectFilePath: string; | ||
| projectId?: string; | ||
| projectName?: string; | ||
| } | ||
| interface IProjectTemplatesService { | ||
| defaultTemplatePath: IFuture<string>; | ||
| installAndroidFramework(whereToInstall: string): IFuture<string> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| declare module "properties-parser" { | ||
| function createEditor(path: string, callback: (err: IErrors, data: any) => void); | ||
| } |
| 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": process.env.NATIVESCRIPT_DEBUG}); | ||
| var dispatcher = $injector.resolve("dispatcher"); | ||
| dispatcher.runMainFiber(); | ||
| dispatcher.runMainFiber(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ///<reference path=".d.ts"/> | ||
| import propertiesParser = require("properties-parser"); | ||
| import Future = require("fibers/future"); | ||
| export class PropertiesParser implements IPropertiesParser { | ||
| public createEditor(filePath: string) { | ||
| var future = new Future<any>(); | ||
| propertiesParser.createEditor(filePath, (err, data) => { | ||
| if(err) { | ||
| future.throw(err); | ||
| } else { | ||
| future.return(data); | ||
| } | ||
| }); | ||
| return future; | ||
| } | ||
| } | ||
| $injector.register("propertiesParser", PropertiesParser); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| ///<reference path="../.d.ts"/> | ||
| import path = require("path"); | ||
| import util = require("util"); | ||
| import helpers = require("./../common/helpers"); | ||
| export class PlatformService implements IPlatformService { | ||
| private platformCapabilities: { [key: string]: IPlatformCapabilities } = { | ||
| ios: { | ||
| targetedOS: ['darwin'] | ||
| }, | ||
| android: { | ||
Contributor 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? ContributorAuthor 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.
| ||
| } | ||
| }; | ||
| private platformNames = []; | ||
| constructor(private $errors: IErrors, | ||
| private $fs: IFileSystem, | ||
| private $projectService: IProjectService) { | ||
| this.platformNames = Object.keys(this.platformCapabilities); | ||
| } | ||
| public getCapabilities(platform: string): IPlatformCapabilities { | ||
| return this.platformCapabilities[platform]; | ||
| } | ||
| public addPlatforms(platforms: string[]): IFuture<void> { | ||
| return (() => { | ||
| 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"); | ||
| } | ||
| this.$projectService.ensureProject(); | ||
| var platformsDir = this.$projectService.projectData.platformsDir; | ||
| this.$fs.ensureDirectoryExists(platformsDir).wait(); | ||
| _.each(platforms, platform => { | ||
| this.addPlatform(platform.toLowerCase()).wait(); | ||
| }); | ||
| }).future<void>()(); | ||
| } | ||
| private addPlatform(platform: string): IFuture<void> { | ||
| return(() => { | ||
| platform = platform.split("@")[0]; | ||
| this.validatePlatform(platform); | ||
| 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 | ||
| 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 this.platformNames.indexOf(p) > -1; }); | ||
| }).future<string[]>()(); | ||
| } | ||
| public getAvailablePlatforms(): IFuture<string[]> { | ||
| return (() => { | ||
| var installedPlatforms = this.getInstalledPlatforms().wait(); | ||
| return _.filter(this.platformNames, 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 (() => { | ||
| platform = platform.toLowerCase(); | ||
| this.validatePlatform(platform); | ||
| var normalizedPlatformName = this.normalizePlatformName(platform); | ||
| this.$projectService.prepareProject(normalizedPlatformName, this.platformNames).wait(); | ||
| }).future<void>()(); | ||
| } | ||
| public buildPlatform(platform: string): IFuture<void> { | ||
| return (() => { | ||
| platform = platform.toLocaleLowerCase(); | ||
| this.validatePlatform(platform); | ||
| this.$projectService.buildProject(platform).wait(); | ||
| }).future<void>()(); | ||
| } | ||
| private validatePlatform(platform: string): void { | ||
| if (!this.isValidPlatform(platform)) { | ||
| this.$errors.fail("Invalid platform %s. Valid platforms are %s.", platform, helpers.formatListOfNames(this.platformNames)); | ||
| } | ||
| 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; | ||
| } | ||
| private normalizePlatformName(platform: string): string { | ||
| switch(platform) { | ||
| case "android": | ||
| return "Android"; | ||
| case "ios": | ||
| return "iOS"; | ||
| } | ||
| return undefined; | ||
| } | ||
| } | ||
| $injector.register("platformService", PlatformService); | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
This pattern seems repeated with the one in
NodePackageManager. Consider adding a helper similar to the one in theQlibrary. https://github.com/kriskowal/q/wiki/API-Reference#qnfbindnodefunc-argsThere 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.
It's a good idea, but I think it would be better to do it in another PR. Agree?