Skip to content

Commit

Permalink
New option "-d, depth <levels>" to cut off the dependency tree display
Browse files Browse the repository at this point in the history
- Use "commander" for the CLI
- Providing a depth was possibly before, but the feature was not
  documented before, so this is not a breaking change
  • Loading branch information
nknapp committed May 7, 2017
1 parent 3e73cfe commit f820acb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .thought/partials/usage.md.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
Run `analyze-module-size` in your project directory. The output will be something like this:
(Note that the displayed sizes are accumulated from the each module an its dependencies):

{{exec 'node bin/analyze-module-size.js'}}
{{exec 'node bin/analyze-module-size.js'}}

## CLI options

{{exec 'node bin/analyze-module-size.js --help'}}
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ Run `analyze-module-size` in your project directory. The output will be somethin
(Note that the displayed sizes are accumulated from the each module an its dependencies):

```
size: 60k... with-dependencies: 1720k
├── bluebird@3.5.0, 716k, 0 deps
size: 60k... with-dependencies: 1112k
├─┬ globby@6.1.0, 484k, 17 deps
│ ├─┬ glob@7.1.1, 340k, 10 deps
│ │ ├─┬ minimatch@3.0.3, 132k, 3 deps
Expand Down Expand Up @@ -66,14 +65,30 @@ size: 60k... with-dependencies: 1720k
│ └── supports-color@2.0.0, 20k, 0 deps
├─┬ debug@2.6.6, 128k, 1 deps
│ └── ms@0.7.3, 20k, 0 deps
├─┬ commander@2.9.0, 88k, 1 deps
│ └── graceful-readlink@1.0.1, 28k, 0 deps
├── archy@1.0.0, 52k, 0 deps
├── graceful-fs@4.1.11, 48k, 0 deps
├─┬ deep-aplus@1.0.4, 44k, 1 deps
│ └── lodash.isplainobject@4.0.6, 20k, 0 deps
├── progress@2.0.0, 44k, 0 deps
├── p-map@1.1.1, 20k, 0 deps
└── pify@2.3.0, 20k, 0 deps
```

## CLI options

```
Usage: analyze-module-size [options]
Options:
-h, --help output usage information
-V, --version output the version number
-d, --depth <levels> Show only dependencies up to a given depth of recursion
```



# License

Expand Down
17 changes: 10 additions & 7 deletions bin/analyze-module-size.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/usr/bin/env node

var {analyze} = require('../src/index')
const {analyze} = require('../src/index')
const {ProgressHandler} = require('../src/progress')
const program = require('commander')
require('graceful-fs').gracefulify(require('fs'))

var realFs = require('fs')
var gracefulFs = require('graceful-fs')
var {ProgressHandler} = require('../src/progress')
program
.version(require('../package').version)
.usage('[options]')
.option('-d, --depth <levels>', 'Show only dependencies up to a given depth of recursion')
.parse(process.argv)

gracefulFs.gracefulify(realFs)

analyze(process.cwd(), {progress: new ProgressHandler(process.stderr), depth: process.argv[2]})
analyze(process.cwd(), {progress: new ProgressHandler(process.stderr), depth: program.depth})
.then(
(output) => {
return process.stdout.write(output)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"archy": "^1.0.0",
"bluebird": "^3.5.0",
"chalk": "^1.1.3",
"commander": "^2.9.0",
"debug": "^2.6.6",
"deep-aplus": "^1.0.4",
"glob": "^7.1.1",
Expand Down

0 comments on commit f820acb

Please sign in to comment.