mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Split out code for args, parsing, and shared
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user