-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmermaid-action.js
More file actions
24 lines (17 loc) · 942 Bytes
/
mermaid-action.js
File metadata and controls
24 lines (17 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const run = require('child_process').execSync
const fs = require('fs')
const path = require('path')
module.exports = function (content, options) {
let inputFile = path.join(process.cwd(), `.tmp-pmcf-input-${Date.now()}`)
let outputFile = path.join(process.cwd(), `.tmp-pmcf-output-${Date.now()}.${options.format}`)
fs.writeFileSync(inputFile, content)
let resolved = path.resolve(__dirname, 'node_modules', '.bin', 'mmdc')
let cmd = `${resolved} -i "${inputFile}" -o "${outputFile}" -e "${options.format}" -b "${options.background}" -t "${options.theme}" -w "${options.width}" -s ${options.scale} -f`
run(cmd)
let fileData = options.format.match(/svg/i)
? fs.readFileSync(outputFile, 'utf8')
: fs.readFileSync(outputFile)
if (fs.existsSync(inputFile)) fs.unlink(inputFile, err => err)
if (fs.existsSync(outputFile)) fs.unlink(outputFile, err => err)
return fileData
}