1 | # pkg-reflector
|
2 |
|
3 | [![Build Status](https://img.shields.io/circleci/project/zcong1993/pkg-reflector/master.svg?style=flat)](https://circleci.com/gh/zcong1993/pkg-reflector) [![NPM version](https://img.shields.io/npm/v/pkg-reflector.svg?style=flat-square)](https://npmjs.com/package/pkg-reflector) [![npm](https://img.shields.io/npm/dm/pkg-reflector.svg)](https://www.npmjs.com/package/pkg-reflector)
|
4 |
|
5 | > Find and install the npm modules your js files used
|
6 |
|
7 | ---
|
8 |
|
9 | ## New
|
10 |
|
11 | - use flag `--npm` or `--yarn` choose installing tool (default: prefer `yarn` if available)
|
12 |
|
13 | - support alias `prf` for `pkg-reflector`
|
14 |
|
15 | - now support multi files, can be used like `pkg-reflector src/* libs/* *.js`, resolve files using [globby](https://github.com/sindresorhus/globby) and always ignore `**/node_modules/**`
|
16 |
|
17 | ## Install
|
18 |
|
19 | ```sh
|
20 | $ npm install -g pkg-reflector
|
21 | # using yarn
|
22 | $ yarn global add pkg-reflector
|
23 | ```
|
24 |
|
25 | ## Feature
|
26 |
|
27 | Sometimes, you copy some js file from other folder or project, such as `rollup.config.js`,you only want to use it in your current project.
|
28 |
|
29 | If the js file depends some pkgs, you should install the pkgs first by your self, like this:
|
30 |
|
31 | ```sh
|
32 | $ yarn add pkg1 pkg2 pkg3...
|
33 | ```
|
34 |
|
35 | you always get some error when add pkgs cause wrong spelling of the long pkg name, so use `pkg-reflector`, you can do it like this:
|
36 |
|
37 | ```sh
|
38 | $ prf foo.js
|
39 | # then have a coffee
|
40 | ```
|
41 |
|
42 | easy way, isn't it ?
|
43 |
|
44 | - automatic ignore the pkgs your `package.json` exist
|
45 | - automatic ignore node core modules
|
46 | - ignore local file, such as `./index.js`
|
47 | - correct parse `foo/bar` pkgs
|
48 | - can only install es5 modules, es6 modules or all of them
|
49 |
|
50 | ## Usage
|
51 | ```sh
|
52 | $ prf <js file[s]> [options]
|
53 | ```
|
54 |
|
55 | ### simple
|
56 | ```sh
|
57 | $ prf <file>
|
58 | ```
|
59 |
|
60 |
|
61 | will install the pkgs and save `dependence`.
|
62 |
|
63 | ### multi files
|
64 |
|
65 | ```sh
|
66 | $ prf file1 file2 ...
|
67 | ```
|
68 |
|
69 | or use `patterns` all [sindresorhus/globby](https://github.com/sindresorhus/globby) support
|
70 |
|
71 | ```sh
|
72 | $ prf "./**/*.js"
|
73 | ```
|
74 | *Note:* you should pass args as string `"./**/*.js"`, not `./**/*.js`(this will be executed by terminal, if it contains `node_modules` folder maybe cause error `zsh: argument list too long`)
|