From edc71934dc6c9a631641a5b361c9096830fbf8e5 Mon Sep 17 00:00:00 2001 From: David Evans Date: Sat, 21 Apr 2018 20:24:54 +0100 Subject: [PATCH] Add commandline tool for generating SVG from code [#32] --- .../contents.xcworkspacedata | 3 + bin/sequence-diagram-svg.js | 46 + index.html | 2 +- lib/sequence-diagram-web.js | 9969 +++++++++++++++++ lib/sequence-diagram-web.min.js | 1 + lib/sequence-diagram.js | 282 +- lib/sequence-diagram.min.js | 2 +- library.htm | 6 +- package.json | 11 +- scripts/rollup.config.js | 8 + scripts/standalone-web.mjs | 17 + scripts/standalone.mjs | 39 +- spec/support/karma.conf.js | 1 + spec/support/rollup.config.js | 1 + 14 files changed, 10375 insertions(+), 13 deletions(-) create mode 100755 bin/sequence-diagram-svg.js create mode 100644 lib/sequence-diagram-web.js create mode 100644 lib/sequence-diagram-web.min.js create mode 100644 scripts/standalone-web.mjs 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 @@ - + - +