diff --git a/docs/man_pages/lib-management/plugin-update.md b/docs/man_pages/lib-management/plugin-update.md new file mode 100644 index 0000000000..7126433933 --- /dev/null +++ b/docs/man_pages/lib-management/plugin-update.md @@ -0,0 +1,34 @@ +plugin update +========== + +Usage | Synopsis +------|------- +General | `$ tns plugin update ` + +<% 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 + +* `` 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 `` or `@` where `` is the name of a plugin that is published in the npm registry and `` is a valid version of this plugin. + * A `` to the directory which contains the plugin, including its `package.json` file. + * A `` to a `.tar.gz` archive containing a directory with the plugin and its `package.json` file. + * A `` which resolves to a `.tar.gz` archive containing a directory with the plugin and its `package.json` file. + * A `` 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. +<% } %> diff --git a/docs/man_pages/lib-management/plugin.md b/docs/man_pages/lib-management/plugin.md index c22f74beef..22cfa5906f 100644 --- a/docs/man_pages/lib-management/plugin.md +++ b/docs/man_pages/lib-management/plugin.md @@ -12,6 +12,7 @@ Lets you manage the plugins for your project. `` 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. @@ -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. <% } %> diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts index e87ebd8719..aa80ce5b96 100644 --- a/lib/bootstrap.ts +++ b/lib/bootstrap.ts @@ -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"); diff --git a/lib/commands/plugin/update-plugin.ts b/lib/commands/plugin/update-plugin.ts new file mode 100644 index 0000000000..b3e6b49c1c --- /dev/null +++ b/lib/commands/plugin/update-plugin.ts @@ -0,0 +1,41 @@ +export class UpdatePluginCommand implements ICommand { + constructor(private $pluginsService: IPluginsService, + private $errors: IErrors) { } + + execute(args: string[]): IFuture { + 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()(); + } + + canExecute(args: string[]): IFuture { + 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()(); + } + + public allowedParameters: ICommandParameter[] = []; +} +$injector.registerCommand("plugin|update", UpdatePluginCommand);