Skip to content

Commit cedd197

Browse files
(feature) Add back conversion.
1 parent d5c0496 commit cedd197

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

gulpfile.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
var gulp = require('gulp')
22
var babel = require('gulp-babel')
3+
var es = require('event-stream')
34

45
gulp.task('babel', function () {
5-
return gulp.src('index.js')
6+
return es.concat(
7+
gulp.src('index.js')
68
.pipe(babel())
7-
.pipe(gulp.dest('lib'))
9+
.pipe(gulp.dest('lib')),
10+
gulp.src('index_back.js')
11+
.pipe(babel())
12+
.pipe(gulp.dest('lib')))
813
})
914

1015
gulp.task('default', ['babel'])

index_back.js

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

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.3",
44
"description": "Simple command line tool that converts graphlib graphs to dot files via graphlib-dot",
55
"bin": {
6-
"graphlib2dot": "lib/index.js"
6+
"graphlib2dot": "lib/index.js",
7+
"dot2graphlib": "lib/index_back.js"
78
},
89
"scripts": {
910
"test": "node node_modules/standard/bin/cmd.js"
@@ -30,6 +31,7 @@
3031
"devDependencies": {
3132
"babel": "^5.8.29",
3233
"babel-eslint": "^4.1.3",
34+
"event-stream": "^3.3.2",
3335
"gulp": "^3.9.0",
3436
"gulp-babel": "^5.3.0",
3537
"standard": "^5.4.1"

0 commit comments

Comments
 (0)