Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 152 lines (101 sloc) 4.889 kb
c730a52 @pahen first commit
authored
1 # MaDGe - Module Dependency Graph
2
3 [![Build Status](https://secure.travis-ci.org/pahen/node-madge.png)](http://travis-ci.org/pahen/node-madge)
4
728541a @pahen Updated README
authored
5 Create graphs from your [CommonJS](http://nodejs.org/api/modules.html) or [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) module dependencies. Could also be useful for finding circular dependencies in your code. Tested on [Node.js](http://nodejs.org/) and [RequireJS](http://requirejs.org/) projects. Dependencies are calculated using static code analysis. CommonJS dependencies are found using James Halliday's [detective](https://github.com/substack/node-detective) and for AMD I'm using some parts copied from James Burke's [RequireJS](https://github.com/jrburke/requirejs) (both are using [UglifyJS](https://github.com/mishoo/UglifyJS)).
c730a52 @pahen first commit
authored
6
1d774ea @pahen Added one more example graph (from the express project)
authored
7 ## Examples
c730a52 @pahen first commit
authored
8 Here's a very simple example of a generated image.
9
1d774ea @pahen Added one more example graph (from the express project)
authored
10 ![](https://github.com/pahen/node-madge/raw/master/examples/small.png)
c730a52 @pahen first commit
authored
11
12 - blue = has dependencies
13 - green = has no dependencies
14 - red = has circular dependencies
15
1d774ea @pahen Added one more example graph (from the express project)
authored
16 Here's an example generated from the [Express](https://github.com/visionmedia/express) project.
17
18 ![](https://github.com/pahen/node-madge/raw/master/examples/express.png)
19
c730a52 @pahen first commit
authored
20 # Installation
21
22 To install as a library:
23
24 $ npm install madge
25
26 To install the command-line tool:
27
28 $ sudo npm -g install madge
29
30 ## Graphviz (optional)
31
32 Only required if you want to generate the visual graphs using [Graphviz](http://www.graphviz.org/).
33
34 ### Mac OS X
35
36 $ sudo port install graphviz
37
38 ### Ubuntu
39
40 $ sudo apt-get install graphviz
41
42 # API
43
44 Coming soon ..
45
46 # CLI
47
48 Usage: madge [options] <file|dir ...>
49
50 Options:
51 -h, --help output usage information
52 -V, --version output the version number
53 -f, --format <name> format to parse (amd/cjs)
54 -o, --output <type> output format (plain/json)
55 -s, --summary show summary of all dependencies
56 -c, --circular show circular dependencies
57 -d, --depends <id> show modules that depends on the given id
58 -x, --exclude <regex> a regular expression for excluding modules
59 -t, --dot output graph in the DOT language
60 -i, --image <filename> write graph to file as a PNG image
61 -l, --layout <name> layout engine to use for image graph (dot/neato/fdp/sfdp/twopi/circo)
62 -b, --break-on-error break on parse errors & missing modules
63 -n, --no-colors skip colors in output and images
64 -r, --read skip scanning folders and read JSON from stdin
edf2c2f @pahen Corrected some stuff from the previous commit that added support for …
authored
65 -C, --config <filename> provide a config file
c730a52 @pahen first commit
authored
66
67
68 ## Examples:
69
471fbd8 @pahen Added two more examples
authored
70 ### List all module dependencies (CommonJS)
71
72 $ madge /path/src
73
74 ### List all module dependencies (AMD)
75
76 $ madge --format amd /path/src
77
c730a52 @pahen first commit
authored
78 ### Finding circular dependencies
79
80 $ madge --circular /path/src
81
82 ### Show modules that depends on a given module
83
84 $ madge --depends 'wheels' /path/src
85
86 ### Excluding modules
87
728541a @pahen Updated README
authored
88 $ madge --exclude '^foo$|^bar$|^tests' /path/src
c730a52 @pahen first commit
authored
89
90 ### Save graph as a PNG image (graphviz required)
91
728541a @pahen Updated README
authored
92 $ madge --image graph.png /path/src
c730a52 @pahen first commit
authored
93
94 ### Save graph as a [DOT](http://en.wikipedia.org/wiki/DOT_language) file for further processing (graphviz required)
95
96 $ madge --dot /path/src > graph.gv
97
98 ### Pipe predefined results (the example image was produced with the following command)
99
100 $ cat << EOF | madge --read --image example.png
101 {
102 "a": ["b", "c", "d"],
103 "b": ["c"],
104 "c": [],
105 "d": ["a"]
106 }
107 EOF
108
edf2c2f @pahen Corrected some stuff from the previous commit that added support for …
authored
109 ## Config (use with --config)
110
111 {
112 "format": "amd",
113 "image": "dependencyMap.png",
114 "fontFace": "Arial",
115 "fontSize": "14px",
116 "imageColors": {
117 "noDependencies" : "#0000ff",
118 "dependencies" : "#00ff00",
119 "circular" : "#bada55",
120 "edge" : "#666666",
121 "bgcolor": "#ffffff"
122 }
123 }
124
c730a52 @pahen first commit
authored
125 # Running tests
126
127 $ npm test
128
129 # License
130
131 (The MIT License)
132
133 Copyright (c) 2012 Patrik Henningsson &lt;patrik.henningsson@gmail.com&gt;
134
135 Permission is hereby granted, free of charge, to any person obtaining
136 a copy of this software and associated documentation files (the
137 'Software'), to deal in the Software without restriction, including
138 without limitation the rights to use, copy, modify, merge, publish,
139 distribute, sublicense, and/or sell copies of the Software, and to
140 permit persons to whom the Software is furnished to do so, subject to
141 the following conditions:
142
143 The above copyright notice and this permission notice shall be
144 included in all copies or substantial portions of the Software.
145
146 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
147 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
148 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
149 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
150 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
151 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
152 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.