Communitygithub.com

YepAPI/skills

Commander.js、使用 Clack 的互動式提示、旋轉指示器、色彩、設定檔、退出碼與 npm 發佈。

skills 是什麼?

這項技能提供了一套完整的 CLI 工具開發規則與模式,專注於使用 Commander.js 處理參數解析,並結合 @clack/prompts 或 inquirer 實作現代化的互動式提示。它涵蓋了使用 ora 顯示長時間操作的旋轉指示器、以 chalk 進行色彩化輸出(錯誤用紅色、成功用綠色、警告用黃色),以及透過 cosmiconfig 自動搜尋多種格式的設定檔(如 .toolrc、.toolrc.json、tool.config.js)。技能也明確定義了退出碼使用慣例(0 成功、1 一般錯誤、2 用法錯誤),並強調在 package.json 設定 bin 欄位、加入 #!/usr/bin/env node shebang 以及使用 ESM 的 type: module。主要支援的開發平台包括 Node.js 與 npm,適合用於建置結構化、可腳本化的 CLI 工具,特別注重 CI/CD 相容性與使用者體驗。

相容平台~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.js 會自動加入這些 — 為每個選項撰寫清晰的描述
  • 錯誤處理:在頂層捕捉錯誤,向 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.

相關技能