Clean up some messaging

This commit is contained in:
Will Boyd
2020-01-14 10:26:50 -05:00
parent c428cd574c
commit 551e6823f4
4 changed files with 26 additions and 7 deletions
+13 -1
View File
@@ -1,12 +1,24 @@
const path = require('path');
const wizard = require('./src/wizard');
const parser = require('./src/parser');
const writer = require('./src/writer');
(async () => {
// parse any command line arguments and run wizard
let config = await wizard.getConfig();
// parse data from XML and do Markdown translations
let posts = await parser.parseFilePromise(config)
// write files, downloading images as needed
await writer.writeFilesPromise(posts, config);
wizard.displayCommand(config);
// happy goodbye
console.log('\nAll done!');
console.log('Look for your output files in: ' + path.resolve(config.output));
})().catch(ex => {
// sad goodbye
console.log('\nSomething went wrong, execution halted early.');
console.error(ex);
});
+1 -1
View File
@@ -6,7 +6,7 @@ const shared = require('./shared');
const translator = require('./translator');
async function parseFilePromise(config) {
console.log('\nParsing export file...');
console.log('\nParsing...');
const content = await fs.promises.readFile(config.input, 'utf8');
const data = await xml2js.parseStringPromise(content, {
trim: true,
+6 -3
View File
@@ -5,6 +5,8 @@ const fs = require('fs');
const inquirer = require('inquirer');
const path = require('path');
const package = require('../package.json');
// all user options for command line and wizard are declard here
const options = [
// wizard must always be first
@@ -119,6 +121,7 @@ function parseCommandLine(argv) {
// setup for help output
commander
.name('node index.js')
.version('v' + package.version, '-v, --version', 'Display version number')
.helpOption('-h, --help', 'See the thing you\'re looking at right now')
.on('--help', () => {
console.log('\nMore documentation is at https://github.com/lonekorean/wordpress-export-to-markdown');
@@ -157,7 +160,7 @@ function validateFile(value) {
return isValid ? true : 'Unable to find file: ' + path.resolve(value);
}
function displayCommand(config) {
function getCommand(config) {
let command = 'node index.js --wizard=false';
options.forEach(option => {
if (option.name !== 'wizard') {
@@ -168,8 +171,8 @@ function displayCommand(config) {
}
}
});
console.log('\nTo skip the wizard and rerun with the same options, run this:\n' + command);
return command;
}
exports.getConfig = getConfig;
exports.displayCommand = displayCommand;
exports.getCommand = getCommand;
+6 -2
View File
@@ -83,8 +83,12 @@ async function writeImageFilesPromise(posts, config) {
});
});
console.log('\nSaving images...');
await processPayloadsPromise(payloads, loadImageFilePromise);
if (payloads.length > 0) {
console.log('\nDownloading and saving images...');
await processPayloadsPromise(payloads, loadImageFilePromise);
} else {
console.log('\nNo images to download and save...');
}
}
async function loadImageFilePromise(imageUrl) {