Add new parameter to the console client to override the svg configuration in sequence diagrams

This commit is contained in:
jjmr
2015-01-13 16:17:30 +01:00
parent 0b2afb8e71
commit 9b892ef128
8 changed files with 136 additions and 1101 deletions

View File

@@ -23,6 +23,7 @@ function cli(options) {
, svg: 's'
, verbose: 'v'
, phantomPath: 'e'
, sequenceConfig: 'c'
}
, 'boolean': ['help', 'png', 'svg']
, 'string': ['outputDir']
@@ -37,13 +38,14 @@ function cli(options) {
, "file The mermaid description file to be rendered"
, ""
, "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`"
, " -e --phantomPath Specify the path to the phantomjs executable"
, " -h --help Show this message"
, " -v --verbose Show logging"
, " --version Print version and quit"
, " -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`"
, " -e --phantomPath Specify the path to the phantomjs executable"
, " -c --sequenceConfig Specify the path to the file with the configuration to be applied in the sequence diagram"
, " -h --help Show this message"
, " -v --verbose Show logging"
, " --version Print version and quit"
]
return this
@@ -70,7 +72,7 @@ cli.prototype.parse = function(argv, next) {
}
// ensure that parameter-expecting options have parameters
;['outputDir', 'phantomPath'].forEach(function(i) {
;['outputDir', 'phantomPath', 'sequenceConfig'].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."))
@@ -86,6 +88,10 @@ cli.prototype.parse = function(argv, next) {
options.png = true
}
if (options.sequenceConfig) {
options.sequenceConfig = checkConfig(options.sequenceConfig)
}
this.checkPhantom = createCheckPhantom(options.phantomPath)
this.checkPhantom(function(err, path) {
@@ -102,6 +108,16 @@ cli.prototype.parse = function(argv, next) {
}
}
function checkConfig(configPath) {
try {
var text = fs.readFileSync(configPath, 'utf8')
JSON.parse(text)
return text
} catch (e) {
return null;
}
}
function createCheckPhantom(_phantomPath) {
var phantomPath = _phantomPath
, phantomVersion
@@ -128,7 +144,7 @@ function createCheckPhantom(_phantomPath) {
, "details."
].join('\n')
)
next(err)
return
}