From 970061ff9db627d0d9df143cdc24c6f6eb6075e3 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Wed, 11 Jun 2025 13:01:36 -0700 Subject: [PATCH] chore(cli): formatting + version consistency --- cli/bin/index.js | 2 +- cli/lib/config.js | 6 +++++ cli/lib/directus/client.js | 1 + cli/lib/directus/relationHelpers.js | 1 + cli/lib/download.js | 17 ++++++++++-- cli/lib/jobs.js | 2 ++ cli/lib/tasks/addBlockedRobot.js | 1 - cli/lib/tasks/addEpisodeToShow.js | 2 ++ cli/lib/tasks/addLinkToShare.js | 3 ++- cli/lib/tasks/addPost.js | 3 +++ cli/lib/tasks/updateReadingProgress.js | 2 ++ cli/package-lock.json | 34 +++++++++++++---------- cli/package.json | 4 +-- package-lock.json | 37 +++++++++++++++++--------- package.json | 2 +- 15 files changed, 83 insertions(+), 34 deletions(-) diff --git a/cli/bin/index.js b/cli/bin/index.js index 2eea5ca..abdc9a7 100755 --- a/cli/bin/index.js +++ b/cli/bin/index.js @@ -12,7 +12,7 @@ import { runTasksMenu } from '../lib/tasks/index.js'; process.on('unhandledRejection', (err) => handleExitError(err, 'Unhandled rejection')); process.on('uncaughtException', (err) => handleExitError(err, 'Uncaught exception')); -program.name('coryd').description('🪄 Handle tasks, run commands or jobs, download things and have fun.').version('3.2.0'); +program.name('coryd').description('🪄 Handle tasks, run commands or jobs, download things and have fun.').version('3.2.5'); program.command('init').description('Initialize CLI and populate required config.').action(async () => { const { initConfig } = await import('../lib/config.js'); await initConfig(); diff --git a/cli/lib/config.js b/cli/lib/config.js index b2abd67..cdd1700 100644 --- a/cli/lib/config.js +++ b/cli/lib/config.js @@ -31,6 +31,7 @@ export const initConfig = async () => { message: 'Where is your storage root directory?', validate: fs.pathExists }]); + config.storageDir = storageDir; } } else { @@ -39,6 +40,7 @@ export const initConfig = async () => { message: 'Where is your storage root directory?', validate: fs.pathExists }]); + config.storageDir = storageDir; } @@ -66,6 +68,7 @@ export const initConfig = async () => { message: `Subpath for ${mediaType}/${assetType} (relative to storage root):`, default: defaultPath }]); + subpath = response.subpath; } @@ -161,6 +164,7 @@ const fetchGlobals = async () => { if (!POSTGREST_URL || !POSTGREST_API_KEY) { console.warn('⚠️ Missing POSTGREST_URL or POSTGREST_API_KEY in env, skipping globals fetch.'); + return {}; } @@ -176,9 +180,11 @@ const fetchGlobals = async () => { if (!res.ok) throw new Error(await res.text()); const data = await res.json(); + return data[0] || {}; } catch (err) { console.error('❌ Error fetching globals:', err.message); + return {}; } }; diff --git a/cli/lib/directus/client.js b/cli/lib/directus/client.js index 402026f..4d65bd7 100644 --- a/cli/lib/directus/client.js +++ b/cli/lib/directus/client.js @@ -71,6 +71,7 @@ export const searchItems = async (collection, query = '', filters = {}) => { return data?.data ?? []; } catch (err) { console.error(`❌ Failed to search ${collection}:`, err.message); + return []; } }; diff --git a/cli/lib/directus/relationHelpers.js b/cli/lib/directus/relationHelpers.js index 23bc7c6..a8a9127 100644 --- a/cli/lib/directus/relationHelpers.js +++ b/cli/lib/directus/relationHelpers.js @@ -17,6 +17,7 @@ export const promptForMultipleRelations = async (collection, label = collection) if (!results.length) { console.warn(`⚠️ No ${collection} found for "${query}".`); + continue; } diff --git a/cli/lib/download.js b/cli/lib/download.js index 648b6a2..441ae54 100644 --- a/cli/lib/download.js +++ b/cli/lib/download.js @@ -31,11 +31,13 @@ const overwriteImageDownloadPrompt = async (url, finalPath, fileName) => { if (!overwrite) { console.log(`⚠️ Skipped existing file: ${fileName}`); + return; } } await downloadImage(url, finalPath); + console.log(`✅ Saved to: ${finalPath}`); }; @@ -53,7 +55,8 @@ export const downloadWatchingImages = async () => { }); if (!tmdbId) { - console.warn('⚠️ TMDB ID is required.') + console.warn('⚠️ TMDB ID is required.'); + return; } @@ -62,6 +65,7 @@ export const downloadWatchingImages = async () => { message: 'Enter the poster url:', validate: (val) => { if (!val) return true; + return isValidTMDBUrl(val); } }, @@ -70,6 +74,7 @@ export const downloadWatchingImages = async () => { message: 'Enter the backdrop url:', validate: (val) => { if (!val) return true; + return isValidTMDBUrl(val); } }]); @@ -84,6 +89,7 @@ export const downloadWatchingImages = async () => { if (!targetSubPath) { console.error(`❌ Missing path for ${mediaType}/${type}. Check your config.`); + continue; } @@ -102,7 +108,8 @@ export const downloadArtistImage = async () => { }); if (!artistName) { - console.warn('⚠️ Artist name is required.') + console.warn('⚠️ Artist name is required.'); + return; } @@ -112,6 +119,7 @@ export const downloadArtistImage = async () => { validate: (val) => { try { new URL(val); + return true; } catch { return '❌ Must be a valid url.'; @@ -138,6 +146,7 @@ export const downloadAlbumImage = async () => { if (!artistName) { console.warn('⚠️ Artist name is required.'); + return; } @@ -148,6 +157,7 @@ export const downloadAlbumImage = async () => { if (!albumName) { console.warn('⚠️ Album name is required.'); + return; } @@ -157,6 +167,7 @@ export const downloadAlbumImage = async () => { validate: (val) => { try { new URL(val); + return true; } catch { return '❌ Must be a valid url.'; @@ -188,6 +199,7 @@ export const downloadBookImage = async () => { if (!bookTitle) { console.warn('⚠️ Book title is required.'); + return; } @@ -197,6 +209,7 @@ export const downloadBookImage = async () => { validate: (val) => { try { new URL(val); + return true; } catch { return 'Must be a valid URL'; diff --git a/cli/lib/jobs.js b/cli/lib/jobs.js index 71c1cd0..42b760f 100644 --- a/cli/lib/jobs.js +++ b/cli/lib/jobs.js @@ -135,6 +135,7 @@ const runCurl = async ({ if (!url) { console.error(`❌ Missing URL for job. Check ${urlEnvVar} in your .env`); + return; } @@ -150,6 +151,7 @@ const runCurl = async ({ if (!res.ok) { const errText = await res.text(); + throw new Error(errText); } diff --git a/cli/lib/tasks/addBlockedRobot.js b/cli/lib/tasks/addBlockedRobot.js index 2fa430e..aa780c0 100644 --- a/cli/lib/tasks/addBlockedRobot.js +++ b/cli/lib/tasks/addBlockedRobot.js @@ -8,7 +8,6 @@ export const addBlockedRobot = async () => { initDirectusClient(config); const robots = await searchItems('robots', '/'); - let rootRobot = robots.find(r => r.path === '/'); if (!rootRobot) { diff --git a/cli/lib/tasks/addEpisodeToShow.js b/cli/lib/tasks/addEpisodeToShow.js index 89fc5ac..4d46e43 100644 --- a/cli/lib/tasks/addEpisodeToShow.js +++ b/cli/lib/tasks/addEpisodeToShow.js @@ -16,6 +16,7 @@ export const addEpisodeToShow = async () => { if (!matches.length) { console.warn('⚠️ No matching shows found.'); + return; } @@ -63,6 +64,7 @@ export const addEpisodeToShow = async () => { if (update) { await updateItem('episodes', match.id, { plays }); + console.log(`✅ Updated episode: S${season_number}E${episode_number}`); } else { console.warn('⚠️ Skipped update.'); diff --git a/cli/lib/tasks/addLinkToShare.js b/cli/lib/tasks/addLinkToShare.js index c980b35..efe574e 100644 --- a/cli/lib/tasks/addLinkToShare.js +++ b/cli/lib/tasks/addLinkToShare.js @@ -5,6 +5,7 @@ import { removeUrlProtocol } from '../sanitize.js'; export const addLinkToShare = async () => { const config = await loadConfig(); + initDirectusClient(config); const { title, link, description, authorQuery } = await inquirer.prompt([ @@ -30,7 +31,6 @@ export const addLinkToShare = async () => { ]); const authorMatches = await searchItems('authors', authorQuery); - let author; if (!authorMatches.length) { @@ -98,6 +98,7 @@ export const addLinkToShare = async () => { if (!tags.length) { console.warn(`⚠️ No tags found matching "${trimmedQuery}"`); + continue; } diff --git a/cli/lib/tasks/addPost.js b/cli/lib/tasks/addPost.js index dd7a985..ddf99f0 100644 --- a/cli/lib/tasks/addPost.js +++ b/cli/lib/tasks/addPost.js @@ -55,6 +55,7 @@ export const addPost = async () => { if (!tags.length) { console.warn(`⚠️ No tags found matching "${trimmedQuery}"`); + continue; } @@ -104,6 +105,7 @@ export const addPost = async () => { if (!results.length) { console.warn(`⚠️ No items found in "${collection}" matching "${query}"`); + continue; } @@ -151,6 +153,7 @@ export const addPost = async () => { if (!matches.length) { console.warn(`⚠️ No ${mediaType} found matching "${query.trim()}"`); + continue; } diff --git a/cli/lib/tasks/updateReadingProgress.js b/cli/lib/tasks/updateReadingProgress.js index 7ceb632..dcb04b7 100644 --- a/cli/lib/tasks/updateReadingProgress.js +++ b/cli/lib/tasks/updateReadingProgress.js @@ -11,6 +11,7 @@ export const updateReadingProgress = async () => { if (!readingBooks.length) { console.log('📖 No books currently marked as "started".'); + return; } @@ -33,6 +34,7 @@ export const updateReadingProgress = async () => { message: '📕 New progress percentage (0–100):', validate: input => { const num = Number(input); + return !isNaN(num) && num >= 0 && num <= 100 || 'Enter a number from 0 to 100'; } }); diff --git a/cli/package-lock.json b/cli/package-lock.json index 3274e84..198cea5 100644 --- a/cli/package-lock.json +++ b/cli/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd", - "version": "3.2.4", + "version": "3.2.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd", - "version": "3.2.4", + "version": "3.2.5", "dependencies": { "@directus/sdk": "^19.1.0", "chalk": "^5.4.1", @@ -426,18 +426,24 @@ } }, "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "license": "MIT" + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-3.0.1.tgz", + "integrity": "sha512-vjtV3hiLqYDNRoiAv0zC4QaGAMPomEoq83PRmYIofPswwZurCeWR5LByXm7SyoL0Zh5+2z0+HC7jG8gSZJUh0w==", + "license": "MIT", + "engines": { + "node": ">= 16" + } }, "node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-4.0.1.tgz", + "integrity": "sha512-YClrbvTCXGe70pU2JiEiPLYXO9gQkyxYeKpJIQHVS/gOs6EWMQP2RYBwjFLNT322Ji8TOC3IMPfsYCedNpzKfA==", "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^3.0.0" + }, + "engines": { + "node": ">= 18" } }, "node_modules/chalk": { @@ -785,12 +791,12 @@ } }, "node_modules/minimatch": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", - "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.2.tgz", + "integrity": "sha512-+9TJCIYXgZ2Dm5LxVCFsa8jOm+evMwXHFI0JM1XROmkfkpz8/iLLDh+TwSmyIBrs6C6Xu9294/fq8cBA+P6AqA==", "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^4.0.1" }, "engines": { "node": "20 || >=22" diff --git a/cli/package.json b/cli/package.json index 483fc77..9f23676 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,7 +1,7 @@ { "name": "coryd", - "version": "3.2.4", - "description": "The CLI for my site to run scripts, manage and download assets.", + "version": "3.2.5", + "description": "The CLI for my site to handle tasks, run commands or jobs and download things.", "type": "module", "bin": { "coryd": "./bin/index.js" diff --git a/package-lock.json b/package-lock.json index 03d1657..70235ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "markdown-it-footnote": "^4.0.0", "markdown-it-link-attributes": "4.0.1", "markdown-it-prism": "^3.0.0", - "postcss": "^8.5.4", + "postcss": "^8.5.5", "postcss-import": "^16.1.0", "postcss-import-ext-glob": "^2.1.1", "rimraf": "^6.0.1", @@ -1756,24 +1756,37 @@ "node": ">= 6" } }, + "node_modules/glob/node_modules/balanced-match": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-3.0.1.tgz", + "integrity": "sha512-vjtV3hiLqYDNRoiAv0zC4QaGAMPomEoq83PRmYIofPswwZurCeWR5LByXm7SyoL0Zh5+2z0+HC7jG8gSZJUh0w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 16" + } + }, "node_modules/glob/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-4.0.1.tgz", + "integrity": "sha512-YClrbvTCXGe70pU2JiEiPLYXO9gQkyxYeKpJIQHVS/gOs6EWMQP2RYBwjFLNT322Ji8TOC3IMPfsYCedNpzKfA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^3.0.0" + }, + "engines": { + "node": ">= 18" } }, "node_modules/glob/node_modules/minimatch": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", - "integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.2.tgz", + "integrity": "sha512-+9TJCIYXgZ2Dm5LxVCFsa8jOm+evMwXHFI0JM1XROmkfkpz8/iLLDh+TwSmyIBrs6C6Xu9294/fq8cBA+P6AqA==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^4.0.1" }, "engines": { "node": "20 || >=22" @@ -2817,9 +2830,9 @@ } }, "node_modules/postcss": { - "version": "8.5.4", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.4.tgz", - "integrity": "sha512-QSa9EBe+uwlGTFmHsPKokv3B/oEMQZxfqW0QqNCyhpa6mB1afzulwn8hihglqAb2pOw+BJgNlmXQ8la2VeHB7w==", + "version": "8.5.5", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.5.tgz", + "integrity": "sha512-d/jtm+rdNT8tpXuHY5MMtcbJFBkhXE6593XVR9UoGCH8jSFGci7jGvMGH5RYd5PBJW+00NZQt6gf7CbagJCrhg==", "dev": true, "funding": [ { diff --git a/package.json b/package.json index de1e9f7..9366574 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "markdown-it-footnote": "^4.0.0", "markdown-it-link-attributes": "4.0.1", "markdown-it-prism": "^3.0.0", - "postcss": "^8.5.4", + "postcss": "^8.5.5", "postcss-import": "^16.1.0", "postcss-import-ext-glob": "^2.1.1", "rimraf": "^6.0.1",