Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hank Chan committed Nov 18, 2018
2 parents f1cf6a6 + 55cfaa8 commit a1abe0f
Show file tree
Hide file tree
Showing 23 changed files with 616 additions and 285 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

**2018-Nov-15:** `v1` published.
177 changes: 130 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# npm-fzf    [![npm](https://img.shields.io/npm/v/npm-fzf.svg)](https://www.npmjs.com/package/npm-fzf) [![Build Status](https://travis-ci.org/hankchanocd/npm-fzf.svg?branch=master)](https://travis-ci.org/hankchanocd/npm-fzf) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![Known Vulnerabilities](https://snyk.io/test/github/hankchanocd/npm-fzf/badge.svg?targetFile=package.json)](https://snyk.io/test/github/hankchanocd/npm-fzf?targetFile=package.json) [![Github issues](https://img.shields.io/github/issues/hankchanocd/npm-fzf.svg)](https://github.com/hankchanocd/npm-fzf/issues)
# npm-fzf
   [![npm](https://img.shields.io/npm/v/npm-fzf.svg)](https://www.npmjs.com/package/npm-fzf) [![Build Status](https://travis-ci.org/hankchanocd/npm-fzf.svg?branch=master)](https://travis-ci.org/hankchanocd/npm-fzf) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![Known Vulnerabilities](https://snyk.io/test/github/hankchanocd/npm-fzf/badge.svg?targetFile=package.json)](https://snyk.io/test/github/hankchanocd/npm-fzf?targetFile=package.json) [![Github issues](https://img.shields.io/github/issues/hankchanocd/npm-fzf.svg)](https://github.com/hankchanocd/npm-fzf/issues)

> Fuzzy search npm modules with `fzf`
> npm with `fzf`
`npm-fzf`, also called `npf`, fuzzy search npm modules with [`fzf`](https://github.com/junegunn/fzf), creating a more fulfilling search experience at terminal.
<br />
<br />
<p align="center">
<img alt="demo animation" width="700" src="https://hankchanocd.github.io/npf/examples/demo.svg" />
</p>
<br />

`npm-fzf`, also called `npf`, fuzzifies some most commonly used npm commands with [`fzf`](https://github.com/junegunn/fzf)i.e. `npm ls`, `npm search`, `npm run`, creating a more fulfilling develop experience at terminal.

## Requirements

(Must): `npf` requires Node 8 for runtime or above.
Must: `npf` requires Node 8 for runtime or above.

(Highly Recommended): [`fzf`](https://github.com/junegunn/fzf) is used heavily by `npf`. If `fzf` is not installed, `npf` will default to a much less capable sibling, [`node-fzf`](https://github.com/talmobi/node-fzf) - `fzf`'s implementation in Node.
Highly Recommended: [`fzf`](https://github.com/junegunn/fzf) is used heavily by `npf`. If `fzf` is not installed, `npf` will default to a much less capable sibling, [`node-fzf`](https://github.com/talmobi/node-fzf) - `fzf`'s implementation in Node.

## CLI

Expand All @@ -19,101 +27,176 @@ $ npm install -g npm-fzf
## Usage

```
Usage: npf [option] [name]
Usage: npf [options] [command]
Fuzzy search npm modules with fzf
npm with fzf
Options:
-v, --version output the version number
# Feature flags
-l, --local list local dependencies, which is also the default feature
-g, --global list global modules
-t, --time show the latest global installs
-s, --scripts list/execute npm scripts
-v, --version output the version number
-d, --details include details to each dependency, but disable the fuzzy mode
-P, --no-preview disable the default fzf preview mode
-F, --no-fuzzy disable the default fuzzy mode and resort to stdout
-h, --help output usage information
Commands:
list|ls [options] npm list with fzf
info [module] npm info with fzf
run npm run with fzf
search <module...> npm search with fzf
```

# Flavor flags
-d, --details include details to each dependency, but disable the default fuzzy mode
-a, --all a flavor flag that shows all available information on any feature flag
-P, --no-preview disable the default fzf preview mode
-F, --no-fuzzy disable the default fuzzy mode and resort to stdout
### `npf search`

-h, --help output usage information
```
Usage: search [options] <module...>
## Examples
npm search with fzf
### Global modules
Options:
-h, --help output usage information
Examples:
npf search <module...>, fuzzy search for npm modules with preview
npf search <module...> --no-preview, fuzzy search for npm modules without preview
npf search <module...> --no-fuzzy, plain search for npm modules
```

```bash
$ npf -g
$ npf search express
$ npf search express react
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/global_demo.png" width="650"></p>
<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/search_demo.png" width="650"></p>

### Recent global installs

A quick refresher on what the heck it's installed/upgraded globally in the recent past
### `npf list`

```
Usage: list|ls [options]
npm list with fzf
Options:
-l, --local list local dependencies, which is also the default feature
-g, --global list global modules
-t, --time show the latest global installs
-h, --help output usage information
Examples:
npf ls, a fzf list with preview of local dependencies
npf ls -t, a fzf list of latest global installs
npf ls -g --no-preview, a fuzzy list with no preview of global installs
npf ls -g --details, a normal, detailed list of global installs
```

### Local dependencies

```bash
$ npf -t
$ npf ls
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/recent_demo.png" width="650"></p>
<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/local_demo.png" width="650"></p>

### Execute module's npm scripts
### Global modules

```bash
$ npf -s
$ npf ls -g
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/scripts_demo.png" width="650"></p>
<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/global_demo.png" width="650"></p>

### Fetch from NPM registry
### Recent global installs

Fetch the module's latest version by default, unless a version is specified
A quick refresher on what the heck it's installed/upgraded globally in the recent past

```bash
$ npf express
$ npf ls -t
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/fetch_module_demo.png" width="650"></p>
<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/recent_demo.png" width="650"></p>


### Turn off preview mode

Preview mode uses `fzf --preview` underneath and is turned on in most cases by default. You can also opt for `--no-preview` to turn off the default preview mode.

```bash
$ npf -t --no-preview
$ npf -g --no-preview
$ npf -l --no-preview
$ npf express --no-preview
$ npf ls -t --no-preview
$ npf ls -g --no-preview
$ npf ls -l --no-preview
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/no-preview-demo.png" width="650"></p>
<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/no_preview_demo.png" width="650"></p>

### Turn off fuzzy mode

Fuzzy mode is by default on. You can also opt for `--no-fuzzy` to turn it off.

```bash
$ npf -t --no-fuzzy
$ npf -g --no-fuzzy
$ npf ls -t --no-fuzzy
$ npf ls -g --no-fuzzy
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/no-fuzzy-demo.png" width="650"></p>
<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/no_fuzzy_demo.png" width="650"></p>

### Details flag

Applied to both local dependencies and global installs

```
$ npf --details
$ npf -g --details
$ npf ls --details
$ npf ls -g --details
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/details_demo.png" width="650"></p>

### `npf run`

```
Usage: run [options]
npm run with fzf
Options:
-h, --help output usage information
Examples:
npf run, execute npm scripts with fzf
npf run --no-fuzzy, execute npm scripts without fzf
```

```bash
$ npf run
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/scripts_demo.png" width="650"></p>

### `npf info`

```
Usage: info [options] [module]
npm info with fzf
Options:
-h, --help output usage information
Examples:
npf info [module], a fuzzy list with preview of a module's dependencies fetched from NPM registry
npf info [module] --no-preview, a fuzzy list of a module's dependencies fetched from NPM registry
npf info [module] --no-fuzzy, a list of a module's dependencies fetched from NPM registry
```

`npf info` fetches the module's latest version by default, unless a version is specified.

It defaults to the current folder if no argument provided.

```bash
$ npf info npm-fzf
```

<p align="center"><img src="https://raw.githubusercontent.com/hankchanocd/npm-fzf/master/images/fetch_module_demo.png" width="650"></p>

## API

`npf` uses [`npmlist`](https://github.com/hankchanocd/npmlist)'s API for getting modules' dependencies. `npf` itself does not expose any API.
Expand All @@ -128,11 +211,11 @@ To perform unit tests and integration tests, simply run `npm test`. (Need Help)

## Changelog

**2018-Nov-15:** `v1` published.
[CHANGELOG](./CHANGELOG.md)

## Contribution

If you have a suggestion, leave it in [Issues](https://github.com/hankchanocd/npm-fzf/issues) for discussion first. I will reply in no more than 3 days. See [here](./CONTRIBUTING.md) on how to contribute.
If you have a suggestion, leave it on [Issues](https://github.com/hankchanocd/npm-fzf/issues) for discussion first. I will reply in no more than 3 days. See [here](./CONTRIBUTING.md) on how to contribute.

[`fzf`](https://github.com/junegunn/fzf) empowers many features that would otherwise be hard to imagine. If you haven't heard of `fzf`, check out junegunn's [`fzf`](https://github.com/junegunn/fzf). Check out my [Dotfiles](https://gitlab.com/hankchanocd/dotfiles/tree/master) to see more use cases of `fzf`.

Expand Down
3 changes: 0 additions & 3 deletions __test__/npmScripts.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const chalk = require('chalk');
const npmScripts = require('./../src/npmScripts');

describe('Test npmScripts', () => {
test('Example test', (done) => {
done();
Expand Down
76 changes: 76 additions & 0 deletions bin/cli.info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';

// Dependencies
const chalk = require('chalk');
const pkgInfo = require('pkginfo');
const cwd = process.cwd();

// Local dependencies
const {
npmRegistry
} = require('./../src/index');

const {
failIfMultipleFlags
} = require('./utils/parseUtils');


module.exports = function infoProgram(program) {

program
.command('info [module]')
.description(`${chalk.grey('npm info')} with fzf`)

// Help
.on('--help', function () {
console.log();
console.log(' Examples:');
console.log(' ' + chalk.blueBright(`npf info [module], ${chalk.white("a fuzzy list with preview of a module's dependencies fetched from NPM registry")}`));
console.log(' ' + chalk.blueBright(`npf info [module] --no-preview, ${chalk.white("a fuzzy list of a module's dependencies fetched from NPM registry")}`));
console.log(' ' + chalk.blueBright(`npf info [module] --no-fuzzy, ${chalk.white("a list of a module's dependencies fetched from NPM registry")}`));
console.log();
})
.action(function (module) {

// Fail if multiple flavor flags given at the same time
failIfMultipleFlags(program, {
positive: ['details'],
negative: ['fuzzy', 'preview'],
errMsg: 'Multiple flavor flags'
});

if (!module) {
let pkg;
try {
pkg = {
exports: {}
};
pkgInfo(pkg, {
dir: cwd,
include: ["name"]
});
module = pkg.exports.name;

} catch (e) {
return console.log(chalk.redBright("No package.json found"));
}

} else if (module === '-') {
return console.log(chalk.white('Incomplete flag')); // i.e. 'npf info -'

} else if (module === '/' || module === '~' || module === '*' || module === '^' || module === '`') {
return console.log(chalk.white('Invalid input')); // typos
}


fetchNPMRegistry(module);

function fetchNPMRegistry(module) {
if (program.all || program.details) return npmRegistry(module).print();

if (!program.fuzzy) return npmRegistry(module).print();

(program.preview) ? npmRegistry(module).fzfPreview(): npmRegistry(module).fzf();
}
});
};
Loading

0 comments on commit a1abe0f

Please sign in to comment.