From df5731985df287ee40ac648916a51777288145b5 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Thu, 6 Feb 2025 13:56:27 -0500 Subject: [PATCH] Logging refactor, quote-date, type count fix --- src/parser.js | 7 ++----- src/questions.js | 5 +++++ src/writer.js | 25 ++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/parser.js b/src/parser.js index b143db0..2a3c95a 100644 --- a/src/parser.js +++ b/src/parser.js @@ -62,16 +62,13 @@ function collectPosts(channelData, postTypes, config) { .filter(postData => !(postType === 'page' && postData.post_name[0] === 'sample-page')) .map(postData => buildPost(postData, turndownService, config)); - if (postTypes.length > 1) { - console.log(`${postsForType.length} "${postType}" posts found.`); + if (postsForType.length > 0) { + console.log(`${postsForType.length} posts of type "${postType}" found.`); } allPosts.push(...postsForType); }); - if (postTypes.length === 1) { - console.log(allPosts.length + ' posts found.'); - } return allPosts; } diff --git a/src/questions.js b/src/questions.js index bf31cbe..0ae9f62 100644 --- a/src/questions.js +++ b/src/questions.js @@ -135,6 +135,11 @@ export const all = [ type: 'string', default: 'utc' }, + { + name: 'quote-date', + type: 'boolean', + default: false + }, { name: 'strict-ssl', type: 'boolean', diff --git a/src/writer.js b/src/writer.js index 4b0df4e..17a28a1 100644 --- a/src/writer.js +++ b/src/writer.js @@ -18,10 +18,10 @@ async function processPayloadsPromise(payloads, loadFunc, config) { try { const data = await loadFunc(payload.item, config); await writeFile(payload.destinationPath, data); - console.log(chalk.green('[OK]') + ' ' + payload.name); + logPayloadResult(payload); resolve(); } catch (ex) { - console.log(chalk.red('[FAILED]') + ' ' + payload.name + ' ' + chalk.red('(' + ex.message + ')')); + logPayloadResult(payload, ex.message); reject(); } }, payload.delay); @@ -54,7 +54,8 @@ async function writeMarkdownFilesPromise(posts, config) { } else { const payload = { item: post, - name: post.type + ' - ' + post.slug, + type: post.type, + name: post.slug, destinationPath, delay }; @@ -88,6 +89,10 @@ async function loadMarkdownFilePromise(post, config) { } else { outputValue = config.includeTimeWithDate ? value.toISO() : value.toISODate(); } + + if (config.quoteDate) { + outputValue = `"${outputValue}"`; + } } else { // single string value const escapedValue = (value || '').replace(/"/g, '\\"'); @@ -122,6 +127,7 @@ async function writeImageFilesPromise(posts, config) { } else { const payload = { item: imageUrl, + type: 'image', name: filename, destinationPath, delay @@ -183,3 +189,16 @@ function buildPostPath(post, config) { function checkFile(path) { return fs.existsSync(path); } + +function logPayloadResult(payload, errorMessage) { + const messageBits = [ + errorMessage ? chalk.red('✗') : chalk.green('✓'), + chalk.gray(`[${payload.type}]`), + payload.name + ]; + if (errorMessage) { + messageBits.push(chalk.red(`(${errorMessage})`)); + } + + console.log(messageBits.join(' ')); +}