diff --git a/index.js b/index.js index 70349a6..7a5c7a0 100644 --- a/index.js +++ b/index.js @@ -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.'); diff --git a/src/intake.js b/src/intake.js index aedf47e..63763e2 100644 --- a/src/intake.js +++ b/src/intake.js @@ -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}`); diff --git a/src/questions.js b/src/questions.js index 44f475d..6269338 100644 --- a/src/questions.js +++ b/src/questions.js @@ -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' } ]; diff --git a/src/settings.js b/src/settings.js index 28ef891..58e67b3 100644 --- a/src/settings.js +++ b/src/settings.js @@ -49,6 +49,3 @@ export const filter_post_types = [ 'wp_global_styles', 'wp_navigation' ]; - -// Output directory. -export const output_directory = 'output'; diff --git a/src/writer.js b/src/writer.js index 52af1de..6a902eb 100644 --- a/src/writer.js +++ b/src/writer.js @@ -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;