generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bpmn-diagram-exporter.js
42 lines (38 loc) · 1.32 KB
/
bpmn-diagram-exporter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const core = require('@actions/core')
const { convertAll } = require('bpmn-to-image')
const fs = require('fs')
const puppeteer = require('bpmn-to-image/node_modules/puppeteer/lib/cjs/puppeteer/node/install')
async function exportBpmnDiagrams() {
try {
core.info('Downloading puppeteer browser..')
await puppeteer.downloadBrowser()
core.info('Successfully downloaded puppeteer browser')
const sourceDirectory = core.getInput('sourceDirectory', { required: true })
const targetDirectory = core.getInput('targetDirectory', { required: true })
for (const bpmn of fs.readdirSync(sourceDirectory)) {
core.info(
`Exporting BPMN at ${sourceDirectory}/${bpmn} to ${targetDirectory}..`
)
await exportBpmnDiagram(sourceDirectory, targetDirectory, bpmn)
core.info(
`Successfully exported BPMN at ${sourceDirectory}/${bpmn} to ${targetDirectory}`
)
}
} catch (error) {
core.setFailed(`Failed to export BPMN: ${error.message}`)
}
}
async function exportBpmnDiagram(sourceDirectory, targetDirectory, bpmn) {
await convertAll([
{
input: `${sourceDirectory}/${bpmn}`,
outputs: [`${targetDirectory}/${basename(bpmn)}.svg`]
}
])
}
function basename(filename) {
return filename.substring(0, filename.lastIndexOf('.'))
}
module.exports = {
exportBpmnDiagrams
}