-
-
Notifications
You must be signed in to change notification settings - Fork 197
Add list dependencies #1661
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
Add list dependencies #1661
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,47 @@ | ||
///<reference path="../../.d.ts"/> | ||
"use strict"; | ||
import { createTable } from "../../common/helpers"; | ||
|
||
export class ListPluginsCommand implements ICommand { | ||
constructor(private $pluginsService: IPluginsService, | ||
private $logger: ILogger) { } | ||
|
||
allowedParameters: ICommandParameter[] = []; | ||
|
||
public execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
let installedPlugins: IPackageJsonDepedenciesResult = this.$pluginsService.getDependenciesFromPackageJson().wait(); | ||
|
||
let headers: string[] = ["Plugin", "Version"]; | ||
let dependenciesData: string[][] = this.createTableCells(installedPlugins.dependencies); | ||
|
||
let dependenciesTable: any = createTable(headers, dependenciesData); | ||
this.$logger.out("Dependencies:"); | ||
this.$logger.out(dependenciesTable.toString()); | ||
|
||
if (installedPlugins.devDependencies && installedPlugins.devDependencies.length) { | ||
let devDependenciesData: string[][] = this.createTableCells(installedPlugins.devDependencies); | ||
|
||
let devDependenciesTable: any = createTable(headers, devDependenciesData); | ||
|
||
this.$logger.out("Dev Dependencies:"); | ||
this.$logger.out(devDependenciesTable.toString()); | ||
} else { | ||
this.$logger.out("There are no dev dependencies."); | ||
} | ||
|
||
let viewDependenciesCommand: string = "npm view <pluginName> grep dependencies".cyan.toString(); | ||
let viewDevDependenciesCommand: string = "npm view <pluginName> grep devDependencies".cyan.toString(); | ||
|
||
this.$logger.warn("NOTE:"); | ||
this.$logger.warn(`If you want to check the dependencies of installed plugin use ${viewDependenciesCommand}`); | ||
this.$logger.warn(`If you want to check the dev dependencies of installed plugin use ${viewDevDependenciesCommand}`); | ||
}).future<void>()(); | ||
} | ||
|
||
private createTableCells(items: IBasePluginData[]): string[][] { | ||
return items.map(item => [item.name, item.version]); | ||
} | ||
} | ||
|
||
$injector.registerCommand("plugin|*list", ListPluginsCommand); |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All my comments for find are applicable here as well :)