project-init

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Context

环境信息

  • Current directory: !
    pwd
  • Git user: !
    git config user.name
  • GitHub CLI: !
    which gh
  • 当前目录: !
    pwd
  • Git 用户: !
    git config user.name
  • GitHub CLI: !
    which gh

Parameters

参数

  • $1
    : Project name (required)
  • $2
    : Project type (python|node|rust|go|generic) - defaults to generic
  • $3
    : --github flag to create GitHub repository
  • $4
    : --private flag for private repository
  • $1
    : 项目名称(必填)
  • $2
    : 项目类型(python|node|rust|go|generic)- 默认值为 generic
  • $3
    : --github 标志,用于创建 GitHub 仓库
  • $4
    : --private 标志,用于创建私有仓库

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 $1
bash
mkdir -p $1/{src,tests,docs,.github/workflows}
cd $1

2. Git Setup

2. Git 配置

bash
git init
bash
git init

3. Base Documentation

3. 基础文档

README.md:
markdown
undefined
README.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 languages
MIT

**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 = false

5. 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-key

6. 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:
/setup:new-project python
{{ elif $2 == "node" }} Use SlashCommand:
/setup:new-project node
{{ elif $2 == "rust" }} Use SlashCommand:
/setup:new-project rust
{{ elif $2 == "go" }} Use SlashCommand:
/setup:new-project go
{{ else }}
根据项目类型,调用专门的配置命令:
{{ if $2 == "python" }} 使用 SlashCommand:
/setup:new-project python
{{ elif $2 == "node" }} 使用 SlashCommand:
/setup:new-project node
{{ elif $2 == "rust" }} 使用 SlashCommand:
/setup:new-project rust
{{ elif $2 == "go" }} 使用 SlashCommand:
/setup:new-project go
{{ else }}

Generic 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

最终步骤

  1. Initialize git hooks:
    pre-commit install
  2. Make initial commit: Use SlashCommand:
    /git:smartcommit "Initial project structure"
  3. Set up CI/CD: Configure based on project type
  4. Install dependencies: Use SlashCommand:
    /deps:install
  1. 初始化 Git 钩子:
    pre-commit install
  2. 提交初始版本: 使用 SlashCommand:
    /git:smartcommit "Initial project structure"
  3. 配置 CI/CD: 根据项目类型进行个性化配置
  4. 安装依赖: 使用 SlashCommand:
    /deps:install

Next Steps Suggestions

后续操作建议

Suggest relevant commands based on project type:
  • /test:setup
    - Set up testing infrastructure
  • /docs:docs
    - Generate documentation
  • /lint:check
    - Verify code quality
  • /github:quickpr
    - Create first PR
根据项目类型推荐相关命令:
  • /test:setup
    - 配置测试基础设施
  • /docs:docs
    - 生成项目文档
  • /lint:check
    - 验证代码质量
  • /github:quickpr
    - 创建第一个 Pull Request