04. 開発ワークフロー
開発環境のセットアップ
Section titled “開発環境のセットアップ”1. リポジトリのクローン
Section titled “1. リポジトリのクローン”git clone <repository-url>cd niro-mcp-servers2. 依存関係のインストール
Section titled “2. 依存関係のインストール”# Bun のインストール(未インストールの場合)curl -fsSL https://bun.sh/install | bash
# 依存関係のインストールbun install3. Docker 環境の起動
Section titled “3. Docker 環境の起動”# 開発環境の起動docker-compose -f docker-compose.dev.yml up -d
# ログの確認docker-compose -f docker-compose.dev.yml logs -f confluence-md-dev4. 環境変数の設定
Section titled “4. 環境変数の設定”# .env.example をコピーcp .env.example .env
# 必要な環境変数を設定# - CONFLUENCE_BASE_URL: Confluence のベース URL# - CONFLUENCE_PAT: Personal Access Token(開発用)Git ブランチ戦略
Section titled “Git ブランチ戦略”ブランチ命名規則
Section titled “ブランチ命名規則”main # 本番環境のコード├── develop # 開発の統合ブランチ├── feature/* # 新機能開発│ ├── feature/clean-html-tool│ ├── feature/macro-expander│ └── feature/docker-setup├── fix/* # バグ修正│ └── fix/markdown-conversion-bug└── docs/* # ドキュメント更新 └── docs/api-documentationブランチ作成の流れ
Section titled “ブランチ作成の流れ”# develop から feature ブランチを作成git checkout developgit pull origin developgit checkout -b feature/clean-html-tool
# 作業後、develop にマージgit checkout developgit merge feature/clean-html-tool
# main にマージ(リリース時)git checkout maingit merge developgit tag -a v1.0.0 -m "Release v1.0.0"git push origin main --tagsコミットメッセージ規約
Section titled “コミットメッセージ規約”Conventional Commits 形式
Section titled “Conventional Commits 形式”<type>(<scope>): <subject>
<body>
<footer>Type の種類
Section titled “Type の種類”| Type | 説明 | 例 |
|---|---|---|
feat | 新機能 | feat(cleaner): add info macro expansion |
fix | バグ修正 | fix(parser): handle nested macros correctly |
docs | ドキュメント | docs(readme): update setup instructions |
style | コードスタイル | style(cleaner): format with prettier |
refactor | リファクタリング | refactor(converter): extract markdown utils |
test | テスト追加・修正 | test(cleaner): add macro expansion tests |
chore | ビルド・設定 | chore(docker): update compose config |
perf | パフォーマンス改善 | perf(parser): optimize DOM traversal |
Scope の例
Section titled “Scope の例”cleaner: 共有ロジック(ConfluenceCleaner)parser: HTML パーサーconverter: Markdown 変換mcp: MCP サーバーdocker: Docker 環境docs: ドキュメント
コミットメッセージの例
Section titled “コミットメッセージの例”# 良い例git commit -m "feat(cleaner): add code macro expansion support"git commit -m "fix(parser): handle empty macro body"git commit -m "docs(specs): add Docker configuration"
# 悪い例(避ける)git commit -m "update"git commit -m "fix bug"git commit -m "WIP"プルリクエスト(PR)の流れ
Section titled “プルリクエスト(PR)の流れ”1. PR の作成
Section titled “1. PR の作成”# feature ブランチで作業完了後git push origin feature/clean-html-tool
# GitHub で PR を作成# Base: develop ← Compare: feature/clean-html-tool2. PR テンプレート
Section titled “2. PR テンプレート”## 概要この PR の目的を簡潔に説明
## 変更内容- [ ] 〇〇機能を追加- [ ] △△のバグを修正- [ ] ××のテストを追加
## 関連 IssueCloses #123
## テスト方法1. Docker 環境を起動2. `bun test` を実行3. 〇〇を確認
## スクリーンショット(必要に応じて)
## チェックリスト- [ ] テストが通る- [ ] ドキュメントを更新した- [ ] コミットメッセージが規約に従っている3. レビュー基準
Section titled “3. レビュー基準”- コードの品質: TypeScript の型安全性、エラーハンドリング
- テストカバレッジ: 新機能には必ずテストを追加
- ドキュメント: API の変更はドキュメントも更新
- パフォーマンス: 大量データでの動作確認
- セキュリティ: 外部入力のバリデーション
コーディング規約
Section titled “コーディング規約”TypeScript スタイルガイド
Section titled “TypeScript スタイルガイド”// ✅ 良い例: 明示的な型定義interface CleanOptions { format?: 'markdown' | 'plaintext'; removeUnwanted?: boolean; expandMacros?: boolean; maxLength?: number;}
export class ConfluenceCleaner { clean(html: string, options: CleanOptions = {}): CleanedContent { // 実装 }}
// ❌ 悪い例: any 型の乱用function process(data: any): any { return data;}// クラス: PascalCaseclass ConfluenceCleaner {}
// 関数・変数: camelCasefunction convertToMarkdown() {}const pageContent = '';
// 定数: UPPER_SNAKE_CASEconst MAX_PAGE_SIZE = 1000;
// インターフェース: PascalCase(I プレフィックスなし)interface CleanedContent {}
// 型エイリアス: PascalCasetype MacroType = 'info' | 'warning' | 'code';ファイル構成
Section titled “ファイル構成”// 1. Import 文import { JSDOM } from "jsdom";import TurndownService from "turndown";
// 2. 型定義export interface CleanOptions { // ...}
// 3. 定数const SELECTORS_TO_REMOVE = [ 'script', 'style',];
// 4. クラス実装export class ConfluenceCleaner { // コンストラクタ constructor() {}
// パブリックメソッド clean() {}
// プライベートメソッド private removeUnwanted() {}}テストフレームワーク
Section titled “テストフレームワーク”- テストランナー: Bun のビルトインテストランナー
- ユニットテスト: Bun test
- 統合テスト: Bun test + Docker
- E2E テスト: 実際の Confluence ページを使用
Bun には Jest 互換のテストランナーが組み込まれているため、追加のテストライブラリは不要です。
テストの書き方
Section titled “テストの書き方”import { describe, it, expect } from 'bun:test';import { ConfluenceCleaner } from './cleaner';
describe('ConfluenceCleaner', () => { describe('clean', () => { it('should convert info macro to blockquote', () => { const cleaner = new ConfluenceCleaner(); const html = ` <ac:structured-macro ac:name="info"> <ac:rich-text-body><p>Test info</p></ac:rich-text-body> </ac:structured-macro> `;
const result = cleaner.clean(html);
expect(result.markdown).toContain('> ℹ️ Info: Test info'); expect(result.metadata.macrosExpanded).toBe(1); });
it('should handle empty HTML', () => { const cleaner = new ConfluenceCleaner(); const result = cleaner.clean('');
expect(result.markdown).toBe(''); expect(result.plaintext).toBe(''); });
it('should remove unwanted elements', () => { const cleaner = new ConfluenceCleaner(); const html = '<script>alert("xss")</script><p>Content</p>';
const result = cleaner.clean(html);
expect(result.markdown).not.toContain('script'); expect(result.markdown).toContain('Content'); }); });});テストの実行
Section titled “テストの実行”# すべてのテストを実行bun test
# 特定のファイルのテストを実行bun test cleaner.test.ts
# カバレッジを確認bun test --coverage
# Watch モードで実行bun test --watchテストカバレッジの目標
Section titled “テストカバレッジの目標”- 共有ロジック: 80% 以上
- MCP サーバー: 70% 以上
- 重要な機能: 90% 以上
デバッグ方法
Section titled “デバッグ方法”ローカルでのデバッグ
Section titled “ローカルでのデバッグ”# TypeScript の型チェックbun run typecheck
# ビルドエラーの確認bun run build
# MCP サーバーをローカルで起動してログ確認bun run --filter @niro/mcp-confluence-md devDocker 内でのデバッグ
Section titled “Docker 内でのデバッグ”# コンテナのログを確認docker-compose -f docker-compose.dev.yml logs -f
# コンテナ内に入ってデバッグdocker-compose -f docker-compose.dev.yml exec confluence-md-dev sh
# コンテナ内でテストを実行docker-compose -f docker-compose.dev.yml exec confluence-md-dev bun testMCP サーバーのデバッグ
Section titled “MCP サーバーのデバッグ”// ログ出力の例console.error('Debug:', { html, options }); // stderr に出力
// MCP サーバーは stdio を使うため、console.log は避ける// デバッグ用のログは console.error を使用リリースフロー
Section titled “リリースフロー”1. バージョンアップ
Section titled “1. バージョンアップ”# パッチバージョン (1.0.0 → 1.0.1)bun version patch
# マイナーバージョン (1.0.0 → 1.1.0)bun version minor
# メジャーバージョン (1.0.0 → 2.0.0)bun version major2. CHANGELOG の更新
Section titled “2. CHANGELOG の更新”## [1.1.0] - 2025-11-26
### Added- info/warning/code マクロのサポート- Docker 環境の構築
### Fixed- 空の HTML を処理する際のバグ修正
### Changed- パフォーマンス改善(処理速度 20% 向上)3. リリースタグの作成
Section titled “3. リリースタグの作成”# タグを作成git tag -a v1.1.0 -m "Release v1.1.0"
# タグをプッシュgit push origin v1.1.0トラブルシューティング
Section titled “トラブルシューティング”よくある問題と解決方法
Section titled “よくある問題と解決方法”問題 1: Bun のインストールエラー
Section titled “問題 1: Bun のインストールエラー”# 解決策: 最新版を再インストールcurl -fsSL https://bun.sh/install | bashsource ~/.bashrc # または ~/.zshrc問題 2: Docker コンテナが起動しない
Section titled “問題 2: Docker コンテナが起動しない”# ログを確認docker-compose -f docker-compose.dev.yml logs
# コンテナを再ビルドdocker-compose -f docker-compose.dev.yml build --no-cachedocker-compose -f docker-compose.dev.yml up -d問題 3: 型エラーが解決しない
Section titled “問題 3: 型エラーが解決しない”# node_modules を削除して再インストールrm -rf node_modules bun.lockbbun install
# TypeScript の型キャッシュをクリアrm -rf packages/*/distbun run build