mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Display command to rerun
This commit is contained in:
@@ -6,6 +6,7 @@ const writer = require('./src/writer');
|
||||
let config = await wizard.getConfig();
|
||||
let posts = await parser.parseFilePromise(config)
|
||||
await writer.writeFilesPromise(posts, config);
|
||||
wizard.displayCommand(config);
|
||||
})().catch(ex => {
|
||||
console.error(ex);
|
||||
});
|
||||
|
||||
+8
-5
@@ -60,17 +60,20 @@ function getPostId(post) {
|
||||
return post.post_id[0];
|
||||
}
|
||||
|
||||
function getPostSlug(post) {
|
||||
return post.post_name[0];
|
||||
}
|
||||
|
||||
function getPostCoverImageId(post) {
|
||||
if (post.postmeta === undefined) return;
|
||||
if (post.postmeta === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let postmeta = post.postmeta.find(postmeta => postmeta.meta_key[0] === '_thumbnail_id');
|
||||
let id = postmeta ? postmeta.meta_value[0] : undefined;
|
||||
return id;
|
||||
}
|
||||
|
||||
function getPostSlug(post) {
|
||||
return post.post_name[0];
|
||||
}
|
||||
|
||||
function getPostTitle(post) {
|
||||
return post.title[0];
|
||||
}
|
||||
|
||||
+36
-14
@@ -68,18 +68,25 @@ async function getConfig() {
|
||||
extendOptionsData();
|
||||
const program = parseCommandLine(process.argv);
|
||||
|
||||
let questions = options.map(option => ({
|
||||
when: option.name !== 'wizard' && program.wizard && !option.isProvided,
|
||||
name: camelcase(option.name),
|
||||
type: option.prompt,
|
||||
message: option.description + '?',
|
||||
default: option.default,
|
||||
|
||||
// these are not used for all option types and that's fine
|
||||
filter: option.coerce,
|
||||
validate: option.validate
|
||||
}));
|
||||
let answers = await inquirer.prompt(questions);
|
||||
let answers;
|
||||
if (program.wizard) {
|
||||
console.log('\nStarting wizard...');
|
||||
let questions = options.map(option => ({
|
||||
when: option.name !== 'wizard' && !option.isProvided,
|
||||
name: camelcase(option.name),
|
||||
type: option.prompt,
|
||||
message: option.description + '?',
|
||||
default: option.default,
|
||||
|
||||
// these are not used for all option types and that's fine
|
||||
filter: option.coerce,
|
||||
validate: option.validate
|
||||
}));
|
||||
answers = await inquirer.prompt(questions);
|
||||
} else {
|
||||
console.log('\nSkipping wizard...');
|
||||
answers = {};
|
||||
}
|
||||
|
||||
const config = { ...program.opts(), ...answers };
|
||||
return config;
|
||||
@@ -114,8 +121,8 @@ function parseCommandLine(argv) {
|
||||
.name('node index.js')
|
||||
.helpOption('-h, --help', 'See the thing you\'re looking at right now')
|
||||
.on('--help', () => {
|
||||
console.log('\nMore documentation at https://github.com/lonekorean/wordpress-export-to-markdown');
|
||||
})
|
||||
console.log('\nMore documentation is at https://github.com/lonekorean/wordpress-export-to-markdown');
|
||||
});
|
||||
|
||||
options.forEach(input => {
|
||||
const flag = '--' + input.name + ' <' + input.type + '>';
|
||||
@@ -150,4 +157,19 @@ function validateFile(value) {
|
||||
return isValid ? true : 'Unable to find file: ' + path.resolve(value);
|
||||
}
|
||||
|
||||
function displayCommand(config) {
|
||||
let command = 'node index.js --wizard=false';
|
||||
options.forEach(option => {
|
||||
if (option.name !== 'wizard') {
|
||||
let configKey = camelcase(option.name);
|
||||
let configValue = config[configKey];
|
||||
if (configValue !== option.default) {
|
||||
command += ' --' + option.name + '=' + configValue;
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log('\nTo skip the wizard and rerun with the same options, run this:\n' + command);
|
||||
}
|
||||
|
||||
exports.getConfig = getConfig;
|
||||
exports.displayCommand = displayCommand;
|
||||
|
||||
Reference in New Issue
Block a user