Chuyển đến nội dung
Skillpedia
Lập trình chung7.1k · #13572

nx-generate

Skill này làm gì

Skill này dùng các generator mã của Nx để tạo khung cho thư viện, ứng dụng và tính năng mới trong monorepo. Skill dành cho lập trình viên muốn mã mới nhất quán và tuân theo các mẫu riêng của workspace.

Khi nào nên dùng

  • ✓Khi bạn cần tạo khung cho một thư viện, ứng dụng hoặc tính năng mới trong monorepo Nx.
  • ✓Khi workspace của bạn có generator riêng cho một việc lặp lại.
  • ✓Khi bạn muốn mã mới khớp với quy ước của workspace hiện có.

Liên kết skill

https://github.com/tech-leads-club/agent-skills/blob/main/packages/skills-catalog/skills/(tooling)/nx-generate/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/tech-leads-club/agent-skills/blob/main/packages/skills-catalog/skills/(tooling)/nx-generate/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể tạo một thư viện React mới trong workspace Nx của tôi bằng generator mà nhóm tôi đang dùng không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent liệt kê các generator có sẵn, chọn một generator phù hợp với yêu cầu và chạy nó với các tùy chọn đúng. Agent ưu tiên generator cục bộ của workspace hơn generator plugin bên ngoài, vì chúng tuân theo mẫu của repo bạn.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Run Nx Generator

Nx generators are powerful tools that scaffold projects, make automated code migrations or automate repetitive tasks in a monorepo. They ensure consistency across the codebase and reduce boilerplate work.

This skill applies when the user wants to:

  • Create new projects like libraries or applications
  • Scaffold features or boilerplate code
  • Run workspace-specific or custom generators
  • Do anything else that an nx generator exists for

Generator Discovery Flow

Step 1: List Available Generators

Use the Nx CLI to discover available generators:

  • List all generators for a plugin: npx nx list @nx/react
  • View available plugins: npx nx list

This includes:

  • Plugin generators (e.g., @nx/react:library, @nx/js:library)
  • Local workspace generators (defined in the repo's own plugins)

Step 2: Match Generator to User Request

Based on the user's request, identify which generator(s) could fulfill their needs. Consider:

  • What artifact type they want to create (library, application, etc.)
  • Which framework or technology stack is relevant
  • Whether they mentioned specific generator names

IMPORTANT: When both a local workspace generator and an external plugin generator could satisfy the request, always prefer the local workspace generator. Local generators are customized for the specific repo's patterns and conventions.

It's possible that the user request is something that no Nx generator exists for whatsoever. In this case, you can stop using this skill and try to help the user another way. HOWEVER, the burden of proof for this is high. Before aborting, carefully consider each and every generator that's available. Look into details for any that could be related in any way before making this decision.

Pre-Execution Checklist

Before running any generator, complete these steps:

1. Fetch Generator Schema

Use the --help flag to understand all available options:

npx nx g @nx/react:library --help

Pay attention to:

  • Required options that must be provided
  • Optional options that may be relevant to the user's request
  • Default values that might need to be overridden

2. Read Generator Source Code

Understanding what the generator actually does helps you:

  • Know what files will be created/modified
  • Understand any side effects (updating configs, installing deps, etc.)
  • Identify options that might not be obvious from the schema

To find generator source code:

  • For plugin generators: Use node -e "console.log(require.resolve('@nx/<plugin>/generators.json'));" to find the generators.json, then locate the source from there
  • If that fails, read directly from node_modules/<plugin>/generators.json
  • For local generators: They are typically in tools/generators/ or a local plugin directory. You can search the repo for the generator name to find it.

2.5 Reevaluate if the generator is right

Once you have built up an understanding of what the selected generator does, reconsider: Is this the right generator to service the user request? If not, it's okay to go back to the Generator Discovery Flow and select a different generator before proceeding. If you do, make sure to go through the entire pre-execution checklist once more.

3. Understand Repo Context

Before generating, examine the target area of the codebase:

  • Look at similar existing artifacts (other libraries, applications, etc.)
  • Identify patterns and conventions used in the repo
  • Note naming conventions, file structures, and configuration patterns
  • Try to match these patterns when configuring the generator

For example, if similar libraries are using a specific test runner, build tool or linter, try to match that if possible. If projects or other artifacts are organized with a specific naming convention, try to match it.

4. Validate Required Options

Ensure all required options have values:

  • Map the user's request to generator options
  • Infer values from context where possible
  • Ask the user for any critical missing information

Execution

Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Many generators will behave differently based on where they are executed. For example, first-party nx library generators use the cwd to determine the directory that the library should be placed in. This is highly important.

Consider Dry-Run (Optional)

Running with --dry-run first is strongly encouraged but not manda

Câu hỏi thường gặp

Skill chọn generator nào?

Skill ưu tiên generator cục bộ của workspace khi có generator phù hợp, vì chúng khớp với quy ước của repo.

Skill chỉ dùng công cụ Nx à?

Skill dùng dòng lệnh Nx để liệt kê và chạy generator, kể cả generator của plugin.

Skill có tạo khung được mọi thứ trong monorepo không?

Skill hoạt động cho bất kỳ tác vụ nào có generator Nx, như dự án, thư viện hoặc tính năng.

Chi tiết

Mô tả gốc của tác giả

Generate code using Nx generators — scaffold projects, libraries, features, or run workspace-specific generators with proper discovery, validation, and verification. Use when user says "create a new library", "scaffold a component", "generate code with Nx", "run a generator", "nx generate", or any code scaffolding task in a monorepo. Prefers local workspace-plugin generators over external plugins. Do NOT use for running build/test/lint tasks (use nx-run-tasks) or workspace configuration (use nx-workspace).

repo: tech-leads-club/agent-skills

Độ phổ biến

Sao GitHub
7.1k
Vị trí xếp hạng
#13572
Giấy phép
—
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự