-
Notifications
You must be signed in to change notification settings - Fork 38
/
cli.js
executable file
·122 lines (90 loc) · 2.67 KB
/
cli.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env node
const meow = require('meow');
const path = require('path');
const {
join: joinPath,
delimiter: pathDelimiter
} = path;
const chalk = require('chalk');
const error = chalk.bold.red;
const {
convertAll
} = require('./');
const cli = meow(`
Usage
$ bpmn-to-image <diagramFile>${pathDelimiter}<outputConfig> ...
Options
diagramFile Path to BPMN diagram
outputConfig List of extension or output file paths
--min-dimensions=<dimensions> Minimum size in pixels (<width>x<height>)
--title=<title> Add explicit <title> to exported image
--no-title Don't display title on exported image
--no-footer Strip title and logo from image
--scale Scale factor for images (1)
Examples
# export to diagram.png
$ bpmn-to-image diagram.bpmn${pathDelimiter}diagram.png
# export diagram.png and /tmp/diagram.pdf
$ bpmn-to-image diagram.bpmn${pathDelimiter}diagram.png,/tmp/diagram.pdf
# export with minimum size of 500x300 pixels
$ bpmn-to-image --min-dimensions=500x300 diagram.bpmn${pathDelimiter}png
`, {
flags: {
minDimensions: {
type: 'string',
default: '400x300'
},
title: {
default: true
},
footer: {
default: true
},
scale: {
default: 1
}
}
});
if (cli.input.length === 0) {
cli.showHelp(1);
}
const conversions = cli.input.map(function(conversion) {
const hasDelimiter = conversion.includes(pathDelimiter);
if (!hasDelimiter) {
console.error(error(` Error: no <diagramFile>${pathDelimiter}<outputConfig> param provided`));
cli.showHelp(1);
}
const [
input,
output
] = conversion.split(pathDelimiter);
const outputs = output.split(',').reduce(function(outputs, file, idx) {
// just extension
if (file.indexOf('.') === -1) {
const baseName = path.basename(idx === 0 ? input : outputs[idx - 1]);
const name = baseName.substring(0, baseName.lastIndexOf('.'));
return [ ...outputs, `${name}.${file}` ];
}
return [ ...outputs, file ];
}, []);
return {
input,
outputs
}
});
const footer = cli.flags.footer;
const title = cli.flags.title === false ? false : cli.flags.title;
const scale = cli.flags.scale !== undefined ? cli.flags.scale : 1;
const [ width, height ] = cli.flags.minDimensions.split('x').map(function(d) {
return parseInt(d, 10);
});
convertAll(conversions, {
minDimensions: { width, height },
title,
footer,
deviceScaleFactor: scale
}).catch(function(e) {
console.error('failed to export diagram(s)');
console.error(e);
process.exit(1);
});