Skip to content

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 2 commits into from
Apr 6, 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
8 changes: 5 additions & 3 deletions docs/man_pages/lib-management/plugin-add.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugin add
plugin add
==========

Usage | Synopsis
------|-------
General | `$ tns plugin add <Plugin>`

<% if(isConsole) { %>Installs the specified plugin and any packages that it depends on.<% } %>
<% if(isConsole) { %>Installs the specified plugin and any packages that it depends on.<% } %>
<% if(isHtml) { %>Installs the specified plugin and its dependencies in the local `node_modules` folder, adds it to the `dependencies` section in `package.json`, and prepares the plugin for all installed platforms. If you have not configured any platforms for the project, the NativeScript CLI will prepare the plugin 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
Expand All @@ -28,4 +28,6 @@ Command | Description
----------|----------
[plugin](plugin.html) | Lets you manage the plugins for your project.
[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.
<% } %>
29 changes: 29 additions & 0 deletions docs/man_pages/lib-management/plugin-find.md
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.
<% } %>
8 changes: 5 additions & 3 deletions docs/man_pages/lib-management/plugin-remove.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugin remove
plugin remove
==========

Usage | Synopsis
Expand All @@ -12,11 +12,13 @@ General | `$ tns plugin remove <Plugin>`

* `<Plugin>` is the name of the plugin as listed in its `package.json` file.

<% if(isHtml) { %>
<% 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 find](plugin-find.html) | Finds NativeScript plugins in npm.
[plugin search](plugin-search.html) | Finds NativeScript plugins in npm.
<% } %>
29 changes: 29 additions & 0 deletions docs/man_pages/lib-management/plugin-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugin search
Copy link
Contributor

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 :)

==========

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.
<% } %>
10 changes: 7 additions & 3 deletions docs/man_pages/lib-management/plugin.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugin
plugin
==========

Usage | Synopsis
Expand All @@ -12,12 +12,16 @@ 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.
* `find` - Finds NativeScript plugins in npm.
* `search` - Finds NativeScript plugins in npm.

<% if(isHtml) { %>
<% if(isHtml) { %>
### Related Commands

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 find](plugin-find.html) | Finds NativeScript plugins in npm.
[plugin search](plugin-search.html) | Finds NativeScript plugins in npm.
<% } %>
3 changes: 3 additions & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ $injector.require("broccoliPluginWrapper", "./tools/broccoli/broccoli-plugin-wra

$injector.require("pluginVariablesService", "./services/plugin-variables-service");
$injector.require("pluginsService", "./services/plugins-service");
$injector.requireCommand("plugin|*list", "./commands/plugin/list-plugins");
$injector.requireCommand("plugin|find", "./commands/plugin/find-plugins");
$injector.requireCommand("plugin|search", "./commands/plugin/find-plugins");
$injector.requireCommand("plugin|add", "./commands/plugin/add-plugin");
$injector.requireCommand("plugin|remove", "./commands/plugin/remove-plugin");

Expand Down
100 changes: 100 additions & 0 deletions lib/commands/plugin/find-plugins.ts
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);
47 changes: 47 additions & 0 deletions lib/commands/plugin/list-plugins.ts
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);
2 changes: 1 addition & 1 deletion lib/common
Submodule common updated 2 files
+16 −15 declarations.d.ts
+14 −13 options.ts
4 changes: 3 additions & 1 deletion lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface INodePackageManager {
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
view(packageName: string, propertyName: string): IFuture<any>;
executeNpmCommand(npmCommandName: string, currentWorkingDirectory: string): IFuture<any>;
search(filter: string[], silent: boolean): IFuture<any>;
}

interface INpmInstallationManager {
Expand Down Expand Up @@ -58,6 +59,7 @@ interface ILiveSyncService {
}

interface IOptions extends ICommonOptions {
all: boolean;
baseConfig: string;
client: boolean;
compileSdk: number;
Expand Down Expand Up @@ -267,5 +269,5 @@ interface IProjectNameService {
* @param {IOptions} current command options.
* @return {IFuture<strng>} returns the selected name of the project.
*/
ensureValidName(projectName: string, validateOptions?: {force: boolean}): IFuture<string>;
ensureValidName(projectName: string, validateOptions?: { force: boolean }): IFuture<string>;
}
18 changes: 14 additions & 4 deletions lib/definitions/plugins.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
interface IPluginsService {
add(plugin: string): IFuture<void>; // adds plugin by name, github url, local path and et.
remove(pluginName: string): IFuture<void>; // removes plugin only by name
getAvailable(filter: string[]): IFuture<IDictionary<any>>; // gets all available plugins
prepare(pluginData: IDependencyData, platform: string): IFuture<void>;
getAllInstalledPlugins(): IFuture<IPluginData[]>;
ensureAllDependenciesAreInstalled(): IFuture<void>;
afterPrepareAllPlugins(): IFuture<void>;
getDependenciesFromPackageJson(): IFuture<IPackageJsonDepedenciesResult>
}

interface IPackageJsonDepedenciesResult {
dependencies: IBasePluginData[],
devDependencies?: IBasePluginData[]
}

interface IBasePluginData {
name: string;
version: string;
}

interface IPluginData extends INodeModuleData {
Expand All @@ -14,9 +26,7 @@ interface IPluginData extends INodeModuleData {
pluginPlatformsFolderPath(platform: string): string;
}

interface INodeModuleData {
name: string;
version: string;
interface INodeModuleData extends IBasePluginData {
fullPath: string;
isPlugin: boolean;
moduleInfo: any;
Expand Down Expand Up @@ -70,4 +80,4 @@ interface IPluginVariableData {
defaultValue?: string;
name?: string;
value?: string;
}
}
13 changes: 9 additions & 4 deletions lib/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class NodePackageManager implements INodePackageManager {
} else {
let future = new Future<void>();
npm.load(config, (err: Error) => {
if(err) {
if (err) {
future.throw(err);
} else {
future.return();
Expand All @@ -40,7 +40,7 @@ export class NodePackageManager implements INodePackageManager {
}

public install(packageName: string, pathToSave: string, config?: any): IFuture<any> {
if(this.$options.ignoreScripts) {
if (this.$options.ignoreScripts) {
config = config || {};
config["ignore-scripts"] = true;
}
Expand All @@ -49,7 +49,12 @@ export class NodePackageManager implements INodePackageManager {
}

public uninstall(packageName: string, config?: any, path?: string): IFuture<any> {
return this.loadAndExecute("uninstall", [[packageName]], { config, path});
return this.loadAndExecute("uninstall", [[packageName]], { config, path });
}

public search(filter: string[], silent: boolean): IFuture<any> {
let args = (<any[]>([filter] || [])).concat(silent);
return this.loadAndExecute("search", args);
}

public cache(packageName: string, version: string, config?: any): IFuture<IDependencyData> {
Expand Down Expand Up @@ -86,7 +91,7 @@ export class NodePackageManager implements INodePackageManager {
npm.prefix = oldNpmPath;
}

if(err) {
if (err) {
future.throw(err);
} else {
future.return(data);
Expand Down
Loading