feat(cli): prompt to create author if none found when adding link
This commit is contained in:
parent
91621b120a
commit
233e609155
4 changed files with 55 additions and 21 deletions
|
@ -13,7 +13,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.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('init').description('Initialize CLI and populate required config.').action(initConfig);
|
||||||
program.command('run [script]').description('Run site scripts and commands.').action(runRootScript);
|
program.command('run [script]').description('Run site scripts and commands.').action(runRootScript);
|
||||||
program.command('tasks').description('Handle repeated tasks.').action(runTasksMenu);
|
program.command('tasks').description('Handle repeated tasks.').action(runTasksMenu);
|
||||||
|
|
|
@ -4,10 +4,10 @@ import { initDirectusClient, searchItems, createItem } from '../directus/client.
|
||||||
|
|
||||||
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([
|
||||||
|
{
|
||||||
name: 'title',
|
name: 'title',
|
||||||
message: '📝 Title for the link:',
|
message: '📝 Title for the link:',
|
||||||
validate: input => !!input || 'Title is required'
|
validate: input => !!input || 'Title is required'
|
||||||
|
@ -25,15 +25,46 @@ export const addLinkToShare = async () => {
|
||||||
{
|
{
|
||||||
name: 'authorQuery',
|
name: 'authorQuery',
|
||||||
message: '👤 Search for an author:',
|
message: '👤 Search for an author:',
|
||||||
}]);
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
const authorMatches = await searchItems('authors', authorQuery);
|
const authorMatches = await searchItems('authors', authorQuery);
|
||||||
|
|
||||||
if (!authorMatches.length) {
|
let author;
|
||||||
console.log('❌ No matching authors found.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { author } = await inquirer.prompt({
|
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',
|
type: 'list',
|
||||||
name: 'author',
|
name: 'author',
|
||||||
message: 'Select an author:',
|
message: 'Select an author:',
|
||||||
|
@ -43,6 +74,9 @@ export const addLinkToShare = async () => {
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
author = response.author;
|
||||||
|
}
|
||||||
|
|
||||||
let tagIds = [];
|
let tagIds = [];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -50,8 +84,8 @@ export const addLinkToShare = async () => {
|
||||||
name: 'query',
|
name: 'query',
|
||||||
message: '🏷 Search for tags (or leave blank to finish):',
|
message: '🏷 Search for tags (or leave blank to finish):',
|
||||||
});
|
});
|
||||||
const trimmedQuery = query.trim();
|
|
||||||
|
|
||||||
|
const trimmedQuery = query.trim();
|
||||||
if (!trimmedQuery) break;
|
if (!trimmedQuery) break;
|
||||||
|
|
||||||
const tags = await searchItems('tags', trimmedQuery);
|
const tags = await searchItems('tags', trimmedQuery);
|
||||||
|
|
4
cli/package-lock.json
generated
4
cli/package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd",
|
"name": "coryd",
|
||||||
"version": "3.1.0",
|
"version": "3.2.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd",
|
"name": "coryd",
|
||||||
"version": "3.1.0",
|
"version": "3.2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@directus/sdk": "^19.1.0",
|
"@directus/sdk": "^19.1.0",
|
||||||
"chalk": "^5.4.1",
|
"chalk": "^5.4.1",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd",
|
"name": "coryd",
|
||||||
"version": "3.1.0",
|
"version": "3.2.0",
|
||||||
"description": "The CLI for my site to run scripts, manage and download assets.",
|
"description": "The CLI for my site to run scripts, manage and download assets.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue