Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
310 changes: 310 additions & 0 deletions .claude/commands/setup-new-repo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,310 @@
---
description: Setup new repository with DevContainer, CI/CD, and development tools from config template
allowed-tools: Read, Write, Edit, Bash(git:*), Bash(gh:*), Bash(npm:*), Bash(mkdir:*), Bash(cp:*), Bash(ls:*), Bash(cat:*), Bash(test:*), Task, Glob, Grep
argument-hint: '<TARGET_DIR> [--minimal] [--no-devcontainer] [--license MIT|Apache-2.0] [--no-install]'
---

# New Repository Setup Command

新しいリポジトリにDevContainer、CI/CD、開発ツールをセットアップします。

## Overview

以下をセットアップします:

1. **Git初期化** - リポジトリの初期化
2. **DevContainer** - `.devcontainer/` と `.vscode/` 設定
3. **Git設定** - commitlint, `.gitignore`
4. **GitHub Actions** - CI workflow, Issue/PRテンプレート
5. **開発ツール** - ESLint, Prettier, Jest, Husky
6. **ドキュメント** - README.md, CLAUDE.md, SECURITY.md

## Step 1: Parse Arguments

引数から設定を読み取る:

- `TARGET_DIR`: 新規リポジトリのパス(必須)
- `--minimal`: GitHub Actionsをスキップ
- `--no-devcontainer`: DevContainer設定をスキップ
- `--license TYPE`: ライセンス種別(デフォルト: MIT)
- `--no-install`: npm install をスキップ

## Step 2: Validate Target Directory

ターゲットディレクトリを確認:

```bash
# ディレクトリが存在するか確認
ls -la TARGET_DIR 2>/dev/null || echo "Directory will be created"
```

既存のリポジトリがある場合は警告を表示し、上書きの確認を取る。

## Step 3: Get Config Repository Path

このconfigリポジトリのパスを取得:

```bash
# 現在のリポジトリパスを確認
git rev-parse --show-toplevel
```

## Step 4: Initialize Git Repository

```bash
cd TARGET_DIR
git init
```

Comment on lines +52 to +58

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add directory creation before cd TARGET_DIR.

The command sequence attempts to cd TARGET_DIR without ensuring the directory exists first. Step 2 mentions "Directory will be created" but Step 4 doesn't actually create it. If the target directory doesn't exist, the cd command will fail.

📁 Proposed fix to create directory first
+```bash
+mkdir -p TARGET_DIR
+```
+
 ```bash
 cd TARGET_DIR
 git init
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Step 4: Initialize Git Repository
```bash
cd TARGET_DIR
git init
```
## Step 4: Initialize Git Repository
🤖 Prompt for AI Agents
In @.claude/commands/setup-new-repo.md around lines 52 - 58, The "Step 4:
Initialize Git Repository" sequence uses "cd TARGET_DIR" without ensuring the
directory exists; update this step to create the directory first by running
"mkdir -p TARGET_DIR" (or equivalent) before "cd TARGET_DIR" so the subsequent
"git init" won't fail if the target directory is missing; modify the block
containing "cd TARGET_DIR" and "git init" to include the directory creation
command immediately above the cd command.

## Step 5: Copy DevContainer Configuration (unless --no-devcontainer)

```bash
# .devcontainer をコピー
cp -r CONFIG_REPO/.devcontainer TARGET_DIR/

# .vscode をコピー
cp -r CONFIG_REPO/.vscode TARGET_DIR/
```

### DevContainer 設定内容

- `ghcr.io/keito4/config-base:latest` ベースイメージ
- Node.js 22+
- 推奨VS Code拡張機能

## Step 6: Setup Git Configuration

### 6.1 Commitlint設定

```bash
cp CONFIG_REPO/git/commitlint.config.js TARGET_DIR/
```

### 6.2 .gitignore作成

以下の内容で `.gitignore` を作成:

```gitignore
# Dependencies
node_modules/
.pnp
.pnp.js

