Split out code for args, parsing, and shared

This commit is contained in:
Will Boyd
2019-12-15 13:44:04 -05:00
parent 2024d63aed
commit f9e2bc5b0d
5 changed files with 305 additions and 273 deletions
+48
View File
@@ -0,0 +1,48 @@
const fs = require('fs');
const minimist = require('minimist');
function getConfig() {
let args = process.argv.slice(2);
let config = minimist(args, {
string: [
'input',
'output'
],
boolean: [
'yearmonthfolders',
'yearfolders',
'postfolders',
'prefixdate',
'saveimages',
'addcontentimages'
],
default: {
input: 'export.xml',
output: 'output',
yearmonthfolders: false,
yearfolders: false,
postfolders: true,
prefixdate: false,
saveimages: true,
addcontentimages: false
}
});
// TODO: when wizard is implemented user will be asked to repeat input instead of bombing
if (!checkFileExists(config.input)) {
throw new Error('Input file does not exist.');
}
delete config._;
return config;
}
function checkFileExists(path) {
try {
return fs.existsSync(path);
} catch(ex) {
return false;
}
}
exports.getConfig = getConfig;