chore(cli): formatting + version consistency

This commit is contained in:
Cory Dransfeldt 2025-06-11 13:01:36 -07:00
parent fdd556df83
commit 970061ff9d
No known key found for this signature in database
15 changed files with 83 additions and 34 deletions

View file

@ -12,7 +12,7 @@ import { runTasksMenu } from '../lib/tasks/index.js';
process.on('unhandledRejection', (err) => handleExitError(err, 'Unhandled rejection')); process.on('unhandledRejection', (err) => handleExitError(err, 'Unhandled rejection'));
process.on('uncaughtException', (err) => handleExitError(err, 'Uncaught exception')); 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 () => { program.command('init').description('Initialize CLI and populate required config.').action(async () => {
const { initConfig } = await import('../lib/config.js'); const { initConfig } = await import('../lib/config.js');
await initConfig(); await initConfig();

View file

@ -31,6 +31,7 @@ export const initConfig = async () => {
message: 'Where is your storage root directory?', message: 'Where is your storage root directory?',
validate: fs.pathExists validate: fs.pathExists
}]); }]);
config.storageDir = storageDir; config.storageDir = storageDir;
} }
} else { } else {
@ -39,6 +40,7 @@ export const initConfig = async () => {
message: 'Where is your storage root directory?', message: 'Where is your storage root directory?',
validate: fs.pathExists validate: fs.pathExists
}]); }]);
config.storageDir = storageDir; config.storageDir = storageDir;
} }
@ -66,6 +68,7 @@ export const initConfig = async () => {
message: `Subpath for ${mediaType}/${assetType} (relative to storage root):`, message: `Subpath for ${mediaType}/${assetType} (relative to storage root):`,
default: defaultPath default: defaultPath
}]); }]);
subpath = response.subpath; subpath = response.subpath;
} }
@ -161,6 +164,7 @@ const fetchGlobals = async () => {
if (!POSTGREST_URL || !POSTGREST_API_KEY) { if (!POSTGREST_URL || !POSTGREST_API_KEY) {
console.warn('⚠️ Missing POSTGREST_URL or POSTGREST_API_KEY in env, skipping globals fetch.'); console.warn('⚠️ Missing POSTGREST_URL or POSTGREST_API_KEY in env, skipping globals fetch.');
return {}; return {};
} }
@ -176,9 +180,11 @@ const fetchGlobals = async () => {
if (!res.ok) throw new Error(await res.text()); if (!res.ok) throw new Error(await res.text());
const data = await res.json(); const data = await res.json();
return data[0] || {}; return data[0] || {};
} catch (err) { } catch (err) {
console.error('❌ Error fetching globals:', err.message); console.error('❌ Error fetching globals:', err.message);
return {}; return {};
} }
}; };

View file

@ -71,6 +71,7 @@ export const searchItems = async (collection, query = '', filters = {}) => {
return data?.data ?? []; return data?.data ?? [];
} catch (err) { } catch (err) {
console.error(`❌ Failed to search ${collection}:`, err.message); console.error(`❌ Failed to search ${collection}:`, err.message);
return []; return [];
} }
}; };

View file

@ -17,6 +17,7 @@ export const promptForMultipleRelations = async (collection, label = collection)
if (!results.length) { if (!results.length) {
console.warn(`⚠️ No ${collection} found for "${query}".`); console.warn(`⚠️ No ${collection} found for "${query}".`);
continue; continue;
} }

View file

