code-setup-project

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Set up a project development environment with wrapper scripts and/or a Nix flake.
使用 wrapper 脚本和/或 Nix flake 搭建项目开发环境。

Parameters

参数

  • location: Desired location for setup artifacts.
    • "machine-local": Inside
      .my/
      (ignored by git, good for personal tools).
    • "project-local": Root level (e.g.,
      bin/
      ,
      flake.nix
      ).
  • setup_types: What to set up ("wrapper", "flake", or "both").
If these parameters are not explicitly provided in the request, infer them from context or ask the user for clarification before proceeding.
  • location:搭建产物的目标存放位置
    • "machine-local":存放在
      .my/
      目录下(git 会忽略该目录,适合个人工具使用)
    • "project-local":存放在项目根目录(例如
      bin/
      flake.nix
  • setup_types:需要搭建的内容(可选值为 "wrapper"、"flake" 或 "both")
如果请求中未明确提供这些参数,请先从上下文推断,或向用户确认后再继续操作。

Process

流程

For each setup type selected:
针对每个选中的搭建类型执行如下操作:

Wrapper Scripts

Wrapper 脚本

  1. Determine paths based on location:
    • Machine-local:
      .my/bin/
      with
      my-
      prefix
    • Project-local:
      bin/
      , ask about naming:
      • Generic:
        test
        ,
        lint
        ,
        fmt
        ,
        build
        ,
        dev
      • Prefixed (default):
        <project-name>-test
        , etc.
  2. Invoke the
    code-analyze-project
    skill to:
    • Detect project type
    • Recommend wrappers (test, lint, fmt, build, dev commands)
  3. Present recommended wrappers and ask which to create
  4. Create wrapper directory if needed
  5. If machine-local: Create
    .my/.gitignore
    with content
    *
  6. Create wrapper scripts with template:
bash
#!/usr/bin/env bash
set -euo pipefail
<command>
  1. Make executable:
    chmod +x <dir>/*
  1. 根据存储位置确定路径:
    • 本地机器级:
      .my/bin/
      目录,脚本前缀为
      my-
    • 项目本地级:
      bin/
      目录,询问用户命名规则:
      • 通用命名:
        test
        lint
        fmt
        build
        dev
      • 带前缀(默认):
        <项目名>-test
        等格式
  2. 调用
    code-analyze-project
    技能,完成以下操作:
    • 检测项目类型
    • 推荐需要的 wrapper 脚本(test、lint、fmt、build、dev 相关命令)
  3. 展示推荐的 wrapper 脚本列表,询问用户需要创建哪些
  4. 若所需目录不存在则先创建 wrapper 脚本存放目录
  5. 如果是本地机器级存储:创建
    .my/.gitignore
    文件,内容为
    *
  6. 按照如下模板创建 wrapper 脚本:
bash
#!/usr/bin/env bash
set -euo pipefail
<command>
  1. 赋予脚本可执行权限:
    chmod +x <dir>/*

Nix Flake

Nix Flake

  1. Determine path based on location:
    • Machine-local:
      .my/flake.nix
    • Project-local:
      flake.nix
  2. Check for existing flake at the determined path
  3. Detect project type and required packages:
    • Node.js: package.json → nodejs, npm/pnpm/yarn
    • Python: pyproject.toml, setup.py → python3, pip/poetry/uv
    • Go: go.mod → go, gopls
    • Rust: Cargo.toml → cargo, rustc
    • Ruby: Gemfile → ruby, bundler
    • Other: check for Makefile, CMakeLists.txt, etc.
  4. Generate flake using the template in templates/flake.nix
    • Use
      buildInputs
      (not
      packages
      ) for dependencies
    • No shellHook unless absolutely necessary
    • Keep it simple and minimal
    • If updating existing flake, preserve custom inputs/outputs but simplify structure
  5. If machine-local: Create
    .my/.gitignore
    with content
    *
    if not exists
  6. Verify the flake:
    nix flake check path:.
  • If verification fails, fix issues and re-verify
  1. 根据存储位置确定路径:
    • 本地机器级:
      .my/flake.nix
    • 项目本地级:
      flake.nix
  2. 检查确定的路径下是否已存在 flake 文件
  3. 检测项目类型和所需依赖包:
    • Node.js:存在 package.json → 依赖 nodejs、npm/pnpm/yarn
    • Python:存在 pyproject.toml、setup.py → 依赖 python3、pip/poetry/uv
    • Go:存在 go.mod → 依赖 go、gopls
    • Rust:存在 Cargo.toml → 依赖 cargo、rustc
    • Ruby:存在 Gemfile → 依赖 ruby、bundler
    • 其他:检查是否存在 Makefile、CMakeLists.txt 等文件
  4. 使用 templates/flake.nix 中的模板生成 flake 文件
    • 依赖项放入
      buildInputs
      (不要放在
      packages
      中)
    • 除非绝对必要,否则不要添加 shellHook
    • 保持配置简洁最小化
    • 如果是更新已有 flake,保留自定义的 inputs/outputs,但简化整体结构
  5. 如果是本地机器级存储:若
    .my/.gitignore
    不存在则创建,内容为
    *
  6. 验证 flake 配置:
    nix flake check path:.
  • 如果验证失败,修复问题后重新验证

Output

输出

  • Project type detected
  • Wrapper/flake location created
  • Scripts/flake created (with descriptions)
  • How to use
  • 检测到的项目类型
  • 创建的 wrapper/flake 存放位置
  • 已创建的脚本/flake 文件(附带说明)
  • 使用说明