关于 project-init
project-init 是用于启动新软件项目的技能,可创建通用目录结构和基础开发文件。支持 generic、Python、Node、Rust 和 Go 项目类型,并可选择创建 GitHub 仓库。
主要功能
- 01创建源码、测试和文档目录
- 02初始化 Git 仓库
- 03添加 README、许可证和 gitignore
- 04配置 EditorConfig 与 pre-commit
- 05添加 GitHub Actions CI 工作流
- 06可创建 GitHub 仓库
适用场景
- 01从头启动新的代码库
- 02创建标准项目骨架
- 03准备基础 CI 和开发文件
- 04为项目创建 GitHub 仓库
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ laurigates/ claude-plugins --skill project-init安装后在 Claude Code 中输入/project-init确认已加载。
详细介绍
/project:init
何时使用此技能
| 在以下情况下使用此技能…… | 在以下情况下改用 project-discovery…… |
|---|---|
| 从头搭建全新项目(src/tests/docs、README、CI) | 在已有结构的现有仓库中工作 |
| 使用通用基础布局初始化 Python/Node/Rust/Go 代码库 | 在已建立的项目中继续工作时,改用 project-continue |
| 创建与本地骨架相匹配的 GitHub 仓库 | 从现有项目中提取模式时,改用 project-distill |
上下文
- 当前目录:!
pwd - Git 用户:!
git config user.name - GitHub CLI:!
which gh
参数
$1:项目名称(必填)$2:项目类型(python|node|rust|go|generic)——默认为 generic$3:用于创建 GitHub 仓库的 --github 标志$4:用于创建私有仓库的 --private 标志
基础项目结构
创建所有项目都需要的通用项目结构:
1. 核心目录
mkdir -p $1/{src,tests,docs,.github/workflows}
cd $1
2. Git 设置
git init
3. 基础文档
README.md:
# $1
## Description
[Project description]
## Installation
See [Installation Guide](docs/installation.md)
## Usage
See [Usage Guide](docs/usage.md)
## Development
See [Development Guide](docs/development.md)
## License
MIT
LICENSE: 创建标准 MIT 许可证文件
.gitignore: 添加适用于所有语言的常见模式
4. EditorConfig
.editorconfig:
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{py,rs,go}]
indent_size = 4
[*.md]
trim_trailing_whitespace = false
5. Pre-commit 基础配置
.pre-commit-config.yaml:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-merge-conflict
- id: detect-private-key
6. GitHub Actions 基础配置
.github/workflows/ci.yml:
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run linters
run: echo "Linting step - configure based on project type"
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: echo "Testing step - configure based on project type"
7. Makefile 基础配置
创建带彩色输出的通用 Makefile:
.PHONY: help install test lint format clean
help:
@echo "Available commands:"
@echo " make install - Install dependencies"
@echo " make test - Run tests"
@echo " make lint - Run linters"
@echo " make format - Format code"
@echo " make clean - Clean build artifacts"
install:
@echo "Installing dependencies..."
test:
@echo "Running tests..."
lint:
@echo "Running linters..."
format:
@echo "Formatting code..."
clean:
@echo "Cleaning..."
语言专属设置
基础初始化仅创建通用结构。之后使用 configure-plugin 技能应用语言专属工具链
(包管理器、代码检查器/格式化工具、测试框架、Dockerfile)——请参阅该插件的
README,了解当前技能列表。不要依赖单条引导命令;根据实际需要组合使用
configure 技能。
创建 GitHub 仓库
{{ if $3 == "--github" }}
创建 GitHub 仓库。${4:---public} 会在 $4 为
--private 时展开为 --private,否则展开为 --public——因此只会传递一个可见性标志
(绝不会同时传递两者):
gh repo create $1 "${4:---public}" --clone
git remote add origin https://github.com/$(gh api user -q .login)/$1.git
{{ endif }}
最后步骤
- 初始化 git hooks:
pre-commit install - 创建初始提交:使用 SlashCommand:
/git:commit "Initial project structure" - 设置 CI/CD:根据项目类型进行配置
- 安装依赖项:使用 SlashCommand:
/deps:install
后续步骤建议
根据项目类型建议相关命令:
/test:setup- 设置测试基础设施/git:pr- 创建第一个 PR
评论
支持 Markdown