Skip to content

Commit

Permalink
bugfix write filetype from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
kaishuu0123 committed Dec 6, 2018
1 parent 94a6b8d commit 7c6e27b
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 8 deletions.
30 changes: 23 additions & 7 deletions bin/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,27 @@ function writeOutputFile(fileType, inputSVG, outputPath) {
}
}

function writeOutputStdout(fileType, inputSVG) {
switch (fileType) {
case 'pdf':
var doc = new PDFDocument();
SVGtoPDF(doc, inputSVG, 0, 0)
doc.pipe(process.stdout)
doc.end();
break;
case 'png':
console.log("WARNING: png format is not supported yet.")
break;
case 'svg':
// PASS THROUGH
default:
process.stdout.write(inputSVG);
}
}


if (process.stdin.isTTY) {
options = yargs
let options = yargs
.required(1, "DOT file is required")
.argv;

Expand All @@ -54,21 +73,18 @@ if (process.stdin.isTTY) {
} else {
var stdin = "";

options = yargs.argv;
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function() {
var chunk = this.read();
if (chunk !== null) {
stdin += chunk;
}
});

process.stdin.on('end', function() {
outputSVG = viz(stdin);
let options = yargs.argv;

if (options.output) {
writeOutputFile(options.type, outputSVG, options.output);
} else {
console.log(outputSVG);
}
writeOutputStdout(options.type, outputSVG);
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphviz-dot",
"version": "0.1.0",
"version": "0.3.0",
"author": "Koki Oyatsu",
"license": "MIT",
"bin": "bin/dot.js",
Expand Down
Loading

0 comments on commit 7c6e27b

Please sign in to comment.