-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·71 lines (66 loc) · 2.56 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
#!/usr/bin/env node
var argv = require('commander');
var fs = require('fs');
var opn = require('opn');
var path = require('path');
var qlabHTML = require('./index.js');
var readPkg = require('read-pkg');
argv
.description('Exports contents of the current QLab workspace to an HTML file')
.option('-o, --output [filename]', 'File to save HTML/PDF to (defaults to <workspace name>.html; use - to echo to stdout)')
.option('-p, --open', 'Open HTML file in default browser after saving')
.option('-n, --show-notes', 'Show cue notes')
.option('-d, --dark', 'Use dark theme')
.option('-r, --break-after-cue-lists', 'Force a page break after each cue list/cart when the page is printed')
.option('-b, --indicate-broken-cues', 'Indicate broken cues with a red X')
.option('-s, --hide-status', 'Hide cue status')
.option('-t, --truncate-cue-names', 'Truncate cue names instead of wrapping them (can cause issues with printing)')
.option('--export-pdf', 'Render workspace to PDF instead of HTML (experimental; requires chrome-remote-interface and chrome-runner)')
.option('--landscape', 'Render PDF in landscape mode instead of portrait')
.option('--ms', 'Display waits and durations with millisecond resolution')
.version(readPkg.sync(__dirname).version)
.parse(process.argv);
var options = argv.opts();
options.showStatus = !options.hideStatus;
if (options.output === '-') {
qlabHTML.generateHTML(options, function(html) {
if (options.exportPdf === true) {
qlabHTML.convertHTMLtoPDF(html, options.landscape, function(pdf) {
console.log(pdf.toString());
});
} else {
console.log(html);
}
});
} else {
qlabHTML.exportHTML(options.output, options, function(err, htmlPath, html) {
if (!err) {
if (options.exportPdf === true) {
qlabHTML.convertHTMLtoPDF(html, options.landscape, function(pdf) {
var pathObj = path.parse(htmlPath);
pathObj.ext = '.pdf';
pathObj.base = undefined;
var pdfPath = path.format(pathObj);
fs.unlinkSync(htmlPath);
fs.writeFileSync(pdfPath, pdf);
console.log(`Workspace in PDF saved to ${pdfPath}`);
if (options.open === true) {
opn(pdfPath, {
wait: false
});
}
});
} else {
console.log(`Workspace saved to ${htmlPath}`);
if (options.open === true) {
opn(htmlPath, {
wait: false
});
}
}
} else {
console.error('An error occurred while saving the HTML file.');
console.error(err);
}
});
}