Fix undefined answer bug, start on example path

This commit is contained in:
Will Boyd
2025-01-27 14:57:04 -05:00
parent fad9d97488
commit 91073742fa
2 changed files with 34 additions and 18 deletions
+7 -14
View File
@@ -22,13 +22,11 @@ export const all = [
choices: [
{
name: 'Yes',
value: true,
description: '/my-post/index.md'
value: true
},
{
name: 'No',
value: false,
description: '/my-post.md'
value: false
}
],
prompt: inquirer.select
@@ -41,13 +39,11 @@ export const all = [
choices: [
{
name: 'Yes',
value: true,
description: ''
value: true
},
{
name: 'No',
value: false,
description: ''
value: false
}
],
prompt: inquirer.select
@@ -60,18 +56,15 @@ export const all = [
choices: [
{
name: 'Year folders',
value: 'year',
description: ''
value: 'year'
},
{
name: 'Year and month folders',
value: 'year-month',
description: ''
value: 'year-month'
},
{
name: 'No',
value: 'none',
description: ''
value: 'none'
}
],
prompt: inquirer.select
+27 -4
View File
@@ -84,7 +84,6 @@ function getCommandLineAnswers(questions) {
export async function getWizardAnswers(questions) {
const answers = {};
for (const question of questions) {
// this will be set to the normalized answer during validation
let normalizedAnswer;
const promptConfig = {
@@ -106,8 +105,7 @@ export async function getWizardAnswers(questions) {
}
}
// don't care about the return value of prompt() because normalizedAnswer will be used
await question.prompt(promptConfig).catch((ex) => {
const answer = await question.prompt(promptConfig).catch((ex) => {
// exit gracefully if user hits ctrl + c during wizard
if (ex instanceof Error && ex.name === 'ExitPromptError') {
console.log('\nUser quit wizard early.');
@@ -117,7 +115,7 @@ export async function getWizardAnswers(questions) {
}
});
answers[camelcase(question.name)] = normalizedAnswer;
answers[camelcase(question.name)] = normalizedAnswer ?? answer;
}
return answers;
@@ -135,3 +133,28 @@ function normalize(value, type, onError) {
onError(ex.message);
}
}
function buildSamplePath(config) {
const pathSegments = [];
if (config.dateFolders === 'year' || config.dateFolders === 'year-month') {
pathSegments.push('2025');
}
if (config.dateFolders === 'year-month') {
pathSegments.push('01');
}
let slugFragment = 'my-post';
if (config.prefixDate) {
slugFragment = '2025-01-31-' + slugFragment;
}
if (config.postFolders) {
pathSegments.push(slugFragment, 'index.md');
} else {
pathSegments.push(slugFragment + '.md');
}
return '/' + pathSegments.join('/');
}