Skip to content

Commit

Permalink
Merge pull request #236 from zekth/add-package-support
Browse files Browse the repository at this point in the history
feat: support package.json config
  • Loading branch information
pahen authored Jan 30, 2020
2 parents 2cba3e1 + 0acebb7 commit 0e8951f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ Property | Type | Default | Description
`detectiveOptions` | Object | false | Custom `detective` options for [dependency-tree](https://github.com/dependents/node-dependency-tree) and [precinct](https://github.com/dependents/node-precinct#usage)
`dependencyFilter` | Function | false | Function called with a dependency filepath (exclude substree by returning false)

> Note that when running the CLI it's possible to use a runtime configuration file. The config should placed in `.madgerc` in your project or home folder. Look [here](https://github.com/dominictarr/rc#standards) for alternative locations for the file. Here's an example:
You can use configuration file either in `.madgerc` in your project or home folder or directly in `package.json`. Look [here](https://github.com/dominictarr/rc#standards) for alternative locations for the file.

> .madgerc
```json
{
Expand All @@ -233,6 +235,23 @@ Property | Type | Default | Description
}
```

> package.json
```json
{
"name": "foo",
"version": "0.0.1",
...
"madge": {
"fontSize": "10px",
"graphVizOptions": {
"G": {
"rankdir": "LR"
}
}
}
}
```

# CLI

## Examples
Expand Down
7 changes: 6 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ if (!program.color) {
const log = require('../lib/log');
const output = require('../lib/output');
const madge = require('../lib/api');
const config = Object.assign({}, rc);

let packageConfig = {};
try {
packageConfig = require(path.join(process.cwd(), 'package.json')).madge;
} catch (e) { }
const config = Object.assign(rc, packageConfig);

program.options.forEach((opt) => {
const name = opt.name();
Expand Down

0 comments on commit 0e8951f

Please sign in to comment.