# Testing
coverage/
*.lcov

# Production
build/
dist/
*.tgz

# Misc
.DS_Store
.env
.env.local
.env.*.local

# Logs
logs
*.log
npm-debug.log*

# IDE
.idea/
*.swp
*.swo
*~
.vscode/settings.local.json

# OS
Thumbs.db
```

## Step 7: Copy GitHub Actions (unless --minimal)

```bash
mkdir -p TARGET_DIR/.github/workflows
cp CONFIG_REPO/.github/workflows/ci.yml TARGET_DIR/.github/workflows/

mkdir -p TARGET_DIR/.github/ISSUE_TEMPLATE
cp -r CONFIG_REPO/.github/ISSUE_TEMPLATE/* TARGET_DIR/.github/ISSUE_TEMPLATE/

cp CONFIG_REPO/.github/PULL_REQUEST_TEMPLATE.md TARGET_DIR/.github/
```

## Step 8: Setup Development Tools

### 8.1 package.json 作成

```json
{
"name": "new-project",
"version": "1.0.0",
"description": "New project bootstrapped from config repository",
"scripts": {
"lint": "eslint . --ext .js,.ts,.tsx",
"lint:fix": "npm run lint -- --fix",
"format": "prettier --write .",
"format:check": "prettier --check .",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"prepare": "husky"
},
"devDependencies": {
"@commitlint/cli": "^19.0.0",
"@commitlint/config-conventional": "^19.0.0",
"eslint": "^9.0.0",
"husky": "^9.0.0",
"jest": "^29.0.0",
"prettier": "^3.0.0"
}
}
```

### 8.2 設定ファイルをコピー

```bash
cp CONFIG_REPO/eslint.config.mjs TARGET_DIR/
cp CONFIG_REPO/.prettierrc TARGET_DIR/
cp CONFIG_REPO/jest.config.js TARGET_DIR/
```

## Step 9: Create Documentation

### 9.1 README.md

プロジェクト名を含むREADMEを作成:

```markdown
# {project-name}

<!-- TODO: Add project description -->

## Features

<!-- TODO: List key features -->

## Getting Started

### Prerequisites

- Node.js 22+
- npm or pnpm

### Installation

\`\`\`bash
npm install
\`\`\`

### Development

\`\`\`bash
npm run dev
\`\`\`

### Testing

\`\`\`bash
npm test
npm run test:coverage
\`\`\`

## Contributing

Please read [CLAUDE.md](./CLAUDE.md) for development guidelines.

## License

This project is licensed under the {LICENSE} License.
```

### 9.2 CLAUDE.md

```bash
cp CONFIG_REPO/.claude/CLAUDE.md TARGET_DIR/
```

### 9.3 SECURITY.md

セキュリティポリシーを作成。

Comment on lines +230 to +233

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Complete SECURITY.md creation step.

Step 9.3 mentions creating a security policy ("セキュリティポリシーを作成") but doesn't provide the content, template, or command to create it. This step is incomplete compared to the detailed instructions provided for README.md and other files.

📄 Suggestion to complete this step

Either provide the SECURITY.md template content inline (similar to the README.md template) or specify copying from the config repository:

cp CONFIG_REPO/SECURITY.md TARGET_DIR/

Or provide a basic template if one doesn't exist in the config repo.

🤖 Prompt for AI Agents
In @.claude/commands/setup-new-repo.md around lines 230 - 233, Update the "9.3
SECURITY.md" step to include a concrete SECURITY.md creation action: either
paste a basic SECURITY.md template (e.g., reporting process, contact, PGP key,
disclosure timeline) directly under the "### 9.3 SECURITY.md" section or add a
copy command that pulls the file from the config repo (e.g., cp
CONFIG_REPO/SECURITY.md TARGET_DIR/) and mention which repo/path to use; ensure
the section clearly shows the template content or the exact copy command and
destination so the step is actionable.

## Step 10: Install Dependencies (unless --no-install)

```bash
cd TARGET_DIR
npm install
npx husky init
```

## Step 11: Generate Summary

```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Repository Setup Complete
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📁 Target: {TARGET_DIR}

Files Created:
✅ .devcontainer/
✅ .vscode/
✅ .github/workflows/ci.yml
✅ .github/ISSUE_TEMPLATE/
✅ .github/PULL_REQUEST_TEMPLATE.md
✅ package.json
✅ eslint.config.mjs
✅ .prettierrc
✅ jest.config.js
✅ commitlint.config.js
✅ .gitignore
✅ README.md
✅ CLAUDE.md
✅ SECURITY.md

Next Steps:
1. cd {TARGET_DIR}
2. Update README.md with project details
3. Update package.json (name, description)
4. git add . && git commit -m "chore: initial setup"
5. gh repo create (optional)
6. git push -u origin main

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
Comment on lines +244 to +276

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Specify language for fenced code block.

The fenced code block lacks a language specification. While this is output text rather than executable code, specifying text or plaintext would satisfy the linter and improve clarity.

📝 Proposed fix
-```
+```text
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 ✅ Repository Setup Complete
🧰 Tools
🪛 markdownlint-cli2 (0.20.0)

[warning] 244-244: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
In @.claude/commands/setup-new-repo.md around lines 244 - 276, The fenced code
block containing the "Repository Setup Complete" banner is missing a language
identifier; update that block to use a plaintext language tag (e.g., add
```text) so the linter is satisfied and the output is rendered clearly—locate
the fenced block that wraps the banner text and change its opening
triple-backticks to include "text" (or "plaintext").


## Options Summary

| オプション | 説明 | デフォルト |
| ------------------- | -------------------------- | ---------- |
| `--minimal` | GitHub Actionsをスキップ | false |
| `--no-devcontainer` | DevContainer設定をスキップ | false |
| `--license TYPE` | ライセンス種別 | MIT |
| `--no-install` | npm installをスキップ | false |

## Alternative: Use Shell Script

シェルスクリプトを直接実行することも可能:

```bash
/path/to/config/script/setup-new-repo.sh TARGET_DIR [OPTIONS]
```

Comment on lines +287 to +294

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for setup-new-repo.sh in the repository
echo "=== Searching for setup-new-repo.sh ==="
fd -t f 'setup-new-repo\.sh' || echo "No matches found"

echo ""
echo "=== Searching for any script directory ==="
fd -t d 'script' || echo "No script directories found"

echo ""
echo "=== Checking the documentation file ==="
head -n 300 .claude/commands/setup-new-repo.md | tail -n 30

Repository: keito4/config

Length of output: 1132


Remove or clarify the non-existent shell script reference.

The shell script setup-new-repo.sh does not exist in the repository. The path /path/to/config/script/setup-new-repo.sh is a placeholder that will confuse users. Either remove this section or add a note that it describes a planned feature and is not yet available.

🤖 Prompt for AI Agents
In @.claude/commands/setup-new-repo.md around lines 287 - 294, The documentation
references a non-existent shell script path
`/path/to/config/script/setup-new-repo.sh` which will confuse users; either
remove the "Alternative: Use Shell Script" section or update it to clearly mark
the script as a placeholder/planned feature (e.g., "script not yet available")
and remove the absolute placeholder path, ensuring references to
"setup-new-repo.sh" or the section header "Alternative: Use Shell Script" are
updated accordingly so readers aren’t misled.

## Related Commands

| コマンド | 説明 |
| -------------------------- | ------------------------------ |
| `/setup-ci` | CI/CDワークフローの詳細設定 |
| `/setup-husky` | Husky + lint-staged の詳細設定 |
| `/setup-team-protection` | ブランチ保護ルールの設定 |
| `/config-base-sync-update` | DevContainerを最新に更新 |

## Error Handling

エラー発生時:

1. 具体的なエラー内容を報告
2. 手動での修正方法を提案
3. 部分的な成功でも適用可能な変更は適用