Skip to content

Update plugin command added #1947

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
Jul 26, 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
34 changes: 34 additions & 0 deletions docs/man_pages/lib-management/plugin-update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugin update
==========

Usage | Synopsis
------|-------
General | `$ tns plugin update <Plugin(s)>`

<% if(isConsole) { %>Uninstalls and installs the specified plugin(s) and any packages that it depends on.<% } %>
<% if(isHtml) { %>Uninstalls and installs the specified plugin(s) and its dependencies in the local `node_modules` folder, adds it to the `dependencies` section in `package.json`, and prepares the plugin(s) for all installed platforms. If you have not configured any platforms for the project, the NativeScript CLI will prepare the plugin(s) when you add a platform. For more information about working with plugins, see [NativeScript Plugins](https://github.com/NativeScript/nativescript-cli/blob/master/PLUGINS.md).<% } %>

### Attributes

* `<Plugin(s)>` is a valid NativeScript plugin or list of plugins, specified by any of the following. If not specified the command will use currently installed plugins in the project.
* A `<Name>` or `<Name>@<Version>` where `<Name>` is the name of a plugin that is published in the npm registry and `<Version>` is a valid version of this plugin.
* A `<Local Path>` to the directory which contains the plugin, including its `package.json` file.
* A `<Local Path>` to a `.tar.gz` archive containing a directory with the plugin and its `package.json` file.
* A `<URL>` which resolves to a `.tar.gz` archive containing a directory with the plugin and its `package.json` file.
* A `<git Remote URL>` which resolves to a `.tar.gz` archive containing a directory with the plugin and its `package.json` file.

<% if(isHtml) { %>
### Prerequisites

* Verify that the plugin that you want to add contains a valid `package.json` file. Valid `package.json` files contain a `nativescript` section.

### Related Commands

Command | Description
----------|----------
[plugin](plugin.html) | Lets you manage the plugins for your project.
[plugin add](plugin-add.html) | Installs the specified plugin and its dependencies.
[plugin remove](plugin-remove.html) | Uninstalls the specified plugin and its dependencies.
[plugin find](plugin-find.html) | Finds NativeScript plugins in npm.
[plugin search](plugin-search.html) | Finds NativeScript plugins in npm.
<% } %>
2 changes: 2 additions & 0 deletions docs/man_pages/lib-management/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Lets you manage the plugins for your project.
`<Command>` extends the `plugin` command. You can set the following values for this attribute.
* `add` - Installs the specified plugin and its dependencies.
* `remove` - Uninstalls the specified plugin and its dependencies.
* `update` - Uninstalls and installs the specified plugin(s) and its dependencies.
* `find` - Finds NativeScript plugins in npm.
* `search` - Finds NativeScript plugins in npm.

Expand All @@ -22,6 +23,7 @@ Command | Description
----------|----------
[plugin add](plugin-add.html) | Installs the specified plugin and its dependencies.
[plugin remove](plugin-remove.html) | Uninstalls the specified plugin and its dependencies.
[plugin update](plugin-update.html) | Updates the specified plugin(s) and its dependencies.
[plugin find](plugin-find.html) | Finds NativeScript plugins in npm.
[plugin search](plugin-search.html) | Finds NativeScript plugins in npm.
<% } %>
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ $injector.requireCommand("plugin|search", "./commands/plugin/find-plugins");
$injector.requireCommand("plugin|add", "./commands/plugin/add-plugin");
$injector.requireCommand("plugin|install", "./commands/plugin/add-plugin");
$injector.requireCommand("plugin|remove", "./commands/plugin/remove-plugin");
$injector.requireCommand("plugin|update", "./commands/plugin/update-plugin");

$injector.require("doctorService", "./services/doctor-service");
$injector.require("xcprojService", "./services/xcproj-service");
Expand Down
41 changes: 41 additions & 0 deletions lib/commands/plugin/update-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export class UpdatePluginCommand implements ICommand {
constructor(private $pluginsService: IPluginsService,
private $errors: IErrors) { }

execute(args: string[]): IFuture<void> {
return (() => {
let pluginNames = args;

if (!pluginNames || args.length === 0) {
let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
pluginNames = installedPlugins.map(p => p.name);
}

_.each(pluginNames, p => {
this.$pluginsService.remove(p).wait();
this.$pluginsService.add(p).wait();
});
}).future<void>()();
}

canExecute(args: string[]): IFuture<boolean> {
return (() => {
if (!args || args.length === 0) {
return true;
}

let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
let installedPluginNames: string[] = installedPlugins.map(pl => pl.name);

let pluginName = args[0].toLowerCase();
if (!_.some(installedPluginNames, name => name.toLowerCase() === pluginName)) {
this.$errors.failWithoutHelp(`Plugin "${pluginName}" is not installed.`);
}

return true;
}).future<boolean>()();
}

public allowedParameters: ICommandParameter[] = [];
}
$injector.registerCommand("plugin|update", UpdatePluginCommand);