-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fatme Havaluova
authored and
Fatme Havaluova
committed
Jun 24, 2015
1 parent
787d2ce
commit b061f55
Showing
3 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,72 @@ | ||
///<reference path="../.d.ts"/> | ||
"use strict"; | ||
|
||
import path = require("path"); | ||
|
||
export class InstallCommand implements ICommand { | ||
constructor() { } | ||
constructor(private $fs: IFileSystem, | ||
private $errors: IErrors, | ||
private $logger: ILogger, | ||
private $options: IOptions, | ||
private $injector: IInjector, | ||
private $staticConfig: IStaticConfig) { } | ||
|
||
allowedParameters: ICommandParameter[] = []; | ||
|
||
execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
let projectFilePath = this.getProjectFilePath(args[0]); | ||
let projectData = this.getProjectData(projectFilePath).wait(); | ||
let projectName = projectData.id.split(".")[2]; | ||
|
||
if(!this.$options.path) { | ||
this.$options.path = path.join(path.dirname(projectFilePath), projectName); | ||
} | ||
|
||
this.$injector.resolve("projectService").createProject(projectName).wait(); | ||
|
||
this.$logger.info("Adding platforms..."); | ||
|
||
let $platformsData = this.$injector.resolve("platformsData"); | ||
_.each($platformsData.platformsNames, platform => { | ||
let platformData = $platformsData.getPlatformData(platform); | ||
let frameworkPackageData = projectData[platformData.frameworkPackageName]; | ||
if(frameworkPackageData && frameworkPackageData.version) { | ||
this.$injector.resolve("platformService").addPlatforms([`${platform}@${frameworkPackageData.version}`]).wait(); | ||
} | ||
}); | ||
|
||
}).future<void>()(); | ||
} | ||
|
||
canExecute(args: string[]): IFuture<boolean> { | ||
return (() => { | ||
let projectFilePath = this.getProjectFilePath(args[0]); | ||
if(!this.$fs.exists(projectFilePath).wait()) { | ||
this.$errors.failWithoutHelp("The provided path doesn't contain package.json"); | ||
} | ||
|
||
let projectData = this.getProjectData(projectFilePath).wait(); | ||
if(!projectData) { | ||
this.$errors.failWithoutHelp("Invalid project file. Verify that the specified package.json file contains a nativescript key and try again."); | ||
} | ||
|
||
return true; | ||
}).future<boolean>()(); | ||
} | ||
|
||
private getProjectFilePath(providedPath: string): string { | ||
providedPath = path.resolve(providedPath); | ||
return path.basename(providedPath) === "package.json" ? providedPath : path.join(providedPath, "package.json"); | ||
} | ||
|
||
private getProjectData(projectFilePath: string): IFuture<any> { | ||
return (() => { | ||
let fileContent = this.$fs.readJson(projectFilePath).wait(); | ||
let projectData = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE]; | ||
|
||
return projectData; | ||
}).future<any>()(); | ||
} | ||
} | ||
$injector.register("install", InstallCommand); | ||
$injector.registerCommand("install", InstallCommand); |