@k2works/claude-code-booster 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,465 @@
1
+ # TypeScript アプリケーション環境構築ガイド
2
+
3
+ ## 概要
4
+
5
+ 本ガイドは、TypeScript アプリケーション開発環境をゼロから構築し、ソフトウェア開発の三種の神器(バージョン管理、テスティング、自動化)を実践するための手順書です。テスト駆動開発(TDD)により「動作するきれいなコード」を継続的に作成できる開発環境を整備します。
6
+
7
+ ## 前提条件
8
+
9
+ - Node.js 18 以降がインストールされていること
10
+ - npm または yarn がインストールされていること
11
+ - Git がインストールされていること
12
+ - VS Code または WebStorm がインストールされていること(推奨)
13
+
14
+ ## ソフトウェア開発の三種の神器
15
+
16
+ ### 1. バージョン管理
17
+
18
+ #### Git の基本設定
19
+
20
+ ```bash
21
+ # ユーザー設定
22
+ git config --global user.name "Your Name"
23
+ git config --global user.email "your.email@example.com"
24
+
25
+ # リポジトリの初期化
26
+ git init
27
+
28
+ # .gitignore の作成
29
+ echo "node_modules/" >> .gitignore
30
+ echo "dist/" >> .gitignore
31
+ echo "coverage/" >> .gitignore
32
+ echo ".env" >> .gitignore
33
+ echo ".DS_Store" >> .gitignore
34
+ ```
35
+
36
+ #### コミットメッセージ規約(Conventional Commits)
37
+
38
+ ```text
39
+ <タイプ>(<スコープ>): <タイトル>
40
+ <空行>
41
+ <ボディ>
42
+ <空行>
43
+ <フッタ>
44
+ ```
45
+
46
+ **タイプの種類:**
47
+ - `feat`: 新機能の追加
48
+ - `fix`: バグ修正
49
+ - `docs`: ドキュメント変更のみ
50
+ - `style`: コードに影響を与えない変更(フォーマット等)
51
+ - `refactor`: 機能追加でもバグ修正でもないコード変更
52
+ - `perf`: パフォーマンスを改善するコード変更
53
+ - `test`: テストの追加や修正
54
+ - `chore`: ビルドプロセスやツール、ライブラリの変更
55
+
56
+ **例:**
57
+ ```bash
58
+ git commit -m 'feat: ユーザー認証機能を追加'
59
+ git commit -m 'fix: ログイン時のバリデーションエラーを修正'
60
+ git commit -m 'refactor: FizzBuzz クラスのメソッド抽出'
61
+ ```
62
+
63
+ ### 2. テスティング
64
+
65
+ #### プロジェクトの初期化
66
+
67
+ ```bash
68
+ # プロジェクトの初期化
69
+ npm init -y
70
+
71
+ # TypeScript の設定
72
+ npm install -D typescript @types/node
73
+ npx tsc --init
74
+ ```
75
+
76
+ #### テストフレームワークのセットアップ
77
+
78
+ ```bash
79
+ # Vitest とテスト関連パッケージのインストール
80
+ npm install -D vitest @vitest/coverage-v8 @types/node
81
+ ```
82
+
83
+ #### package.json の設定
84
+
85
+ ```json
86
+ {
87
+ "name": "typescript-app",
88
+ "private": true,
89
+ "version": "0.0.0",
90
+ "type": "module",
91
+ "scripts": {
92
+ "dev": "vite",
93
+ "build": "tsc && vite build",
94
+ "preview": "vite preview",
95
+ "test": "vitest run",
96
+ "test:watch": "vitest",
97
+ "test:coverage": "vitest run --coverage",
98
+ "lint": "eslint . --ext .ts,.tsx",
99
+ "lint:fix": "eslint . --ext .ts,.tsx --fix",
100
+ "format": "prettier --write .",
101
+ "format:check": "prettier --check .",
102
+ "gulp": "gulp",
103
+ "watch": "gulp watch",
104
+ "guard": "gulp guard",
105
+ "check": "gulp checkAndFix",
106
+ "commit": "git add . && git commit",
107
+ "setup": "npm install && npm run check"
108
+ }
109
+ }
110
+ ```
111
+
112
+ #### テストの基本構造
113
+
114
+ ```typescript
115
+ // src/fizz-buzz.ts
116
+ export class FizzBuzz {
117
+ private static readonly MAX_NUMBER = 100
118
+
119
+ public static generate(number: number): string {
120
+ const isFizz = number % 3 === 0
121
+ const isBuzz = number % 5 === 0
122
+
123
+ if (isFizz && isBuzz) return 'FizzBuzz'
124
+ if (isFizz) return 'Fizz'
125
+ if (isBuzz) return 'Buzz'
126
+
127
+ return number.toString()
128
+ }
129
+
130
+ public static generateList(): string[] {
131
+ return Array.from({ length: this.MAX_NUMBER }, (_, i) => this.generate(i + 1))
132
+ }
133
+ }
134
+ ```
135
+
136
+ ```typescript
137
+ // src/fizz-buzz.test.ts
138
+ import { describe, it, expect } from 'vitest'
139
+ import { FizzBuzz } from './fizz-buzz'
140
+
141
+ describe('FizzBuzz', () => {
142
+ describe('三の倍数の場合', () => {
143
+ it('3を渡したら文字列Fizzを返す', () => {
144
+ expect(FizzBuzz.generate(3)).toBe('Fizz')
145
+ })
146
+ })
147
+
148
+ describe('五の倍数の場合', () => {
149
+ it('5を渡したら文字列Buzzを返す', () => {
150
+ expect(FizzBuzz.generate(5)).toBe('Buzz')
151
+ })
152
+ })
153
+
154
+ describe('三と五の倍数の場合', () => {
155
+ it('15を渡したら文字列FizzBuzzを返す', () => {
156
+ expect(FizzBuzz.generate(15)).toBe('FizzBuzz')
157
+ })
158
+ })
159
+ })
160
+ ```
161
+
162
+ #### TDD のサイクル
163
+
164
+ ```bash
165
+ # Red: 失敗するテストを書く
166
+ npm run test
167
+
168
+ # Green: テストを通す最小限の実装
169
+ # コードを修正
170
+
171
+ # Refactor: リファクタリング
172
+ npm run test
173
+
174
+ # コミット
175
+ git add .
176
+ git commit -m 'feat: FizzBuzz 基本機能を実装'
177
+ ```
178
+
179
+ ### 3. 自動化
180
+
181
+ #### 静的コード解析(ESLint)
182
+
183
+ ```bash
184
+ # ESLint のインストール
185
+ npm install -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-prettier eslint-plugin-prettier
186
+ ```
187
+
188
+ #### eslint.config.js の設定
189
+
190
+ ```javascript
191
+ export default [
192
+ {
193
+ files: ['**/*.ts', '**/*.tsx'],
194
+ languageOptions: {
195
+ parser: '@typescript-eslint/parser',
196
+ parserOptions: {
197
+ ecmaVersion: 2020,
198
+ sourceType: 'module'
199
+ }
200
+ },
201
+ plugins: {
202
+ '@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
203
+ 'prettier': require('eslint-plugin-prettier')
204
+ },
205
+ rules: {
206
+ // 基本的なルール
207
+ '@typescript-eslint/no-unused-vars': 'error',
208
+ '@typescript-eslint/no-explicit-any': 'warn',
209
+
210
+ // 循環的複雑度の制限(7以下を推奨)
211
+ 'complexity': ['error', { max: 7 }],
212
+
213
+ // Prettier 統合
214
+ 'prettier/prettier': 'error'
215
+ }
216
+ },
217
+ {
218
+ files: ['**/*.test.{ts,tsx}'],
219
+ rules: {
220
+ '@typescript-eslint/no-unused-expressions': 'off',
221
+ '@typescript-eslint/no-unused-vars': 'warn'
222
+ }
223
+ }
224
+ ]
225
+ ```
226
+
227
+ #### コードフォーマッタ(Prettier)
228
+
229
+ ```bash
230
+ # Prettier のインストール
231
+ npm install -D prettier eslint-config-prettier eslint-plugin-prettier
232
+ ```
233
+
234
+ #### .prettierrc の設定
235
+
236
+ ```json
237
+ {
238
+ "semi": false,
239
+ "singleQuote": true,
240
+ "tabWidth": 2,
241
+ "trailingComma": "es5",
242
+ "printWidth": 100,
243
+ "endOfLine": "lf"
244
+ }
245
+ ```
246
+
247
+ #### コードカバレッジ
248
+
249
+ Vitest に組み込まれたカバレッジ機能を使用:
250
+
251
+ ```bash
252
+ # カバレッジの実行
253
+ npm run test:coverage
254
+ ```
255
+
256
+ #### vitest.config.ts の設定
257
+
258
+ ```typescript
259
+ import { defineConfig } from 'vitest/config'
260
+
261
+ export default defineConfig({
262
+ test: {
263
+ coverage: {
264
+ reporter: ['text', 'html', 'json'],
265
+ reportsDirectory: 'coverage',
266
+ exclude: [
267
+ 'node_modules/**',
268
+ 'dist/**',
269
+ '**/*.test.ts',
270
+ '**/*.config.js',
271
+ '**/*.config.ts',
272
+ 'src/main.ts'
273
+ ],
274
+ all: true,
275
+ thresholds: {
276
+ global: {
277
+ branches: 80,
278
+ functions: 80,
279
+ lines: 80,
280
+ statements: 80
281
+ }
282
+ }
283
+ }
284
+ }
285
+ })
286
+ ```
287
+
288
+ #### タスクランナー(Gulp)
289
+
290
+ ```bash
291
+ # Gulp のインストール
292
+ npm install -D gulp gulp-shell
293
+ ```
294
+
295
+ #### gulpfile.js の設定
296
+
297
+ ```javascript
298
+ import { watch, series } from 'gulp'
299
+ import shell from 'gulp-shell'
300
+
301
+ // 基本タスク
302
+ export const test = shell.task(['npm run test'])
303
+ export const coverage = shell.task(['npm run test:coverage'])
304
+ export const lint = shell.task(['npm run lint'])
305
+ export const lintFix = shell.task(['npm run lint:fix'])
306
+ export const format = shell.task(['npm run format'])
307
+ export const formatCheck = shell.task(['npm run format:check'])
308
+ export const build = shell.task(['npm run build'])
309
+ export const dev = shell.task(['npm run dev'])
310
+
311
+ // 複合タスク
312
+ export const checkAndFix = series(lintFix, format, test)
313
+
314
+ // ファイル監視タスク(Guard機能)
315
+ export function guard() {
316
+ console.log('🔍 Guard is watching for file changes...')
317
+ console.log('Files will be automatically linted, formatted, and tested on change.')
318
+ watch('src/**/*.ts', series(lintFix, format, test))
319
+ watch('**/*.test.ts', series(test))
320
+ }
321
+
322
+ // ファイル監視タスク
323
+ export function watchFiles() {
324
+ watch('src/**/*.ts', series(formatCheck, lint, test))
325
+ watch('**/*.test.ts', series(test))
326
+ }
327
+
328
+ // デフォルトタスク
329
+ export default series(checkAndFix, guard)
330
+
331
+ // ウォッチタスクのエイリアス
332
+ export { watchFiles as watch }
333
+ ```
334
+
335
+ ## 開発ワークフロー
336
+
337
+ ### 1. 環境のセットアップ
338
+
339
+ ```bash
340
+ # プロジェクトの初期化
341
+ npm init -y
342
+
343
+ # 依存関係のインストール
344
+ npm install
345
+
346
+ # 初期チェック実行
347
+ npm run setup
348
+ ```
349
+
350
+ ### 2. 開発の開始
351
+
352
+ ```bash
353
+ # Guard を起動(自動テスト・リント・フォーマット)
354
+ npm run guard
355
+
356
+ # 別ターミナルで開発サーバーを起動
357
+ npm run dev
358
+ ```
359
+
360
+ ### 3. TDD サイクルの実践
361
+
362
+ 1. **Red**: 失敗するテストを作成
363
+ ```bash
364
+ # テストファイル作成・編集
365
+ # Guard が自動でテスト実行し、失敗を確認
366
+ ```
367
+
368
+ 2. **Green**: テストを通す最小限の実装
369
+ ```bash
370
+ # 実装コードを作成
371
+ # Guard が自動でテスト実行し、成功を確認
372
+ ```
373
+
374
+ 3. **Refactor**: コードをリファクタリング
375
+ ```bash
376
+ # コードを改善
377
+ # Guard が自動でリント・フォーマット・テスト実行
378
+ ```
379
+
380
+ 4. **Commit**: 作業をコミット
381
+ ```bash
382
+ git add .
383
+ git commit -m 'feat: 新機能を実装'
384
+ ```
385
+
386
+ ### 4. 品質チェック
387
+
388
+ ```bash
389
+ # 全体的な品質チェック
390
+ npm run check
391
+
392
+ # カバレッジ確認
393
+ npm run test:coverage
394
+
395
+ # 静的解析
396
+ npm run lint
397
+
398
+ # フォーマットチェック
399
+ npm run format:check
400
+ ```
401
+
402
+ ## ベストプラクティス
403
+
404
+ ### 1. テスト戦略
405
+
406
+ - **単体テスト**: 各機能の動作を検証
407
+ - **統合テスト**: 複数のコンポーネント間の協調を検証
408
+ - **E2E テスト**: ユーザーの視点から全体的な動作を検証
409
+
410
+ ### 2. コード品質
411
+
412
+ - **循環的複雑度**: 7以下を維持
413
+ - **テストカバレッジ**: 80%以上を目標
414
+ - **ESLint ルール**: プロジェクトに応じてカスタマイズ
415
+
416
+ ### 3. 継続的改善
417
+
418
+ - **定期的なリファクタリング**: 技術的負債の蓄積を防ぐ
419
+ - **コードレビュー**: チーム全体のコード品質向上
420
+ - **ツールのアップデート**: セキュリティと性能の維持
421
+
422
+ ## トラブルシューティング
423
+
424
+ ### よくある問題と解決法
425
+
426
+ #### 1. テストが実行されない
427
+
428
+ ```bash
429
+ # node_modules を再インストール
430
+ rm -rf node_modules package-lock.json
431
+ npm install
432
+
433
+ # キャッシュをクリア
434
+ npm cache clean --force
435
+ ```
436
+
437
+ #### 2. ESLint エラーが発生
438
+
439
+ ```bash
440
+ # 自動修正を試行
441
+ npm run lint:fix
442
+
443
+ # 設定ファイルを確認
444
+ cat eslint.config.js
445
+ ```
446
+
447
+ #### 3. TypeScript コンパイルエラー
448
+
449
+ ```bash
450
+ # TypeScript 設定を確認
451
+ cat tsconfig.json
452
+
453
+ # 型定義を再インストール
454
+ npm install -D @types/node
455
+ ```
456
+
457
+ ## 参考資料
458
+
459
+ - [Conventional Commits](https://www.conventionalcommits.org/ja/)
460
+ - [Vitest 公式ドキュメント](https://vitest.dev/)
461
+ - [ESLint 公式ドキュメント](https://eslint.org/)
462
+ - [Prettier 公式ドキュメント](https://prettier.io/)
463
+ - [TypeScript 公式ドキュメント](https://www.typescriptlang.org/)
464
+
465
+ このガイドに従って環境を構築することで、効率的で品質の高い TypeScript アプリケーション開発が可能になります。