Skip to content

Added tns update command #2137

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

Merged
merged 1 commit into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/man_pages/project/configuration/update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
platform update
==========

Usage | Synopsis
------|-------
Update with the latest version |`$ tns update`
Update with specific version | `$ tns update <version>`

Updates a NativeScript project to the latest (or specified) version.

### Related Commands

Command | Description
----------|----------
[install](install.html) | Installs all platforms and dependencies described in the `package.json` file in the current directory.
[platform add](platform-add.html) | Configures the current project to target the selected platform.
[platform remove](platform-remove.html) | Removes the selected platform from the platforms that the project currently targets.
[platform](platform.html) | Lists all platforms that the project currently targets.
[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.
[platform update](platform-update.html) | Updates the NativeScript runtime for the specified platform.
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@ $injector.require("xmlValidator", "./xml-validator");

$injector.requireCommand("devices", "./commands/devices");
$injector.requireCommand("post-install-cli", "./commands/post-install");
$injector.requireCommand("update", "./commands/update");

$injector.require("iOSLogFilter", "./services/ios-log-filter");
77 changes: 77 additions & 0 deletions lib/commands/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import * as path from "path";
import * as shelljs from "shelljs";

export class UpdateCommand implements ICommand {
constructor(
private $projectData: IProjectData,
private $platformService: IPlatformService,
private $pluginsService: IPluginsService,
private $logger: ILogger,
private $options: IOptions,
private $errors: IErrors) { }

public execute(args: string[]): IFuture<void> {
return (() => {
let folders = [ "lib", "hooks", "platforms", "node_modules" ];
let tmpDir = path.join(this.$projectData.projectDir, ".tmp_backup");

try {
shelljs.rm("-fr", tmpDir);
shelljs.mkdir(tmpDir);
shelljs.cp(path.join(this.$projectData.projectDir, "package.json"), tmpDir);
for (let folder of folders) {
shelljs.cp("-rf", path.join(this.$projectData.projectDir, folder), tmpDir);
}
} catch(error) {
this.$logger.error("Could not backup project folders!");
return;
}

try {
this.executeCore(args, folders);
} catch (error) {
shelljs.cp("-f", path.join(tmpDir, "package.json"), this.$projectData.projectDir);
for (let folder of folders) {
shelljs.rm("-rf", path.join(this.$projectData.projectDir, folder));
shelljs.cp("-fr", path.join(tmpDir, folder), this.$projectData.projectDir);
}
this.$logger.error("Could not update the project!");
} finally {
shelljs.rm("-fr", tmpDir);
}

}).future<void>()();
}

public canExecute(args: string[]): IFuture<boolean> {
return (() => {
return args.length < 2 && this.$projectData.projectDir !== "";
}).future<boolean>()();
}

private executeCore(args: string[], folders: string[]) {
let platforms = this.$platformService.getInstalledPlatforms().wait();

this.$platformService.removePlatforms(platforms).wait();
this.$pluginsService.remove("tns-core-modules").wait();
this.$pluginsService.remove("tns-core-modules-widgets").wait();

for (let folder of folders) {
shelljs.rm("-fr", folder);
}

if (args.length === 1) {
for (let platform of platforms) {
this.$platformService.addPlatforms([ platform+"@"+args[0] ]).wait();
}
this.$pluginsService.add("tns-core-modules@" + args[0]).wait();
} else {
this.$platformService.addPlatforms(platforms).wait();
this.$pluginsService.add("tns-core-modules").wait();
}
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
}

allowedParameters: ICommandParameter[] = [];
}
$injector.registerCommand("update", UpdateCommand);