2017-04-13 20:50:22 +08:00
|
|
|
var path = require('path')
|
|
|
|
var spawn = require('child_process').spawn
|
2014-12-20 17:18:38 -08:00
|
|
|
|
|
|
|
var mkdirp = require('mkdirp')
|
|
|
|
|
|
|
|
var phantomscript = path.join(__dirname, 'phantomscript.js')
|
|
|
|
|
|
|
|
module.exports = { process: processMermaid }
|
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
function processMermaid (files, _options, _next) {
|
2017-04-13 20:50:22 +08:00
|
|
|
var options = _options || {}
|
|
|
|
var outputDir = options.outputDir || process.cwd()
|
|
|
|
var outputSuffix = options.outputSuffix || ''
|
|
|
|
var next = _next || function () { }
|
|
|
|
var phantomArgs = [
|
|
|
|
phantomscript,
|
|
|
|
outputDir,
|
|
|
|
options.png,
|
|
|
|
options.svg,
|
|
|
|
options.css,
|
|
|
|
options.sequenceConfig,
|
|
|
|
options.ganttConfig,
|
|
|
|
options.verbose,
|
|
|
|
options.width,
|
|
|
|
outputSuffix
|
|
|
|
]
|
2017-04-11 22:14:25 +08:00
|
|
|
|
|
|
|
files.forEach(function (file) {
|
2014-12-20 17:18:38 -08:00
|
|
|
phantomArgs.push(file)
|
|
|
|
})
|
2016-03-23 20:34:44 +01:00
|
|
|
|
2017-04-11 22:14:25 +08:00
|
|
|
mkdirp(outputDir, function (err) {
|
2014-12-20 17:18:38 -08:00
|
|
|
if (err) {
|
|
|
|
throw err
|
|
|
|
}
|
2017-04-13 20:50:22 +08:00
|
|
|
var phantom = spawn(options.phantomPath, phantomArgs)
|
2014-12-20 17:18:38 -08:00
|
|
|
|
|
|
|
phantom.on('exit', next)
|
|
|
|
|
|
|
|
phantom.stderr.pipe(process.stderr)
|
|
|
|
phantom.stdout.pipe(process.stdout)
|
|
|
|
})
|
|
|
|
}
|