2019-07-23 01:05:11 +02:00
|
|
|
const GoldDigger = require('./src/GoldDigger');
|
2019-07-22 20:58:24 +02:00
|
|
|
const minimist = require('minimist');
|
|
|
|
|
2019-07-22 22:46:05 +02:00
|
|
|
|
2019-07-23 04:05:48 +02:00
|
|
|
const supportedFormat = ['text', 'json'];
|
|
|
|
const ERR_INVALID_FORMAT = `
|
2019-07-22 22:46:05 +02:00
|
|
|
Invalid output
|
2019-07-23 04:05:48 +02:00
|
|
|
Please specify one of those values : "${supportedFormat}"
|
|
|
|
`
|
|
|
|
|
|
|
|
const helpText = `
|
|
|
|
--input or -i pdf file location (required)
|
|
|
|
--debug or -d show debug information (optional - default false)
|
|
|
|
--format or -f format (optional - default "text") - ("${supportedFormat}"):
|
|
|
|
--help or -h display this help message
|
2019-07-22 22:46:05 +02:00
|
|
|
`
|
|
|
|
|
2019-07-22 20:58:24 +02:00
|
|
|
// converts argument to boolean
|
|
|
|
const toBool = (val) => {
|
|
|
|
return val === 'true' || val === 1 || val === true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const argv = minimist(process.argv.slice(2))
|
2019-07-23 04:05:48 +02:00
|
|
|
const help = argv['help'] || argv['h'];
|
|
|
|
if(help) {
|
|
|
|
console.log(helpText);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const fpath = argv['input'] || argv['i'];
|
2019-07-22 20:58:24 +02:00
|
|
|
let debug = argv['debug'] || argv['d'];
|
2019-07-23 04:05:48 +02:00
|
|
|
let format = argv['format'] || argv['f'] || 'text';
|
2019-07-22 20:58:24 +02:00
|
|
|
debug = toBool(debug);
|
2019-07-23 04:05:48 +02:00
|
|
|
if(format && supportedFormat.indexOf(format) < 0) {
|
|
|
|
console.error(ERR_INVALID_FORMAT);
|
2019-07-22 22:46:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-07-22 20:58:24 +02:00
|
|
|
if(!fpath) {
|
2019-07-23 04:05:48 +02:00
|
|
|
console.log(helpText);
|
2019-07-22 20:58:24 +02:00
|
|
|
console.log(argv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(debug) console.log(fpath);
|
2019-07-22 21:26:01 +02:00
|
|
|
|
|
|
|
// configuration
|
|
|
|
const config = {};
|
|
|
|
config.paintFormXObject = false;
|
|
|
|
config.paintImageMaskXObject = false;
|
|
|
|
config.paintJpegXObject = false;
|
2019-07-23 04:05:48 +02:00
|
|
|
config.format = format;
|
2019-07-22 21:26:01 +02:00
|
|
|
|
|
|
|
const gd = new GoldDigger(config);
|
2019-07-22 20:58:24 +02:00
|
|
|
gd.dig(fpath, debug)
|