Skip to content

Commit 047bf49

Browse files
committed
Update plugin command added
1 parent d55b51c commit 047bf49

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
plugin update
2+
==========
3+
4+
Usage | Synopsis
5+
------|-------
6+
General | `$ tns plugin update <Plugin(s)>`
7+
8+
<% if(isConsole) { %>Uninstalls and installs the specified plugin(s) and any packages that it depends on.<% } %>
9+
<% 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).<% } %>
10+
11+
### Attributes
12+
13+
* `<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.
14+
* 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.
15+
* A `<Local Path>` to the directory which contains the plugin, including its `package.json` file.
16+
* A `<Local Path>` to a `.tar.gz` archive containing a directory with the plugin and its `package.json` file.
17+
* A `<URL>` which resolves to a `.tar.gz` archive containing a directory with the plugin and its `package.json` file.
18+
* A `<git Remote URL>` which resolves to a `.tar.gz` archive containing a directory with the plugin and its `package.json` file.
19+
20+
<% if(isHtml) { %>
21+
### Prerequisites
22+
23+
* Verify that the plugin that you want to add contains a valid `package.json` file. Valid `package.json` files contain a `nativescript` section.
24+
25+
### Related Commands
26+
27+
Command | Description
28+
----------|----------
29+
[plugin](plugin.html) | Lets you manage the plugins for your project.
30+
[plugin add](plugin-add.html) | Installs the specified plugin and its dependencies.
31+
[plugin remove](plugin-remove.html) | Uninstalls the specified plugin and its dependencies.
32+
[plugin find](plugin-find.html) | Finds NativeScript plugins in npm.
33+
[plugin search](plugin-search.html) | Finds NativeScript plugins in npm.
34+
<% } %>

docs/man_pages/lib-management/plugin.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Lets you manage the plugins for your project.
1212
`<Command>` extends the `plugin` command. You can set the following values for this attribute.
1313
* `add` - Installs the specified plugin and its dependencies.
1414
* `remove` - Uninstalls the specified plugin and its dependencies.
15+
* `update` - Uninstalls and installs the specified plugin(s) and its dependencies.
1516
* `find` - Finds NativeScript plugins in npm.
1617
* `search` - Finds NativeScript plugins in npm.
1718

@@ -22,6 +23,7 @@ Command | Description
2223
----------|----------
2324
[plugin add](plugin-add.html) | Installs the specified plugin and its dependencies.
2425
[plugin remove](plugin-remove.html) | Uninstalls the specified plugin and its dependencies.
26+
[plugin update](plugin-update.html) | Updates the specified plugin(s) and its dependencies.
2527
[plugin find](plugin-find.html) | Finds NativeScript plugins in npm.
2628
[plugin search](plugin-search.html) | Finds NativeScript plugins in npm.
2729
<% } %>

lib/bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ $injector.requireCommand("plugin|search", "./commands/plugin/find-plugins");
8686
$injector.requireCommand("plugin|add", "./commands/plugin/add-plugin");
8787
$injector.requireCommand("plugin|install", "./commands/plugin/add-plugin");
8888
$injector.requireCommand("plugin|remove", "./commands/plugin/remove-plugin");
89+
$injector.requireCommand("plugin|update", "./commands/plugin/update-plugin");
8990

9091
$injector.require("doctorService", "./services/doctor-service");
9192
$injector.require("xcprojService", "./services/xcproj-service");

lib/commands/plugin/update-plugin.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export class UpdatePluginCommand implements ICommand {
2+
constructor(private $pluginsService: IPluginsService,
3+
private $errors: IErrors) { }
4+
5+
execute(args: string[]): IFuture<void> {
6+
return (() => {
7+
let pluginNames = args;
8+
9+
if (!pluginNames || args.length === 0) {
10+
let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
11+
pluginNames = installedPlugins.map(p => p.name);
12+
}
13+
14+
_.each(pluginNames, p => {
15+
this.$pluginsService.remove(p).wait();
16+
this.$pluginsService.add(p).wait();
17+
});
18+
}).future<void>()();
19+
}
20+
21+
canExecute(args: string[]): IFuture<boolean> {
22+
return (() => {
23+
if (!args || args.length === 0) {
24+
return true;
25+
}
26+
27+
let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
28+
let installedPluginNames: string[] = installedPlugins.map(pl => pl.name);
29+
30+
let pluginName = args[0].toLowerCase();
31+
if (!_.some(installedPluginNames, name => name.toLowerCase() === pluginName)) {
32+
this.$errors.failWithoutHelp(`Plugin "${pluginName}" is not installed.`);
33+
}
34+
35+
return true;
36+
}).future<boolean>()();
37+
}
38+
39+
public allowedParameters: ICommandParameter[] = [];
40+
}
41+
$injector.registerCommand("plugin|update", UpdatePluginCommand);

0 commit comments

Comments
 (0)