Logging refactor, quote-date, type count fix

This commit is contained in:
Will Boyd
2025-02-06 13:56:27 -05:00
parent 9fb7ae47c5
commit df5731985d
3 changed files with 29 additions and 8 deletions
+22 -3
View File
@@ -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(' '));
}