Skip to content

Commit

Permalink
fixed css, sequenceConfig, and ganttConfig being sent as buffer to ph…
Browse files Browse the repository at this point in the history
…antomscript

made verbose cli argument a boolean
  • Loading branch information
ben-page committed Sep 28, 2016
1 parent aa6e15e commit 7044926
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 58 deletions.
40 changes: 21 additions & 19 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function cli(options) {
, css: 't'
, width: 'w'
}
, 'boolean': ['help', 'png', 'svg']
, 'boolean': ['help', 'png', 'svg', 'verbose']
, 'string': ['outputDir']
}

Expand Down Expand Up @@ -94,25 +94,38 @@ cli.prototype.parse = function(argv, next) {
else {
options.png = true
}

if (options.sequenceConfig) {
options.sequenceConfig = checkConfig(options.sequenceConfig)
try {
fs.accessSync(options.sequenceConfig, fs.R_OK)

} catch (err) {
this.errors.push(err)
}
} else {
options.sequenceConfig = null
}

if (options.ganttConfig) {
options.ganttConfig = checkConfig(options.ganttConfig)
try {
fs.accessSync(options.ganttConfig, fs.R_OK)

} catch (err) {
this.errors.push(err)
}
} else {
options.ganttConfig = null
}

if (options.css) {
try {
options.css = fs.readFileSync(options.css, 'utf8')

fs.accessSync(options.css, fs.R_OK)

} catch (err) {
this.errors.push(err)
}
} else {
options.css = fs.readFileSync(path.join(__dirname, '..', 'dist', 'mermaid.css'))
options.css = path.join(__dirname, '..', 'dist', 'mermaid.css')
}

// set svg/png flags appropriately
Expand All @@ -136,17 +149,6 @@ cli.prototype.parse = function(argv, next) {
}
}

function checkConfig(configPath) {
try {
var text = fs.readFileSync(configPath, 'utf8');
JSON.parse(text)
return text
} catch (e) {
console.log(e);
return null;
}
}

function createCheckPhantom(_phantomPath) {
var phantomPath = _phantomPath
, phantomVersion
Expand Down
54 changes: 15 additions & 39 deletions lib/phantomscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var system = require('system')
, fs = require('fs')
, webpage = require('webpage')


var page = webpage.create()
, files = system.args.slice(9, system.args.length)
, width = system.args[8]
Expand All @@ -40,22 +39,14 @@ var options = {
outputDir: system.args[1]
, png: system.args[2] === 'true' ? true : false
, svg: system.args[3] === 'true' ? true : false
, css: system.args[4] !== '' ? system.args[4] : '* { margin: 0; padding: 0; }'
, sequenceConfig: system.args[5]
, ganttConfig: system.args[6]
, css: fs.read(system.args[4])
, sequenceConfig: system.args[5] !== 'null' ? fs.read(system.args[5]) : '{}'
, ganttConfig: system.args[6] !== 'null' ? fs.read(system.args[6]) : '{}'
, verbose: system.args[7] === 'true' ? true : false
, width: width
}
, log = logger(options.verbose)

// If no css is suuplied make sure a fixed witdth is given to the gant renderer
if(system.args[3] !== ''){
if(typeof options.ganttConfig === 'undefined'){
options.ganttConfig = {};
}
options.ganttConfig.useWidth = 1200;
}

page.content = [
'<html>'
, '<head>'
Expand Down Expand Up @@ -229,7 +220,7 @@ function executeInPage(data) {
, width
, height
, confWidth = data.confWidth

toRemove = document.getElementsByClassName('mermaid')
if (toRemove && toRemove.length) {
for (var i = 0, len = toRemove.length; i < len; i++) {
Expand All @@ -242,41 +233,26 @@ function executeInPage(data) {
elContent = document.createTextNode(contents)
el.appendChild(elContent)
//el.innerText = '<b>hello</b>\uD800' //contents;

document.body.appendChild(el)

mermaid.initialize({
sequenceDiagram:{useMaxWidth:false},
flowchart:{useMaxWidth:false},
logLevel:1
});

//console.log('after initialize',sequenceConfig);

if(typeof sequenceConfig !== undefined && sequenceConfig !== 'undefined'){
//sc = document.createElement("script")
//scContent = document.createTextNode('mermaid.sequenceConfig = JSON.parse(' + JSON.stringify(sequenceConfig) + ');')
//sc.appendChild(scContent)

//document.body.appendChild(sc)
mermaid.initialize({
sequenceDiagram:JSON.parse(sequenceConfig)
});
}
mermaid.initialize({
sequenceDiagram:sequenceConfig
});

//console.log('after initialize 2');
if(typeof ganttConfig !== undefined && ganttConfig !== 'undefined'){
sc = document.createElement("script")
scContent = document.createTextNode('mermaid.ganttConfig = JSON.parse(' + JSON.stringify(ganttConfig) + ');')
sc.appendChild(scContent)

document.body.appendChild(sc)
}else{
sc = document.createElement("script")
scContent = document.createTextNode('mermaid.ganttConfig = {useWidth:1200};')
sc.appendChild(scContent)

document.body.appendChild(sc)
}
sc = document.createElement("script")
scContent = document.createTextNode('mermaid.ganttConfig = ' + ganttConfig + ';')
sc.appendChild(scContent)

document.body.appendChild(sc)

mermaid.init();

Expand Down

0 comments on commit 7044926

Please sign in to comment.