Skip to content

Commit 8fe861c

Browse files
author
Tsvetan Raikov
committed
Added tns update command
1 parent 6b049a8 commit 8fe861c

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
platform update
2+
==========
3+
4+
Usage | Synopsis
5+
------|-------
6+
Update with the latest version |`$ tns update`
7+
Update with specific version | `$ tns update <version>`
8+
9+
Updates a NativeScript project to the latest (or specified) version.
10+
11+
### Related Commands
12+
13+
Command | Description
14+
----------|----------
15+
[install](install.html) | Installs all platforms and dependencies described in the `package.json` file in the current directory.
16+
[platform add](platform-add.html) | Configures the current project to target the selected platform.
17+
[platform remove](platform-remove.html) | Removes the selected platform from the platforms that the project currently targets.
18+
[platform](platform.html) | Lists all platforms that the project currently targets.
19+
[prepare](prepare.html) | Copies common and relevant platform-specific content from the app directory to the subdirectory for the selected target platform in the platforms directory.
20+
[platform update](platform-update.html) | Updates the NativeScript runtime for the specified platform.

lib/bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ $injector.require("xmlValidator", "./xml-validator");
118118

119119
$injector.requireCommand("devices", "./commands/devices");
120120
$injector.requireCommand("post-install-cli", "./commands/post-install");
121+
$injector.requireCommand("update", "./commands/update");
121122

122123
$injector.require("iOSLogFilter", "./services/ios-log-filter");

lib/commands/update.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as path from "path";
2+
3+
export class UpdateCommand implements ICommand {
4+
constructor(
5+
private $projectData: IProjectData,
6+
private $platformService: IPlatformService,
7+
private $pluginsService: IPluginsService,
8+
private $logger: ILogger,
9+
private $fs: IFileSystem,
10+
private $options: IOptions,
11+
private $errors: IErrors) { }
12+
13+
public execute(args: string[]): IFuture<void> {
14+
return (() => {
15+
let platforms = this.$platformService.getInstalledPlatforms().wait();
16+
17+
this.$platformService.removePlatforms(platforms).wait();
18+
this.$pluginsService.remove("tns-core-modules").wait();
19+
this.$pluginsService.remove("tns-core-modules-widgets").wait();
20+
21+
this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, "lib")).wait();
22+
this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, "hooks")).wait();
23+
this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, "platforms")).wait();
24+
this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, "node_modules")).wait();
25+
26+
if (args.length === 1) {
27+
for (let platform of platforms) {
28+
this.$platformService.addPlatforms([ platform+"@"+args[0] ]).wait();
29+
}
30+
this.$pluginsService.add("tns-core-modules@" + args[0]).wait();
31+
} else {
32+
this.$platformService.addPlatforms(platforms).wait();
33+
this.$pluginsService.add("tns-core-modules").wait();
34+
}
35+
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
36+
37+
}).future<void>()();
38+
}
39+
40+
public canExecute(args: string[]): IFuture<boolean> {
41+
return (() => {
42+
return args.length < 2 && this.$projectData.projectDir !== "";
43+
}).future<boolean>()();
44+
}
45+
46+
allowedParameters: ICommandParameter[] = [];
47+
}
48+
$injector.registerCommand("update", UpdateCommand);

0 commit comments

Comments
 (0)