Files
wordpress-export-to-markdown/src/wizard.js
T
2019-12-15 13:44:04 -05:00

48 lines
898 B
JavaScript

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;