Communitygithub.com

YepAPI/skills

使用 Commander.js 构建 CLI 工具,集成 Clack 交互式提示、Ora 加载动画、Chalk 颜色输出、配置文件支持、退出码规范以及 npm 发布流程。

skills 是什么?

此技能为开发者提供了一套完整的 CLI 工具构建指南,基于 Node.js 生态中的多个成熟库。它围绕 Commander.js 进行参数解析,推荐使用 @clack/prompts 或 inquirer 实现优雅的交互式提示,Ora 用于显示长时间操作的加载动画,Chalk 负责控制台颜色输出以提升可读性(错误用红色、成功用绿色、警告用黄色)。配置文件方面使用 cosmiconfig 自动搜索多种格式的配置。技能还规范了退出码(0 成功、1 通用错误、2 用法错误)并强调错误处理时通过 stderr 输出友好信息。此外,它详细说明了 npm 发布所需的 bin 字段、shebang 和 ESM 配置。该技能适用于 Claude Code、Cursor、Codex 等 AI 编码助手,帮助快速生成符合行业标准的 Node.js CLI 应用,确保工具在终端、CI 和脚本环境中都能可靠运行。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/cli-tools

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

CLI 工具

规则

  • 参数解析:使用 Commander.js — .command()、.option()、.argument() 并附上描述
  • 交互式提示:使用 @clack/prompts(现代美观)或 inquirer — 当参数未提供时用于用户输入
  • 加载动画:使用 ora 处理长时间运行的操作 — 启动、更新消息、成功/失败
  • 颜色输出:使用 chalk 进行样式化输出 — 适度使用:红色表示错误,绿色表示成功,黄色表示警告,灰色表示次要信息
  • 配置文件:使用 cosmiconfig — 自动搜索 .toolrc、.toolrc.json、tool.config.js、package.json 中的键
  • 退出码:0 表示成功,1 表示通用错误,2 表示用法错误 — 始终使用 process.exit(code)
  • --help 和 --version 标志:Commander 会自动添加 — 为每个选项编写清晰的描述
  • 错误处理:在顶层捕获错误,向 stderr 打印用户友好的消息,以代码 1 退出
  • 发布:在 package.json 中设置 bin 字段,添加 #!/usr/bin/env node shebang,设置 "type": "module" 以支持 ESM

模式

#!/usr/bin/env node
import { Command } from "commander";
import * as p from "@clack/prompts";
import ora from "ora";
import chalk from "chalk";

const program = new Command()
  .name("my-tool")
  .description("一个执行有用操作的 CLI 工具")
  .version("1.0.0");

program
  .command("init")
  .description("初始化一个新项目")
  .option("-t, --template <name>", "要使用的模板", "default")
  .action(async (options) => {
    p.intro(chalk.bold("项目设置"));

    const name = await p.text({ message: "项目名称?", placeholder: "my-app" });
    if (p.isCancel(name)) { p.cancel("已取消."); process.exit(0); }

    const spinner = ora("正在创建项目...").start();
    await createProject(name, options.template);
    spinner.succeed(chalk.green("项目创建成功!"));

    p.outro(`运行 ${chalk.cyan(`cd ${name} && npm install`)}`);
  });

program.parse();

// package.json: { "bin": { "my-tool": "./dist/index.js" } }

避免

  • 将错误输出到 stdout — 应用 console.error() 或 process.stderr.write() 输出错误
  • 失败时不带退出码退出 — 始终使用 process.exit(1),以便脚本和 CI 能够检测到失败
  • 大段无格式文本 — 使用 chalk 颜色、分节和空白提高可读性
  • 要求交互式输入而不提供标志替代方案 — 始终支持 --flag 覆盖选项以用于 CI/脚本环境
  • 忘记 shebang #!/usr/bin/env node — 没有它,npx 和全局安装将无法正常工作

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Tenant isolation (row-level vs schema), subdomain routing, per-tenant config, and data partitioning.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

相关技能