project-init
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext
环境信息
- Current directory: !
pwd - Git user: !
git config user.name - GitHub CLI: !
which gh
- 当前目录: !
pwd - Git 用户: !
git config user.name - GitHub CLI: !
which gh
Parameters
参数
- : Project name (required)
$1 - : Project type (python|node|rust|go|generic) - defaults to generic
$2 - : --github flag to create GitHub repository
$3 - : --private flag for private repository
$4
- : 项目名称(必填)
$1 - : 项目类型(python|node|rust|go|generic)- 默认值为 generic
$2 - : --github 标志,用于创建 GitHub 仓库
$3 - : --private 标志,用于创建私有仓库
$4
Base Project Structure
基础项目结构
Create universal project structure that all projects need:
创建所有项目通用的项目结构:
1. Core Directories
1. 核心目录
bash
mkdir -p $1/{src,tests,docs,.github/workflows}
cd $1bash
mkdir -p $1/{src,tests,docs,.github/workflows}
cd $12. Git Setup
2. Git 配置
bash
git initbash
git init3. Base Documentation
3. 基础文档
README.md:
markdown
undefinedREADME.md:
markdown
undefined$1
$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:**
Create standard MIT license file
**.gitignore:**
Create with common patterns for all languagesMIT
**LICENSE:**
创建标准 MIT 许可证文件
**.gitignore:**
创建包含多语言通用忽略规则的 .gitignore 文件4. EditorConfig
4. EditorConfig 配置
.editorconfig:
ini
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.editorconfig:
ini
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 = false5. Pre-commit Base Config
5. Pre-commit 基础配置
.pre-commit-config.yaml:
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.pre-commit-config.yaml:
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-key6. GitHub Actions Base
6. GitHub Actions 基础配置
.github/workflows/ci.yml:
yaml
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".github/workflows/ci.yml:
yaml
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 Base
7. Makefile 基础模板
Create universal Makefile with colored output:
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..."创建带彩色输出的通用 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..."Language-Specific Setup
特定语言环境配置
Based on project type, delegate to specialized setup:
{{ if $2 == "python" }}
Use SlashCommand:
{{ elif $2 == "node" }}
Use SlashCommand:
{{ elif $2 == "rust" }}
Use SlashCommand:
{{ elif $2 == "go" }}
Use SlashCommand:
{{ else }}
/setup:new-project python/setup:new-project node/setup:new-project rust/setup:new-project go根据项目类型,调用专门的配置命令:
{{ if $2 == "python" }}
使用 SlashCommand:
{{ elif $2 == "node" }}
使用 SlashCommand:
{{ elif $2 == "rust" }}
使用 SlashCommand:
{{ elif $2 == "go" }}
使用 SlashCommand:
{{ else }}
/setup:new-project python/setup:new-project node/setup:new-project rust/setup:new-project goGeneric project - base structure only
通用项目 - 仅创建基础结构
{{ endif }}
{{ endif }}
GitHub Repository Creation
GitHub 仓库创建
{{ if $3 == "--github" }}
Create GitHub repository:
bash
gh repo create $1 ${4:+--private} --public --clone
git remote add origin https://github.com/$(gh api user -q .login)/$1.git{{ endif }}
{{ if $3 == "--github" }}
创建 GitHub 仓库:
bash
gh repo create $1 ${4:+--private} --public --clone
git remote add origin https://github.com/$(gh api user -q .login)/$1.git{{ endif }}
Final Steps
最终步骤
- Initialize git hooks:
pre-commit install - Make initial commit: Use SlashCommand:
/git:smartcommit "Initial project structure" - Set up CI/CD: Configure based on project type
- Install dependencies: Use SlashCommand:
/deps:install
- 初始化 Git 钩子:
pre-commit install - 提交初始版本: 使用 SlashCommand:
/git:smartcommit "Initial project structure" - 配置 CI/CD: 根据项目类型进行个性化配置
- 安装依赖: 使用 SlashCommand:
/deps:install
Next Steps Suggestions
后续操作建议
Suggest relevant commands based on project type:
- - Set up testing infrastructure
/test:setup - - Generate documentation
/docs:docs - - Verify code quality
/lint:check - - Create first PR
/github:quickpr
根据项目类型推荐相关命令:
- - 配置测试基础设施
/test:setup - - 生成项目文档
/docs:docs - - 验证代码质量
/lint:check - - 创建第一个 Pull Request
/github:quickpr