-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugin find command to list the nativescript plugins available in npm. The command has --all and --count flags to change the output format.
- Loading branch information
1 parent
2ac44da
commit 2ac30c8
Showing
15 changed files
with
236 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
plugin find | ||
========== | ||
|
||
Usage | Synopsis | ||
---|--- | ||
General | `$ tns plugin find [<PluginName>] [--all] [--count <Count>]` | ||
|
||
Finds NativeScript plugins in npm. | ||
|
||
### Options | ||
* `--all` - Specifies that all results will be shown at once. | ||
* `--count` - Specifies the number of results to show at a time. If not set, the default value is 10. After showing the specified number of results, the CLI will prompt you to continue showing more results or to exit the operation. | ||
|
||
> **NOTE:** You cannot set --all and --count simultaneously. | ||
### Attributes | ||
* `<PluginName>` is the name of plugin that you want to find. When specified the search string in npm will be "`nativescript <PluginName>`". | ||
* `<Count>` is the number of the plugins to display. | ||
|
||
<% if(isHtml) { %> | ||
### 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 search](plugin-search.html) | Finds NativeScript plugins in npm. | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
plugin search | ||
========== | ||
|
||
Usage | Synopsis | ||
---|--- | ||
General | `$ tns plugin search [<PluginName>] [--all] [--count <Count>]` | ||
|
||
Finds NativeScript plugins in npm. | ||
|
||
### Options | ||
* `--all` - Specifies that all results will be shown at once. | ||
* `--count` - Specifies the number of results to show at a time. If not set, the default value is 10. After showing the specified number of results, the CLI will prompt you to continue showing more results or to exit the operation. | ||
|
||
> **NOTE:** You cannot set --all and --count simultaneously. | ||
### Attributes | ||
* `<PluginName>` is the name of plugin that you want to find. When specified the search string in npm will be "`nativescript <PluginName>`". | ||
* `<Count>` is the number of the plugins to display. | ||
|
||
<% if(isHtml) { %> | ||
### 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. | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
///<reference path="../../.d.ts"/> | ||
"use strict"; | ||
import { createTable, isInteractive } from "../../common/helpers"; | ||
import { NATIVESCRIPT_KEY_NAME } from "../../constants"; | ||
import Future = require("fibers/future"); | ||
|
||
export class FindPluginsCommand implements ICommand { | ||
private static COUNT_OF_PLUGINS_TO_DISPLAY: number = 10; | ||
|
||
constructor(private $pluginsService: IPluginsService, | ||
private $errors: IErrors, | ||
private $logger: ILogger, | ||
private $prompter: IPrompter, | ||
private $options: IOptions, | ||
private $progressIndicator: IProgressIndicator) { } | ||
|
||
execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
let filter: string[] = this.prepareFilter(args); | ||
|
||
let pluginsFuture: IFuture<IDictionary<any>> = this.$pluginsService.getAvailable(filter); | ||
if (this.$options.json) { | ||
this.$logger.out(JSON.stringify(pluginsFuture.wait())); | ||
return; | ||
} | ||
|
||
this.$logger.printInfoMessageOnSameLine("Searching npm please be patient..."); | ||
this.$progressIndicator.showProgressIndicator(pluginsFuture, 500).wait(); | ||
let plugins: IDictionary<any> = pluginsFuture.get(); | ||
|
||
this.$logger.out("Available NativeScript plugins"); | ||
this.showPlugins(plugins).wait(); | ||
}).future<void>()(); | ||
} | ||
|
||
canExecute(args: string[]): IFuture<boolean> { | ||
return Future.fromResult(true); | ||
} | ||
|
||
public allowedParameters: ICommandParameter[] = []; | ||
|
||
private showPlugins(plugins: IDictionary<any>): IFuture<void> { | ||
return (() => { | ||
let allPluginsNames: string[] = _.keys(plugins).sort(); | ||
|
||
let count: number = this.$options.count || FindPluginsCommand.COUNT_OF_PLUGINS_TO_DISPLAY; | ||
|
||
if (!isInteractive() || this.$options.all) { | ||
count = allPluginsNames.length; | ||
} | ||
|
||
let data: string[][] = []; | ||
|
||
let pluginsToDisplay: string[] = allPluginsNames.splice(0, count); | ||
let shouldDisplayMorePlugins: boolean = true; | ||
|
||
do { | ||
data = this.createTableCells(plugins, pluginsToDisplay); | ||
|
||
let table: any = this.createPluginsTable(data); | ||
|
||
this.$logger.out(table.toString()); | ||
|
||
pluginsToDisplay = allPluginsNames.splice(0, count); | ||
|
||
if (!pluginsToDisplay || pluginsToDisplay.length < 1) { | ||
return; | ||
} | ||
|
||
shouldDisplayMorePlugins = this.$prompter.confirm("Load more plugins?").wait(); | ||
} while (shouldDisplayMorePlugins); | ||
}).future<void>()(); | ||
} | ||
|
||
private createPluginsTable(data: string[][]): any { | ||
let headers: string[] = ["Plugin", "Version", "Description"]; | ||
|
||
let table: any = createTable(headers, data); | ||
|
||
return table; | ||
} | ||
|
||
private createTableCells(plugins: IDictionary<any>, pluginsToDisplay: string[]): string[][] { | ||
return pluginsToDisplay.map(pluginName => { | ||
let pluginDetails: any = plugins[pluginName]; | ||
return [pluginName, pluginDetails.version, pluginDetails.description || ""]; | ||
}); | ||
} | ||
|
||
private prepareFilter(args: string[]): string[] { | ||
return _(args || []) | ||
.map(arg => arg.toLowerCase()) | ||
.concat(NATIVESCRIPT_KEY_NAME) | ||
.uniq() | ||
.value(); | ||
} | ||
|
||
} | ||
|
||
$injector.registerCommand(["plugin|find", "plugin|search"], FindPluginsCommand); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.