forked from b1f6c1c4/draw.io-export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (67 loc) · 1.6 KB
/
index.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
/* eslint-disable no-console */
const yargs = require("yargs");
const path = require("path");
const run = require("./export");
const { globSync } = require("glob");
process.on("unhandledRejection", (e) => {
console.error(e);
throw e;
});
process.on("uncaughtException", (e) => {
console.error(e);
});
const { argv } = yargs
.usage('$0 --glob "<glob1>" "<glob2>" ... "<globN>"')
.usage("$0 -F png <source1.drawio> <source2.drawio> ... <sourceN.drawio>")
.option("F", {
alias: "fmt",
describe: "output format",
type: "string",
default: "pdf",
})
.choices("F", [
"pdf",
"png",
// "cat-pdf",
// "split-png",
// "split-pdf",
// "split-index-png",
// "split-index-pdf",
// "split-id-png",
// "split-id-pdf",
// "split-name-png",
// "split-name-pdf",
])
.option("G", {
alias: "glob",
describe: "enable glob file matching",
type: "boolean",
default: false,
});
module.exports = async () => {
if (argv._.length < 1) {
return yargs.showHelp();
}
const format = argv.F;
for (let i = 0; i < argv._.length; i++) {
if (argv.G) {
const files = globSync(argv._[i], { absolute: true });
for (const file of files) {
console.log("> Converting %s into %s", file, format);
await run({
file,
format,
path: `${file}.exported.${format}`,
});
}
} else {
const file = argv._[i];
console.log("> Converting %s into %s...", file, format);
await run({
file,
format,
path: `${file}.exported.${format}`,
});
}
}
};