chore(cli): dry up link + post tag prompt
This commit is contained in:
parent
efe701f939
commit
555ba74bf6
8 changed files with 75 additions and 104 deletions
|
@ -4,7 +4,7 @@ import { program } from "commander";
|
|||
import chalk from "chalk";
|
||||
import figlet from "figlet";
|
||||
import { loadConfig } from "../lib/config.js";
|
||||
import { handleExitError } from "../lib/handlers.js";
|
||||
import { handleExitError } from "../lib/utils.js";
|
||||
import { runRootScript } from "../lib/runScript.js";
|
||||
import { runJobsMenu } from "../lib/jobs.js";
|
||||
import { runTasksMenu } from "../lib/tasks/index.js";
|
||||
|
|
65
cli/lib/directus/tagHelpers.js
Normal file
65
cli/lib/directus/tagHelpers.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
import inquirer from "inquirer";
|
||||
import { searchItems, createItem } from "./client.js";
|
||||
|
||||
export const promptForTags = async () => {
|
||||
const tagIds = [];
|
||||
|
||||
while (true) {
|
||||
const { query } = await inquirer.prompt({
|
||||
name: "query",
|
||||
message: "🏷 Search for tags (or leave blank to finish):"
|
||||
});
|
||||
|
||||
const trimmedQuery = query.trim();
|
||||
if (!trimmedQuery) break;
|
||||
|
||||
const tags = await searchItems("tags", trimmedQuery);
|
||||
|
||||
if (!tags.length) {
|
||||
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
|
||||
|
||||
const { shouldCreateTag } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "shouldCreateTag",
|
||||
message: `Do you want to create a new tag named "${trimmedQuery}"?`,
|
||||
default: true
|
||||
});
|
||||
|
||||
if (shouldCreateTag) {
|
||||
const createdTag = await createItem("tags", { name: trimmedQuery });
|
||||
const newTagId = createdTag.data?.id || createdTag.id;
|
||||
tagIds.push(newTagId);
|
||||
}
|
||||
|
||||
const { again } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "again",
|
||||
message: "Search and select more tags?",
|
||||
default: false
|
||||
});
|
||||
|
||||
if (!again) break;
|
||||
continue;
|
||||
}
|
||||
|
||||
const { selected } = await inquirer.prompt({
|
||||
type: "checkbox",
|
||||
name: "selected",
|
||||
message: "✔ Select tags to add:",
|
||||
choices: tags.map((tag) => ({ name: tag.name, value: tag.id }))
|
||||
});
|
||||
|
||||
tagIds.push(...selected);
|
||||
|
||||
const { again } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "again",
|
||||
message: "Search and select more tags?",
|
||||
default: false
|
||||
});
|
||||
|
||||
if (!again) break;
|
||||
}
|
||||
|
||||
return [...new Set(tagIds)];
|
||||
};
|
|
@ -2,6 +2,7 @@ import inquirer from "inquirer";
|
|||
import { loadConfig } from "../config.js";
|
||||
import { initDirectusClient, searchItems, createItem } from "../directus/client.js";
|
||||
import { removeUrlProtocol } from "../sanitize.js";
|
||||
import { promptForTags } from "../directus/tagHelpers.js";
|
||||
|
||||
export const addLinkToShare = async () => {
|
||||
const config = await loadConfig();
|
||||
|
@ -87,66 +88,7 @@ export const addLinkToShare = async () => {
|
|||
author = response.author;
|
||||
}
|
||||
|
||||
let tagIds = [];
|
||||
|
||||
while (true) {
|
||||
const { query } = await inquirer.prompt({
|
||||
name: "query",
|
||||
message: "🏷 Search for tags (or leave blank to finish):"
|
||||
});
|
||||
|
||||
const trimmedQuery = query.trim();
|
||||
if (!trimmedQuery) break;
|
||||
|
||||
const tags = await searchItems("tags", trimmedQuery);
|
||||
|
||||
if (!tags.length) {
|
||||
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
|
||||
|
||||
const { shouldCreateTag } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "shouldCreateTag",
|
||||
message: `Do you want to create a new tag named "${trimmedQuery}"?`,
|
||||
default: true
|
||||
});
|
||||
|
||||
if (shouldCreateTag) {
|
||||
const createdTag = await createItem("tags", { name: trimmedQuery });
|
||||
const newTagId = createdTag.data?.id || createdTag.id;
|
||||
|
||||
tagIds.push(newTagId);
|
||||
}
|
||||
|
||||
const { again } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "again",
|
||||
message: "Search and select more tags?",
|
||||
default: false
|
||||
});
|
||||
|
||||
if (!again) break;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const { selected } = await inquirer.prompt({
|
||||
type: "checkbox",
|
||||
name: "selected",
|
||||
message: "✔ Select tags to add:",
|
||||
choices: tags.map((tag) => ({ name: tag.name, value: tag.id }))
|
||||
});
|
||||
|
||||
tagIds.push(...selected);
|
||||
|
||||
const { again } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "again",
|
||||
message: "Search and select more tags?",
|
||||
default: false
|
||||
});
|
||||
|
||||
if (!again) break;
|
||||
}
|
||||
const tagIds = await promptForTags();
|
||||
|
||||
await createItem("links", {
|
||||
title,
|
||||
|
|
|
@ -2,6 +2,7 @@ import inquirer from "inquirer";
|
|||
import { loadConfig } from "../config.js";
|
||||
import { initDirectusClient, createItem, searchItems } from "../directus/client.js";
|
||||
import { promptForMultipleRelations } from "../directus/relationHelpers.js";
|
||||
import { promptForTags } from "../directus/tagHelpers.js";
|
||||
|
||||
const ASSOCIATED_MEDIA_TYPES = ["artists", "books", "movies", "shows", "genres"];
|
||||
const BLOCK_COLLECTIONS = [
|
||||
|
@ -42,44 +43,7 @@ export const addPost = async () => {
|
|||
}
|
||||
]);
|
||||
|
||||
let tagIds = [];
|
||||
|
||||
while (true) {
|
||||
const { query } = await inquirer.prompt({
|
||||
name: "query",
|
||||
message: "🏷 Search for tags (or leave blank to finish):"
|
||||
});
|
||||
const trimmedQuery = query.trim();
|
||||
|
||||
if (!trimmedQuery) break;
|
||||
|
||||
const tags = await searchItems("tags", trimmedQuery);
|
||||
|
||||
if (!tags.length) {
|
||||
console.warn(`⚠️ No tags found matching "${trimmedQuery}"`);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const { selected } = await inquirer.prompt({
|
||||
type: "checkbox",
|
||||
name: "selected",
|
||||
message: "✔ Select tags to add:",
|
||||
choices: tags.map((tag) => ({ name: tag.name, value: tag.id }))
|
||||
});
|
||||
|
||||
tagIds.push(...selected);
|
||||
|
||||
const { again } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
name: "again",
|
||||
message: "Search and select more tags?",
|
||||
default: false
|
||||
});
|
||||
|
||||
if (!again) break;
|
||||
}
|
||||
|
||||
const tagIds = await promptForTags();
|
||||
const selectedBlocks = [];
|
||||
const { includeBlocks } = await inquirer.prompt({
|
||||
type: "confirm",
|
||||
|
|
4
cli/package-lock.json
generated
4
cli/package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "coryd",
|
||||
"version": "3.3.0",
|
||||
"version": "3.4.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coryd",
|
||||
"version": "3.3.0",
|
||||
"version": "3.4.0",
|
||||
"dependencies": {
|
||||
"@directus/sdk": "^19.1.0",
|
||||
"chalk": "^5.4.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "coryd",
|
||||
"version": "3.3.0",
|
||||
"version": "3.4.0",
|
||||
"description": "The CLI for my site to handle tasks, run commands or jobs and download things.",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "10.6.7",
|
||||
"version": "10.7.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coryd.dev",
|
||||
"version": "10.6.7",
|
||||
"version": "10.7.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"minisearch": "^7.1.2",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue