From 551e6823f47097f1d1bb00114597b5c276fb029a Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Tue, 14 Jan 2020 10:26:50 -0500 Subject: [PATCH] Clean up some messaging --- index.js | 14 +++++++++++++- src/parser.js | 2 +- src/wizard.js | 9 ++++++--- src/writer.js | 8 ++++++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index deec646..6bf0ab0 100644 --- a/index.js +++ b/index.js @@ -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); }); diff --git a/src/parser.js b/src/parser.js index 52b4f8b..ed98818 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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, diff --git a/src/wizard.js b/src/wizard.js index 867ec97..28c9609 100644 --- a/src/wizard.js +++ b/src/wizard.js @@ -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; diff --git a/src/writer.js b/src/writer.js index b5560d3..8aa2f7a 100644 --- a/src/writer.js +++ b/src/writer.js @@ -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) {