mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-02 15:16:49 +02:00
Add new parameter to the console client to override the svg configuration in sequence diagrams
This commit is contained in:
34
lib/cli.js
34
lib/cli.js
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user