mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Move output from settings to questions
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import * as commander from 'commander';
|
||||
import path from 'path';
|
||||
import * as parser from './src/parser.js';
|
||||
import * as settings from './src/settings.js';
|
||||
import * as intake from './src/intake.js';
|
||||
import * as writer from './src/writer.js';
|
||||
|
||||
@@ -25,7 +24,7 @@ import * as writer from './src/writer.js';
|
||||
|
||||
// happy goodbye
|
||||
console.log('\nAll done!');
|
||||
console.log('Look for your output files in: ' + path.resolve(settings.output_directory));
|
||||
console.log('Look for your output files in: ' + path.resolve(config.output));
|
||||
})().catch((ex) => {
|
||||
// sad goodbye
|
||||
console.log('\nSomething went wrong, execution halted early.');
|
||||
|
||||
+11
-5
@@ -27,8 +27,10 @@ export async function getConfig() {
|
||||
if (commandLineAnswers.wizard) {
|
||||
console.log('\nStarting wizard...');
|
||||
|
||||
// run wizard for remaining config options
|
||||
const wizardQuestions = questions.all.filter((question) => !(camelcase(question.name) in commandLineAnswers));
|
||||
// run wizard for questions with prompts that were not answered via the command line
|
||||
const wizardQuestions = questions.all.filter((question) => {
|
||||
return question.prompt && !(camelcase(question.name) in commandLineAnswers);
|
||||
});
|
||||
wizardAnswers = await getWizardAnswers(wizardQuestions, commandLineAnswers);
|
||||
} else {
|
||||
console.log('\nSkipping wizard...');
|
||||
@@ -47,6 +49,10 @@ function getCommandLineAnswers(questions) {
|
||||
const option = new commander.Option('--' + question.name + ' <' + question.type + '>', question.description);
|
||||
option.default(question.default);
|
||||
|
||||
if (!question.description) {
|
||||
option.hideHelp();
|
||||
}
|
||||
|
||||
if (question.choices && question.type !== 'boolean') {
|
||||
// let commander handle non-boolean multiple choice validation
|
||||
option.choices(question.choices.map((choice) => choice.value));
|
||||
@@ -68,12 +74,12 @@ function getCommandLineAnswers(questions) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (answers.wizard) {
|
||||
// remove this default answer so the wizard will ask about it later
|
||||
const question = questions.find((question) => camelcase(question.name) === key);
|
||||
if (answers.wizard && question.prompt) {
|
||||
// remove this default answer, allowing the wizard to ask about it later
|
||||
delete answers[key];
|
||||
} else {
|
||||
// normalize and validate default answer
|
||||
const question = questions.find((question) => camelcase(question.name) === key);
|
||||
answers[key] = normalize(value, question.type, (errorMessage) => {
|
||||
// this is formatted to match how commander displays other errors
|
||||
commander.program.error(`error: option '--${question.name} <${question.type}>' argument '${value}' is invalid. ${errorMessage}`);
|
||||
|
||||
+12
-6
@@ -1,12 +1,6 @@
|
||||
import * as inquirer from '@inquirer/prompts';
|
||||
|
||||
export const all = [
|
||||
{
|
||||
name: 'wizard',
|
||||
type: 'boolean',
|
||||
description: 'Use wizard',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
name: 'input',
|
||||
type: 'file-path',
|
||||
@@ -96,5 +90,17 @@ export const all = [
|
||||
}
|
||||
],
|
||||
prompt: inquirer.select
|
||||
},
|
||||
{
|
||||
name: 'wizard',
|
||||
type: 'boolean',
|
||||
description: 'Use wizard',
|
||||
default: true
|
||||
},
|
||||
{
|
||||
name: 'output',
|
||||
type: 'folder-path',
|
||||
description: 'Path to output folder',
|
||||
default: 'output'
|
||||
}
|
||||
];
|
||||
|
||||
@@ -49,6 +49,3 @@ export const filter_post_types = [
|
||||
'wp_global_styles',
|
||||
'wp_navigation'
|
||||
];
|
||||
|
||||
// Output directory.
|
||||
export const output_directory = 'output';
|
||||
|
||||
+1
-1
@@ -171,7 +171,7 @@ async function loadImageFilePromise(imageUrl) {
|
||||
}
|
||||
|
||||
function buildPostPath(post, config) {
|
||||
const outputDir = settings.output_directory;
|
||||
const outputDir = config.output;
|
||||
const type = post.meta.type;
|
||||
const date = post.frontmatter.date;
|
||||
const slug = post.meta.slug;
|
||||
|
||||
Reference in New Issue
Block a user