Skip to content

Commit af66bb6

Browse files
committedJan 5, 2016
Initial commit. CLI.
1 parent e987818 commit af66bb6

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
lib

‎.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
index.js

‎README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# graphlib2dot
2+
3+
This command line tool takes a graphlib JSON document and converts it into a
4+
dot file.
5+
6+
## Installation
7+
8+
Install it globally with npm
9+
10+
```
11+
npm install -g graphlib2dot
12+
```
13+
14+
## Usage
15+
16+
Simply pipe your JSON document into the program:
17+
18+
```
19+
cat graph.json | graphlib2dot
20+
```
21+
22+
Or specify a file:
23+
24+
```
25+
graphlib2dot -f graph.json
26+
```
27+
28+
You can create a JSON representation of your graphlib Graph via
29+
`graphlib.json.write`. More info [here](https://github.com/cpettitt/graphlib/wiki/API-Reference#json-write).

‎gulpfile.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var gulp = require('gulp')
2+
var babel = require('gulp-babel')
3+
4+
gulp.task('babel', function () {
5+
return gulp.src('index.js')
6+
.pipe(babel())
7+
.pipe(gulp.dest('lib'))
8+
})
9+
10+
gulp.task('default', ['babel'])

‎index.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* global __dirname, process */
2+
3+
import program from 'commander'
4+
import fs from 'fs'
5+
import getStdin from 'get-stdin'
6+
import graphlib from 'graphlib'
7+
import gdot from 'graphlib-dot'
8+
9+
program
10+
.version(JSON.parse(fs.readFileSync(__dirname + '/../package.json'))['version'])
11+
.option('-f, --graphfile <graphfile>', 'Set graph file to parse. If none is given stdin is read')
12+
.parse(process.argv)
13+
14+
var processGraph = str => {
15+
var graph = graphlib.json.read(JSON.parse(str))
16+
var dot = gdot.write(graph)
17+
return dot
18+
}
19+
20+
if (program.graphfile) {
21+
var str = fs.readFileSync(program.graphfile)
22+
console.log(processGraph(str))
23+
} else {
24+
getStdin().then(str => {
25+
try {
26+
console.log(processGraph(str))
27+
} catch (e) {
28+
console.error('Error while processing: ', e)
29+
}
30+
})
31+
}

‎package.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "graphlib2dot",
3+
"version": "1.0.0",
4+
"description": "Simple command line tool that converts graphlib graphs to dot files via graphlib-dot",
5+
"bin": {"graphlib2dot": "lib/index.js"},
6+
"scripts": {
7+
"test": "node node_modules/standard/bin/cmd.js"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/LittleHelicase/graphlib2dot.git"
12+
},
13+
"keywords": [
14+
"Graph",
15+
"Visualization"
16+
],
17+
"author": "Maximilian Klein",
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/LittleHelicase/graphlib2dot/issues"
21+
},
22+
"dependencies": {
23+
"commander": "^2.9.0",
24+
"get-stdin": "^5.0.1",
25+
"graphlib": "^2.0.0",
26+
"graphlib-dot": "^0.6.2"
27+
},
28+
"devDependencies": {
29+
"babel": "^5.8.29",
30+
"babel-eslint": "^4.1.3",
31+
"gulp": "^3.9.0",
32+
"gulp-babel": "^5.3.0",
33+
"standard": "^5.4.1"
34+
},
35+
"homepage": "https://github.com/LittleHelicase/graphlib2dot#readme"
36+
}

0 commit comments

Comments
 (0)
Please sign in to comment.