Skip to content

Commit 7576a5c

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Implement install command #587
1 parent 3061fcd commit 7576a5c

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

bin/nativescript.js

100644100755
File mode changed.

lib/bootstrap.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ $injector.require("broccoliPluginWrapper", "./tools/broccoli/broccoli-plugin-wra
5858

5959
$injector.require("pluginsService", "./services/plugins-service");
6060
$injector.requireCommand("plugin|add", "./commands/plugin/add-plugin");
61-
$injector.requireCommand("plugin|remove", "./commands/plugin/remove-plugin");
61+
$injector.requireCommand("plugin|remove", "./commands/plugin/remove-plugin");
62+
$injector.requireCommand("install", "./commands/install");

lib/commands/install.ts

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import path = require("path");
5+
6+
export class InstallCommand implements ICommand {
7+
constructor(private $fs: IFileSystem,
8+
private $errors: IErrors,
9+
private $logger: ILogger,
10+
private $options: IOptions,
11+
private $injector: IInjector,
12+
private $staticConfig: IStaticConfig) { }
13+
14+
allowedParameters: ICommandParameter[] = [];
15+
16+
execute(args: string[]): IFuture<void> {
17+
return (() => {
18+
let projectFilePath = this.getProjectFilePath(args[0]);
19+
let projectData = this.getProjectData(projectFilePath).wait();
20+
let projectName = projectData.id.split(".")[2];
21+
22+
if(!this.$options.path) {
23+
this.$options.path = path.join(path.dirname(projectFilePath), projectName);
24+
}
25+
26+
this.$injector.resolve("projectService").createProject(projectName).wait();
27+
28+
this.$logger.info("Adding platforms...");
29+
30+
let $platformsData = this.$injector.resolve("platformsData");
31+
_.each($platformsData.platformsNames, platform => {
32+
let platformData = $platformsData.getPlatformData(platform);
33+
let frameworkPackageData = projectData[platformData.frameworkPackageName];
34+
if(frameworkPackageData && frameworkPackageData.version) {
35+
this.$injector.resolve("platformService").addPlatforms([`${platform}@${frameworkPackageData.version}`]).wait();
36+
}
37+
});
38+
39+
}).future<void>()();
40+
}
41+
42+
canExecute(args: string[]): IFuture<boolean> {
43+
return (() => {
44+
let projectFilePath = this.getProjectFilePath(args[0]);
45+
if(!this.$fs.exists(projectFilePath).wait()) {
46+
this.$errors.failWithoutHelp("The provided path doesn't contain package.json");
47+
}
48+
49+
let projectData = this.getProjectData(projectFilePath).wait();
50+
if(!projectData) {
51+
this.$errors.failWithoutHelp("Invalid project file. Verify that the specified package.json file contains a nativescript key and try again.");
52+
}
53+
54+
return true;
55+
}).future<boolean>()();
56+
}
57+
58+
private getProjectFilePath(providedPath: string): string {
59+
providedPath = path.resolve(providedPath);
60+
return path.basename(providedPath) === "package.json" ? providedPath : path.join(providedPath, "package.json");
61+
}
62+
63+
private getProjectData(projectFilePath: string): IFuture<any> {
64+
return (() => {
65+
let fileContent = this.$fs.readJson(projectFilePath).wait();
66+
let projectData = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
67+
68+
return projectData;
69+
}).future<any>()();
70+
}
71+
}
72+
$injector.registerCommand("install", InstallCommand);

0 commit comments

Comments
 (0)