Skip to content
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

feat: support package.json config #236

Merged
merged 2 commits into from
Jan 30, 2020
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
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