@ -31,11 +31,13 @@ const overwriteImageDownloadPrompt = async (url, finalPath, fileName) => {
if (!overwrite) { if (!overwrite) {
console.log(`⚠️ Skipped existing file: ${fileName}`); console.log(`⚠️ Skipped existing file: ${fileName}`);
return; return;
} }
} }
await downloadImage(url, finalPath); await downloadImage(url, finalPath);
console.log(`✅ Saved to: ${finalPath}`); console.log(`✅ Saved to: ${finalPath}`);
}; };
@ -53,7 +55,8 @@ export const downloadWatchingImages = async () => {
}); });
if (!tmdbId) { if (!tmdbId) {
console.warn('⚠️ TMDB ID is required.') console.warn('⚠️ TMDB ID is required.');
return; return;
} }
@ -62,6 +65,7 @@ export const downloadWatchingImages = async () => {
message: 'Enter the poster url:', message: 'Enter the poster url:',
validate: (val) => { validate: (val) => {
if (!val) return true; if (!val) return true;
return isValidTMDBUrl(val); return isValidTMDBUrl(val);
} }
}, },
@ -70,6 +74,7 @@ export const downloadWatchingImages = async () => {
message: 'Enter the backdrop url:', message: 'Enter the backdrop url:',
validate: (val) => { validate: (val) => {
if (!val) return true; if (!val) return true;
return isValidTMDBUrl(val); return isValidTMDBUrl(val);
} }
}]); }]);
@ -84,6 +89,7 @@ export const downloadWatchingImages = async () => {
if (!targetSubPath) { if (!targetSubPath) {
console.error(`❌ Missing path for ${mediaType}/${type}. Check your config.`); console.error(`❌ Missing path for ${mediaType}/${type}. Check your config.`);
continue; continue;
} }
@ -102,7 +108,8 @@ export const downloadArtistImage = async () => {
}); });
if (!artistName) { if (!artistName) {
console.warn('⚠️ Artist name is required.') console.warn('⚠️ Artist name is required.');
return; return;
} }
@ -112,6 +119,7 @@ export const downloadArtistImage = async () => {
validate: (val) => { validate: (val) => {
try { try {
new URL(val); new URL(val);
return true; return true;
} catch { } catch {
return '❌ Must be a valid url.'; return '❌ Must be a valid url.';
@ -138,6 +146,7 @@ export const downloadAlbumImage = async () => {
if (!artistName) { if (!artistName) {
console.warn('⚠️ Artist name is required.'); console.warn('⚠️ Artist name is required.');
return; return;
} }
@ -148,6 +157,7 @@ export const downloadAlbumImage = async () => {
if (!albumName) { if (!albumName) {
console.warn('⚠️ Album name is required.'); console.warn('⚠️ Album name is required.');
return; return;
} }
@ -157,6 +167,7 @@ export const downloadAlbumImage = async () => {
validate: (val) => { validate: (val) => {
try { try {
new URL(val); new URL(val);
return true; return true;
} catch { } catch {
return '❌ Must be a valid url.'; return '❌ Must be a valid url.';
@ -188,6 +199,7 @@ export const downloadBookImage = async () => {
if (!bookTitle) { if (!bookTitle) {
console.warn('⚠️ Book title is required.'); console.warn('⚠️ Book title is required.');
return; return;
} }
@ -197,6 +209,7 @@ export const downloadBookImage = async () => {
validate: (val) => { validate: (val) => {
try { try {
new URL(val); new URL(val);
return true; return true;
} catch { } catch {
return 'Must be a valid URL'; return 'Must be a valid URL';

View file

@ -135,6 +135,7 @@ const runCurl = async ({
if (!url) { if (!url) {
console.error(`❌ Missing URL for job. Check ${urlEnvVar} in your .env`); console.error(`❌ Missing URL for job. Check ${urlEnvVar} in your .env`);
return; return;
} }
@ -150,6 +151,7 @@ const runCurl = async ({
if (!res.ok) { if (!res.ok) {
const errText = await res.text(); const errText = await res.text();
throw new Error(errText); throw new Error(errText);
} }

View file

@ -8,7 +8,6 @@ export const addBlockedRobot = async () => {
initDirectusClient(config); initDirectusClient(config);
const robots = await searchItems('robots', '/'); const robots = await searchItems('robots', '/');
let rootRobot = robots.find(r => r.path === '/'); let rootRobot = robots.find(r => r.path === '/');
if (!rootRobot) { if (!rootRobot) {

View file

@ -16,6 +16,7 @@ export const addEpisodeToShow = async () => {
if (!matches.length) { if (!matches.length) {
console.warn('⚠️ No matching shows found.'); console.warn('⚠️ No matching shows found.');
return; return;
} }
@ -63,6 +64,7 @@ export const addEpisodeToShow = async () => {
if (update) { if (update) {
await updateItem('episodes', match.id, { plays }); await updateItem('episodes', match.id, { plays });
console.log(`✅ Updated episode: S${season_number}E${episode_number}`); console.log(`✅ Updated episode: S${season_number}E${episode_number}`);
} else { } else {
console.warn('⚠️ Skipped update.'); console.warn('⚠️ Skipped update.');

View file

@ -5,6 +5,7 @@ import { removeUrlProtocol } from '../sanitize.js';
export const addLinkToShare = async () => { export const addLinkToShare = async () => {
const config = await loadConfig(); const config = await loadConfig();
initDirectusClient(config); initDirectusClient(config);
const { title, link, description, authorQuery } = await inquirer.prompt([ const { title, link, description, authorQuery } = await inquirer.prompt([
@ -30,7 +31,6 @@ export const addLinkToShare = async () => {
]); ]);
const authorMatches = await searchItems('authors', authorQuery); const authorMatches = await searchItems('authors', authorQuery);
let author; let author;
if (!authorMatches.length) { if (!authorMatches.length) {
@ -98,6 +98,7 @@ export const addLinkToShare = async () => {
if (!tags.length) { if (!tags.length) {
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`); console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
continue; continue;
} }

View file

@ -55,6 +55,7 @@ export const addPost = async () => {
if (!tags.length) { if (!tags.length) {
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`); console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
continue; continue;
} }
@ -104,6 +105,7 @@ export const addPost = async () => {
if (!results.length) { if (!results.length) {
console.warn(`⚠️ No items found in "${collection}" matching "${query}"`); console.warn(`⚠️ No items found in "${collection}" matching "${query}"`);
continue; continue;
} }
@ -151,6 +153,7 @@ export const addPost = async () => {
if (!matches.length) { if (!matches.length) {
console.warn(`⚠️ No ${mediaType} found matching "${query.trim()}"`); console.warn(`⚠️ No ${mediaType} found matching "${query.trim()}"`);
continue; continue;
} }

View file

@ -11,6 +11,7 @@ export const updateReadingProgress = async () => {
if (!readingBooks.length) { if (!readingBooks.length) {
console.log('📖 No books currently marked as "started".'); console.log('📖 No books currently marked as "started".');
return; return;
} }
@ -33,6 +34,7 @@ export const updateReadingProgress = async () => {
message: '📕 New progress percentage (0100):', message: '📕 New progress percentage (0100):',
validate: input => { validate: input => {
const num = Number(input); const num = Number(input);
return !isNaN(num) && num >= 0 && num <= 100 || 'Enter a number from 0 to 100'; return !isNaN(num) && num >= 0 && num <= 100 || 'Enter a number from 0 to 100';
} }
}); });

34
cli/package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd", "name": "coryd",
"version": "3.2.4", "version": "3.2.5",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd", "name": "coryd",
"version": "3.2.4", "version": "3.2.5",
"dependencies": { "dependencies": {
"@directus/sdk": "^19.1.0", "@directus/sdk": "^19.1.0",
"chalk": "^5.4.1", "chalk": "^5.4.1",
@ -426,18 +426,24 @@
} }
}, },
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-3.0.1.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "integrity": "sha512-vjtV3hiLqYDNRoiAv0zC4QaGAMPomEoq83PRmYIofPswwZurCeWR5LByXm7SyoL0Zh5+2z0+HC7jG8gSZJUh0w==",
"license": "MIT" "license": "MIT",
"engines": {
"node": ">= 16"
}
}, },
"node_modules/brace-expansion": { "node_modules/brace-expansion": {
"version": "2.0.2", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-4.0.1.tgz",
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", "integrity": "sha512-YClrbvTCXGe70pU2JiEiPLYXO9gQkyxYeKpJIQHVS/gOs6EWMQP2RYBwjFLNT322Ji8TOC3IMPfsYCedNpzKfA==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"balanced-match": "^1.0.0" "balanced-match": "^3.0.0"
},
"engines": {
"node": ">= 18"
} }
}, },
"node_modules/chalk": { "node_modules/chalk": {
@ -785,12 +791,12 @@
} }
}, },
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "10.0.1", "version": "10.0.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.2.tgz",
"integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", "integrity": "sha512-+9TJCIYXgZ2Dm5LxVCFsa8jOm+evMwXHFI0JM1XROmkfkpz8/iLLDh+TwSmyIBrs6C6Xu9294/fq8cBA+P6AqA==",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"brace-expansion": "^2.0.1" "brace-expansion": "^4.0.1"
}, },
"engines": { "engines": {
"node": "20 || >=22" "node": "20 || >=22"

View file

@ -1,7 +1,7 @@
{ {
"name": "coryd", "name": "coryd",
"version": "3.2.4", "version": "3.2.5",
"description": "The CLI for my site to run scripts, manage and download assets.", "description": "The CLI for my site to handle tasks, run commands or jobs and download things.",
"type": "module", "type": "module",
"bin": { "bin": {
"coryd": "./bin/index.js" "coryd": "./bin/index.js"

37
package-lock.json generated
View file

@ -27,7 +27,7 @@
"markdown-it-footnote": "^4.0.0", "markdown-it-footnote": "^4.0.0",
"markdown-it-link-attributes": "4.0.1", "markdown-it-link-attributes": "4.0.1",
"markdown-it-prism": "^3.0.0", "markdown-it-prism": "^3.0.0",
"postcss": "^8.5.4", "postcss": "^8.5.5",
"postcss-import": "^16.1.0", "postcss-import": "^16.1.0",
"postcss-import-ext-glob": "^2.1.1", "postcss-import-ext-glob": "^2.1.1",
"rimraf": "^6.0.1", "rimraf": "^6.0.1",
@ -1756,24 +1756,37 @@
"node": ">= 6" "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": { "node_modules/glob/node_modules/brace-expansion": {
"version": "2.0.2", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-4.0.1.tgz",
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", "integrity": "sha512-YClrbvTCXGe70pU2JiEiPLYXO9gQkyxYeKpJIQHVS/gOs6EWMQP2RYBwjFLNT322Ji8TOC3IMPfsYCedNpzKfA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"balanced-match": "^1.0.0" "balanced-match": "^3.0.0"
},
"engines": {
"node": ">= 18"
} }
}, },
"node_modules/glob/node_modules/minimatch": { "node_modules/glob/node_modules/minimatch": {
"version": "10.0.1", "version": "10.0.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.1.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.2.tgz",
"integrity": "sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==", "integrity": "sha512-+9TJCIYXgZ2Dm5LxVCFsa8jOm+evMwXHFI0JM1XROmkfkpz8/iLLDh+TwSmyIBrs6C6Xu9294/fq8cBA+P6AqA==",
"dev": true, "dev": true,
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"brace-expansion": "^2.0.1" "brace-expansion": "^4.0.1"
}, },
"engines": { "engines": {
"node": "20 || >=22" "node": "20 || >=22"
@ -2817,9 +2830,9 @@
} }
}, },
"node_modules/postcss": { "node_modules/postcss": {
"version": "8.5.4", "version": "8.5.5",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.4.tgz", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.5.tgz",
"integrity": "sha512-QSa9EBe+uwlGTFmHsPKokv3B/oEMQZxfqW0QqNCyhpa6mB1afzulwn8hihglqAb2pOw+BJgNlmXQ8la2VeHB7w==", "integrity": "sha512-d/jtm+rdNT8tpXuHY5MMtcbJFBkhXE6593XVR9UoGCH8jSFGci7jGvMGH5RYd5PBJW+00NZQt6gf7CbagJCrhg==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {

View file

@ -47,7 +47,7 @@
"markdown-it-footnote": "^4.0.0", "markdown-it-footnote": "^4.0.0",
"markdown-it-link-attributes": "4.0.1", "markdown-it-link-attributes": "4.0.1",
"markdown-it-prism": "^3.0.0", "markdown-it-prism": "^3.0.0",
"postcss": "^8.5.4", "postcss": "^8.5.5",
"postcss-import": "^16.1.0", "postcss-import": "^16.1.0",
"postcss-import-ext-glob": "^2.1.1", "postcss-import-ext-glob": "^2.1.1",
"rimraf": "^6.0.1", "rimraf": "^6.0.1",