diff --git a/SequenceDiagram.xcworkspace/contents.xcworkspacedata b/SequenceDiagram.xcworkspace/contents.xcworkspacedata index 1b3961b..5ee6cb9 100644 --- a/SequenceDiagram.xcworkspace/contents.xcworkspacedata +++ b/SequenceDiagram.xcworkspace/contents.xcworkspacedata @@ -16,6 +16,9 @@ + + diff --git a/bin/sequence-diagram-svg.js b/bin/sequence-diagram-svg.js new file mode 100755 index 0000000..af212db --- /dev/null +++ b/bin/sequence-diagram-svg.js @@ -0,0 +1,46 @@ +#!/usr/bin/env node + +const { + headlessTextSizerFactory, + SequenceDiagram, + VirtualDocument, +} = require('../lib/sequence-diagram'); + +function render(code) { + const sd = new SequenceDiagram({ + code, + document: new VirtualDocument(), + namespace: '', + textSizerFactory: headlessTextSizerFactory, + }); + + return sd.dom().outerHTML; +} + +function read(pipe) { + return new Promise((resolve) => { + let all = ''; + pipe.on('readable', () => { + const chunk = pipe.read(); + if(chunk !== null) { + all += chunk; + } + }); + pipe.on('end', () => { + resolve(all); + }); + }); +} + +function getCodeArg() { + if(process.argv.length > 2 && process.argv[2] !== '-') { + return Promise.resolve(process.argv[2]); + } else { + process.stdin.setEncoding('utf8'); + return read(process.stdin); + } +} + +getCodeArg().then((code) => { + process.stdout.write(render(code) + '\n'); +}); diff --git a/index.html b/index.html index 3125c3f..a039543 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,7 @@ - + - +