Skip to content

Commit

Permalink
Add support for combining --circular and --dot
Browse files Browse the repository at this point in the history
  • Loading branch information
pahen committed Oct 1, 2020
1 parent f9863aa commit d2ce3f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ madge('path/to/app.js').then((res) => {
});
```

#### .dot()
#### .dot([circularOnly: boolean])

> Returns a `Promise` resolved with a DOT representation of the module dependency graph.
> Returns a `Promise` resolved with a DOT representation of the module dependency graph. Set `circularOnly` to only include circular dependencies.
```javascript
const madge = require('madge');
Expand Down
14 changes: 7 additions & 7 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ function createOutputFromOptions(program, res) {
});
}

if (program.dot) {
return res.dot(program.circular).then((output) => {
process.stdout.write(output);
return res;
});
}

if (program.circular) {
const circular = res.circular();

Expand All @@ -261,11 +268,4 @@ function createOutputFromOptions(program, res) {

return res;
}

if (program.dot) {
return res.dot().then((output) => {
process.stdout.write(output);
return res;
});
}
}
9 changes: 7 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,15 @@ class Madge {
/**
* Return the module dependency graph as DOT output.
* @api public
* @param {Boolean} circularOnly
* @return {Promise}
*/
dot() {
return graph.dot(this.obj(), this.circular(), this.config);
dot(circularOnly) {
return graph.dot(
circularOnly ? this.circularGraph() : this.obj(),
this.circular(),
this.config
);
}

/**
Expand Down

0 comments on commit d2ce3f7

Please sign in to comment.