mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-08 18:16:44 +02:00
added cli_test_run-samples to test samples from commandline; added --outputSuffix option
This commit is contained in:
@@ -21,6 +21,7 @@ function cli(options) {
|
||||
help: 'h'
|
||||
, png: 'p'
|
||||
, outputDir: 'o'
|
||||
, outputSuffix: 'O'
|
||||
, svg: 's'
|
||||
, verbose: 'v'
|
||||
, phantomPath: 'e'
|
||||
@@ -30,7 +31,7 @@ function cli(options) {
|
||||
, width: 'w'
|
||||
}
|
||||
, 'boolean': ['help', 'png', 'svg', 'verbose']
|
||||
, 'string': ['outputDir']
|
||||
, 'string': ['outputDir', 'outputSuffix']
|
||||
}
|
||||
|
||||
this.errors = []
|
||||
@@ -45,6 +46,7 @@ function cli(options) {
|
||||
, " -s --svg Output SVG instead of PNG (experimental)"
|
||||
, " -p --png If SVG was selected, and you also want PNG, set this flag"
|
||||
, " -o --outputDir Directory to save files, will be created automatically, defaults to `cwd`"
|
||||
, " -O --outputSuffix Suffix to output filenames in front of '.svg' or '.png', defaults to ''"
|
||||
, " -e --phantomPath Specify the path to the phantomjs executable"
|
||||
, " -t --css Specify the path to a CSS file to be included when processing output"
|
||||
, " -c --sequenceConfig Specify the path to the file with the configuration to be applied in the sequence diagram"
|
||||
@@ -79,7 +81,7 @@ cli.prototype.parse = function(argv, next) {
|
||||
}
|
||||
|
||||
// ensure that parameter-expecting options have parameters
|
||||
;['outputDir', 'phantomPath', 'sequenceConfig', 'ganttConfig', 'css'].forEach(function(i) {
|
||||
;['outputDir', 'outputSuffix', 'phantomPath', 'sequenceConfig', 'ganttConfig', 'css'].forEach(function(i) {
|
||||
if(typeof options[i] !== 'undefined') {
|
||||
if (typeof options[i] !== 'string' || options[i].length < 1) {
|
||||
this.errors.push(new Error(i + " expects a value."))
|
||||
|
@@ -12,6 +12,7 @@ module.exports = { process: processMermaid }
|
||||
function processMermaid(files, _options, _next) {
|
||||
var options = _options || {}
|
||||
, outputDir = options.outputDir || process.cwd()
|
||||
, outputSuffix = options.outputSuffix || ""
|
||||
, next = _next || function() {}
|
||||
, phantomArgs = [
|
||||
phantomscript
|
||||
@@ -23,6 +24,7 @@ function processMermaid(files, _options, _next) {
|
||||
, options.ganttConfig
|
||||
, options.verbose
|
||||
, options.width
|
||||
, outputSuffix
|
||||
];
|
||||
|
||||
files.forEach(function(file) {
|
||||
|
@@ -29,7 +29,7 @@ var system = require('system')
|
||||
, webpage = require('webpage')
|
||||
|
||||
var page = webpage.create()
|
||||
, files = system.args.slice(9, system.args.length)
|
||||
, files = system.args.slice(10, system.args.length)
|
||||
, width = system.args[8]
|
||||
|
||||
if(typeof width === 'undefined' || width==='undefined'){
|
||||
@@ -44,6 +44,7 @@ var options = {
|
||||
, ganttConfig: system.args[6] !== 'null' ? JSON.parse(fs.read(system.args[6])) : {}
|
||||
, verbose: system.args[7] === 'true' ? true : false
|
||||
, width: width
|
||||
, outputSuffix: system.args[9]
|
||||
}
|
||||
, log = logger(options.verbose)
|
||||
options.sequenceConfig.useMaxWidth = false;
|
||||
@@ -99,20 +100,20 @@ files.forEach(function(file) {
|
||||
resolveForeignObjects(allElements[i])
|
||||
}
|
||||
|
||||
var outputPath=options.outputDir + fs.separator + filename + options.outputSuffix;
|
||||
if (options.png) {
|
||||
page.viewportSize = {
|
||||
width: ~~oDOM.documentElement.attributes.getNamedItem('width').value
|
||||
, height: ~~oDOM.documentElement.attributes.getNamedItem('height').value
|
||||
}
|
||||
|
||||
page.render(options.outputDir + fs.separator + filename + '.png')
|
||||
page.render(outputPath+'.png')
|
||||
console.log('saved png: ' + filename + '.png')
|
||||
}
|
||||
|
||||
if (options.svg) {
|
||||
var serialize = new XMLSerializer();
|
||||
fs.write(
|
||||
options.outputDir + fs.separator + filename + '.svg'
|
||||
fs.write(outputPath+'.svg'
|
||||
, serialize.serializeToString(oDOM)+'\n'
|
||||
, 'w'
|
||||
)
|
||||
|
@@ -154,7 +154,7 @@ function verifyFiles(expected, dir, t) {
|
||||
}
|
||||
, function(err) {
|
||||
t.notOk(err, 'all files passed')
|
||||
var delete_tmps = false
|
||||
var delete_tmps = true
|
||||
var _rimraf=delete_tmps ? rimraf : function(dir, f) { f(0); }
|
||||
_rimraf(dir, function(rmerr) {
|
||||
t.notOk(rmerr, 'cleaned up')
|
||||
|
62
test/cli_test-run-samples.js
Normal file
62
test/cli_test-run-samples.js
Normal file
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
var exec = require('child_process').exec;
|
||||
var fs = require('fs')
|
||||
, path = require('path')
|
||||
|
||||
var test = require('tape')
|
||||
, async = require('async')
|
||||
, clone = require('clone')
|
||||
, rimraf = require('rimraf')
|
||||
|
||||
var test_dir = "test/fixtures/samples/"
|
||||
|
||||
function exec_mermaid(args, verify) {
|
||||
exec('bin/mermaid.js ' + args,
|
||||
{env: {PATH: "./node_modules/.bin"+path.delimiter+process.env.PATH}},
|
||||
function(error, stdout, stderr) {
|
||||
console.log('error:',error,'\nstdout:\n',stdout,'\nstderr:\n',stderr);
|
||||
verify(error, stdout, stderr);
|
||||
});
|
||||
}
|
||||
|
||||
test('mermaid cli help', function(t) {
|
||||
t.plan(1);
|
||||
var args = [ "--help", ]
|
||||
exec_mermaid(args.join(" "),
|
||||
function(error, stdout, stderr) {
|
||||
t.notOk(error, 'no error code')
|
||||
t.end()
|
||||
});
|
||||
});
|
||||
|
||||
test('sequence (actor) text default svg', function(t) {
|
||||
t.plan(1);
|
||||
var args = [ "--svg",
|
||||
"--outputDir=" + test_dir,
|
||||
test_dir+"sequence_text.mmd",
|
||||
]
|
||||
exec_mermaid(args.join(" "),
|
||||
function(error, stdout, stderr) {
|
||||
t.notOk(error, 'no error code')
|
||||
t.end()
|
||||
});
|
||||
});
|
||||
|
||||
['fo', 'tspan', 'old'].forEach(function(textPlacement) {
|
||||
test('sequence svg text placelment: '+textPlacement, function(t) {
|
||||
t.plan(1);
|
||||
var args = [ "--svg",
|
||||
"--outputDir=" + test_dir,
|
||||
"--outputSuffix=_"+textPlacement,
|
||||
"--sequenceConfig="+test_dir+path.sep+"sequence_text_"+textPlacement+".cfg",
|
||||
test_dir+"sequence_text.mmd",
|
||||
]
|
||||
exec_mermaid(args.join(" "),
|
||||
function(error, stdout, stderr) {
|
||||
t.notOk(error, 'no error code')
|
||||
t.end()
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
6
test/fixtures/samples/sequence_text.mmd
vendored
Normal file
6
test/fixtures/samples/sequence_text.mmd
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
sequenceDiagram
|
||||
participant A as actor
|
||||
participant B as very very very long long long long-long-long text
|
||||
A->>B: hi
|
||||
B-->A:
|
||||
B->>A: hello
|
3
test/fixtures/samples/sequence_text_fo.cfg
vendored
Normal file
3
test/fixtures/samples/sequence_text_fo.cfg
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"textPlacement": "fo"
|
||||
}
|
3
test/fixtures/samples/sequence_text_old.cfg
vendored
Normal file
3
test/fixtures/samples/sequence_text_old.cfg
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"textPlacement": "old"
|
||||
}
|
3
test/fixtures/samples/sequence_text_tspan.cfg
vendored
Normal file
3
test/fixtures/samples/sequence_text_tspan.cfg
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"textPlacement": "tspan"
|
||||
}
|
10
test/fixtures/sequence.mermaid
vendored
10
test/fixtures/sequence.mermaid
vendored
@@ -1,8 +1,8 @@
|
||||
sequenceDiagram
|
||||
Alice->Bob: Hello Bob, how are you?
|
||||
Alice->>Bob: Hello Bob, how are you?
|
||||
Note right of Bob: Bob thinks
|
||||
Bob-->Alice: I am good thanks!
|
||||
Bob-->John the Long: How about you John?
|
||||
Bob-->Alice: Checking with John...
|
||||
Alice->John the Long: Yes... John, how are you?
|
||||
Bob-->>Alice: I am good thanks!
|
||||
Bob-->>John the Long: How about you John?
|
||||
Bob-->>Alice: Checking with John...
|
||||
Alice->>John the Long: Yes... John, how are you?
|
||||
John the Long-->Alice: Better than you!
|
||||
|
Reference in New Issue
Block a user