diff --git a/cli/bin/index.js b/cli/bin/index.js index 85acfdb..5dbe204 100755 --- a/cli/bin/index.js +++ b/cli/bin/index.js @@ -13,7 +13,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.0.0'); +program.name('coryd').description('๐Ÿช„ Handle tasks, run commands or jobs, download things and have fun.').version('3.2.0'); program.command('init').description('Initialize CLI and populate required config.').action(initConfig); program.command('run [script]').description('Run site scripts and commands.').action(runRootScript); program.command('tasks').description('Handle repeated tasks.').action(runTasksMenu); diff --git a/cli/lib/tasks/addLinkToShare.js b/cli/lib/tasks/addLinkToShare.js index 9d17539..5790f8f 100644 --- a/cli/lib/tasks/addLinkToShare.js +++ b/cli/lib/tasks/addLinkToShare.js @@ -4,10 +4,10 @@ import { initDirectusClient, searchItems, createItem } from '../directus/client. export const addLinkToShare = async () => { const config = await loadConfig(); - initDirectusClient(config); - const { title, link, description, authorQuery } = await inquirer.prompt([{ + const { title, link, description, authorQuery } = await inquirer.prompt([ + { name: 'title', message: '๐Ÿ“ Title for the link:', validate: input => !!input || 'Title is required' @@ -25,23 +25,57 @@ export const addLinkToShare = async () => { { name: 'authorQuery', message: '๐Ÿ‘ค Search for an author:', - }]); + } + ]); + const authorMatches = await searchItems('authors', authorQuery); - if (!authorMatches.length) { - console.log('โŒ No matching authors found.'); - return; - } + let author; - const { author } = await inquirer.prompt({ - type: 'list', - name: 'author', - message: 'Select an author:', - choices: authorMatches.map(a => ({ - name: a.name || a.id, - value: a.id, - })) - }); + if (!authorMatches.length) { + const { shouldCreate } = await inquirer.prompt({ + type: 'confirm', + name: 'shouldCreate', + message: 'โŒ No authors found. Do you want to create a new one?', + default: true, + }); + + if (!shouldCreate) return; + + const { name, url, mastodon, rss, json, newsletter, blogroll } = await inquirer.prompt([ + { name: 'name', message: '๐Ÿ‘ค Author name:', validate: input => !!input || 'Name is required' }, + { name: 'url', message: '๐Ÿ”— URL (optional):', default: '' }, + { name: 'mastodon', message: '๐Ÿ˜ Mastodon handle (optional):', default: '' }, + { name: 'rss', message: '๐Ÿ“ก RSS feed (optional):', default: '' }, + { name: 'json', message: '๐Ÿงพ JSON feed (optional):', default: '' }, + { name: 'newsletter', message: '๐Ÿ“ฐ Newsletter URL (optional):', default: '' }, + { type: 'confirm', name: 'blogroll', message: '๐Ÿ“Œ Add to blogroll?', default: false } + ]); + + const created = await createItem('authors', { + name, + url, + mastodon, + rss, + json, + newsletter, + blogroll + }); + + author = created.data?.id || created.id; + } else { + const response = await inquirer.prompt({ + type: 'list', + name: 'author', + message: 'Select an author:', + choices: authorMatches.map(a => ({ + name: a.name || a.id, + value: a.id, + })) + }); + + author = response.author; + } let tagIds = []; @@ -50,8 +84,8 @@ export const addLinkToShare = async () => { name: 'query', message: '๐Ÿท Search for tags (or leave blank to finish):', }); - const trimmedQuery = query.trim(); + const trimmedQuery = query.trim(); if (!trimmedQuery) break; const tags = await searchItems('tags', trimmedQuery); diff --git a/cli/lib/tasks/index.js b/cli/lib/tasks/index.js index 7703d40..af760d1 100644 --- a/cli/lib/tasks/index.js +++ b/cli/lib/tasks/index.js @@ -18,7 +18,7 @@ export const runTasksMenu = async () => { { type: 'list', name: 'task', - message: 'Select a task to run:', + message: 'Select a task to perform:', choices: TASKS.map(t => ({ name: t.name, value: t.handler })) } ]); diff --git a/cli/package-lock.json b/cli/package-lock.json index f7c6fdd..3caf715 100644 --- a/cli/package-lock.json +++ b/cli/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd", - "version": "3.1.0", + "version": "3.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd", - "version": "3.1.0", + "version": "3.2.0", "dependencies": { "@directus/sdk": "^19.1.0", "chalk": "^5.4.1", diff --git a/cli/package.json b/cli/package.json index 635af8b..3e4a7e3 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "coryd", - "version": "3.1.0", + "version": "3.2.0", "description": "The CLI for my site to run scripts, manage and download assets.", "type": "module", "bin": {