Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 53b2dea2d1fece5796e2fc042107d56f55cc9828 0 parents
@tj tj authored
1  .gitignore
@@ -0,0 +1 @@
+node_modules
4 .npmignore
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
5 History.md
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
7 Makefile
@@ -0,0 +1,7 @@
+
+test:
+ @./node_modules/.bin/mocha \
+ --require should \
+ --reporter spec
+
+.PHONY: test
45 Readme.md
@@ -0,0 +1,45 @@
+
+# component-graph
+
+ Dependency graphs for component(1).
+
+## Installation
+
+ $ npm install -g component-graph
+
+Also requires graphviz:
+
+ $ brew install grapviz
+
+## Usage
+
+```
+
+ Usage: component-graph [options]
+
+ Options:
+
+ -h, --help output usage information
+ -t, --type <name> graph type [neato|twopi|fdp|dot]
+ -f, --format <name> set output format [png]
+ -o, --out <path> output to the <path> [out.png]
+
+```
+
+## Types
+
+### dot
+
+ ![](http://f.cl.ly/items/2H0K2h0I0B460V0A2G3n/dot.png)
+
+### twopi
+
+ ![](http://f.cl.ly/items/3g3I283o3U0K0F0X3o3m/twopi.png)
+
+### fdp
+
+ ![](http://f.cl.ly/items/3T1N373F1h1k1L0Z0s1G/fdp.png)
+
+## License
+
+ MIT
96 bin/component-graph
@@ -0,0 +1,96 @@
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var program = require('commander')
+ , component = require('component')
+ , spawn = require('child_process').spawn
+ , path = require('path')
+ , resolve = path.resolve
+ , lookup = component.lookup
+
+// parse argv
+
+program
+ .option('-t, --type <name>', 'graph type [neato|twopi|fdp|dot]', 'dot')
+ .option('-f, --format <name>', 'set output format [png]', 'png')
+ .option('-o, --out <path>', 'output to the <path> [out.png]', 'out.png')
+ .parse(process.argv);
+
+/**
+ * Return the dependency tree of the given config `file`.
+ *
+ * @param {String} file
+ * @param {Array} paths
+ * @return {Object}
+ */
+
+function tree(file, paths, depth){
+ depth = depth || 0;
+ var conf = require(resolve(file));
+ var deps = Object.keys(conf.dependencies || {});
+ var node = {};
+
+ // local deps
+ if (conf.local) deps = deps.concat(conf.local);
+
+ // lookup paths
+ paths = (paths || ['components']).concat(conf.paths);
+
+ // label
+ node.label = conf.name;
+
+ // --depth n
+ if (++depth > program.depth) return node;
+
+ // dependencies
+ node.nodes = deps.map(function(dep){
+ var dep = dep.replace('/', '-');
+ var file = lookup(dep, paths);
+ if (!file) throw new Error('failed to resolve location of "' + dep + '"');
+ file = resolve(file, 'component.json');
+ return tree(file, paths, depth);
+ });
+
+ return node;
+}
+
+/**
+ * Output graph.
+ *
+ * @param {Object} node
+ * @param {Object} stream
+ */
+
+function graph(node, stream) {
+ if (node.nodes) {
+ node.nodes.forEach(function(dep){
+ stream.write(' "' + node.label + '" -> "' + dep.label + '" [style=dotted];\n');
+ graph(dep, stream);
+ });
+ }
+}
+
+/**
+ * Indent `str`.
+ */
+
+function indent(str) {
+ return str.replace(/^/gm, ' ');
+}
+
+// output tree
+
+var tree = tree('component.json');
+var proc = spawn(program.type, ['-T' + program.format, '-o', program.out]);
+var stream = proc.stdin;
+
+stream.write('digraph {\n');
+stream.write(' node [style=filled, fillcolor=white, nodesep=2.0];\n');
+stream.write(' graph [overlap=false];\n');
+stream.write('\n');
+graph(tree, stream);
+stream.write('}\n');
+stream.end();
19 package.json
@@ -0,0 +1,19 @@
+{
+ "name": "component-graph",
+ "version": "0.0.1",
+ "description": "Dependency graphs for component(1)",
+ "keywords": ["component", "graph", "dep", "deps", "dependencies"],
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "repository": { "type": "git", "url": "git://github.com/visionmedia/component-graph.git" },
+ "dependencies": {
+ "commander": "1.1.1",
+ "component": "0.10.1"
+ },
+ "devDependencies": {
+ "mocha": "*",
+ "should": "*"
+ },
+ "bin": {
+ "component-graph": "bin/component-graph"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.