mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-13 19:56:36 +09:00
Clean up some messaging
This commit is contained in:
@@ -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
@@ -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
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user