md-review 0.0.1 → 0.0.2

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Ryo Matsukawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,220 +1,38 @@
1
- # md-preview
1
+ # md-review
2
2
 
3
- ローカルのMarkdownファイルをブラウザで見やすくプレビューするCLIツール
3
+ English | [日本語](./README-ja.md)
4
4
 
5
- ## 特徴
5
+ A CLI tool for reviewing Markdown files with inline comments.
6
+ Comments can be copied and used as feedback for AI agents.
6
7
 
7
- - 🎨 GitHub風の見やすいデザイン
8
- - 🌈 シンタックスハイライト対応(highlight.js)
9
- - ✅ GitHub Flavored Markdown (GFM) サポート
10
- - テーブル
11
- - タスクリスト
12
- - 取り消し線
13
- - 📁 **ファイルツリー表示** - カレントディレクトリ内の全Markdownファイルを一覧表示
14
- - 🗂️ **2カラムレイアウト** - 左側にツリー、右側にプレビュー
15
- - ⚡ 高速な起動(Vite)
16
- - 🚀 軽量なAPIサーバー(Hono)
17
- - 📦 TypeScript + React 19
8
+ ## Features
18
9
 
19
- ## インストール
10
+ - Display Markdown in its original format
11
+ - Add comments to specific lines
12
+ - Select files from tree view
20
13
 
21
- ```bash
22
- # 依存パッケージのインストール
23
- pnpm install
24
- ```
25
-
26
- ## 使い方
27
-
28
- md-previewには**2つのモード**があります:
29
-
30
- ### 1. 開発モード(推奨)
31
-
32
- カレントディレクトリ内の全Markdownファイルをツリー表示し、選択してプレビューできます。
33
-
34
- ```bash
35
- # APIサーバーを起動
36
- node server/index.js &
37
-
38
- # 開発サーバーを起動
39
- pnpm run dev
40
- ```
41
-
42
- または、両方同時に起動:
43
-
44
- ```bash
45
- # APIサーバーをバックグラウンドで起動
46
- node server/index.js &
47
-
48
- # Viteサーバーを起動(http://localhost:6060 が自動で開きます)
49
- pnpm run dev
50
- ```
51
-
52
- ブラウザで `http://localhost:6060` を開くと、以下のようなUIが表示されます:
53
- - **左側**: ファイルツリー(カレントディレクトリ内の全Markdownファイル:.md、.markdown)
54
- - **右側**: 選択されたMarkdownファイルのプレビュー
55
-
56
- ### 2. CLI モード
57
-
58
- 特定のMarkdownファイルのみをプレビューします。
59
-
60
- ```bash
61
- node bin/md-preview.js <markdown-file-path>
62
- ```
63
-
64
- #### 例
65
-
66
- ```bash
67
- # サンプルファイルをプレビュー
68
- node bin/md-preview.js test-samples/sample.md
69
-
70
- # 任意のMarkdownファイルをプレビュー
71
- node bin/md-preview.js ./docs/README.md
72
- node bin/md-preview.js ~/Documents/notes.md
73
- ```
74
-
75
- ### オプション
76
-
77
- ```bash
78
- # ポート番号を指定
79
- node bin/md-preview.js --port 8080 --api-port 3000 file.md
80
-
81
- # ブラウザを自動的に開かない
82
- node bin/md-preview.js --no-open file.md
83
-
84
- # ヘルプを表示
85
- node bin/md-preview.js --help
86
-
87
- # バージョンを表示
88
- node bin/md-preview.js --version
89
- ```
90
-
91
- ## オプション一覧
14
+ ## Install
92
15
 
93
- | オプション | 短縮形 | デフォルト | 説明 |
94
- |-----------|--------|-----------|------|
95
- | `--port` | `-p` | `6060` | Viteサーバーのポート番号 |
96
- | `--api-port` | - | `3030` | APIサーバーのポート番号 |
97
- | `--no-open` | - | - | ブラウザを自動的に開かない |
98
- | `--help` | `-h` | - | ヘルプを表示 |
99
- | `--version` | `-v` | - | バージョンを表示 |
100
-
101
- ## 起動の流れ
102
-
103
- 1. CLIコマンドを実行すると、以下のサーバーが起動します:
104
- - **APIサーバー(Hono)**: `http://localhost:3030` - Markdownファイルを読み込むAPI
105
- - **Viteサーバー**: `http://localhost:6060` - Reactアプリケーション
106
-
107
- 2. 自動的にブラウザで `http://localhost:6060` が開き、Markdownファイルが表示されます
108
-
109
- 3. 終了するには `Ctrl+C` を押してください
110
-
111
- ## 技術スタック
112
-
113
- ### フロントエンド
114
- - **React** 19 - UIライブラリ
115
- - **TypeScript** - 型安全な開発
116
- - **Vite** - 高速な開発サーバー
117
- - **react-markdown** - Markdownレンダリング
118
- - **remark-gfm** - GFM記法サポート
119
- - **rehype-highlight** - シンタックスハイライト
120
- - **highlight.js** - コードハイライトライブラリ
121
-
122
- ### バックエンド
123
- - **Hono** - 高速で軽量なWebフレームワーク
124
- - **@hono/node-server** - Node.js用アダプター
125
-
126
- ### CLI
127
- - **commander** - コマンドライン引数のパース
128
- - **chalk** - ターミナル出力の色付け
129
- - **open** - ブラウザを開く
130
-
131
- ## プロジェクト構成
132
-
133
- ```
134
- md-preview/
135
- ├── bin/
136
- │ └── md-preview.js # CLI エントリーポイント
137
- ├── server/
138
- │ └── index.js # Hono APIサーバー
139
- ├── src/
140
- │ ├── components/
141
- │ │ ├── ErrorDisplay.tsx # エラー表示
142
- │ │ └── MarkdownPreview.tsx # Markdownプレビュー
143
- │ ├── hooks/
144
- │ │ └── useMarkdown.ts # Markdown取得フック
145
- │ ├── styles/
146
- │ │ └── markdown.css # Markdownスタイル
147
- │ ├── App.tsx
148
- │ ├── main.tsx
149
- │ └── index.css
150
- ├── test-samples/
151
- │ └── sample.md # テスト用サンプル
152
- ├── index.html
153
- ├── vite.config.ts
154
- ├── tsconfig.json
155
- └── package.json
156
- ```
157
-
158
- ## サポートするMarkdown記法
159
-
160
- ### 基本記法
161
- - 見出し (h1-h6)
162
- - 段落
163
- - 強調 (**太字**, *斜体*)
164
- - リスト(順序付き/順序なし)
165
- - インラインコード
166
- - コードブロック(シンタックスハイライト付き)
167
- - リンク
168
- - 引用
169
- - 水平線
170
-
171
- ### GFM拡張記法
172
- - テーブル
173
- - タスクリスト
174
- - 取り消し線 (~~text~~)
175
-
176
- ## 開発
177
-
178
- ### 開発サーバーの起動
179
-
180
- ```bash
181
- # Vite開発サーバーのみ起動
182
- pnpm run dev
183
-
184
- # APIサーバーのみ起動
185
- pnpm run server
186
- ```
187
-
188
- ### ビルド
189
-
190
- ```bash
191
- pnpm run build
16
+ ```sh
17
+ npm install -g md-review
192
18
  ```
193
19
 
194
- ## トラブルシューティング
195
-
196
- ### ポートが既に使用されている
20
+ ## Usage
197
21
 
198
- デフォルトのポート(6060, 3030)が既に使用されている場合は、別のポートを指定してください:
199
-
200
- ```bash
201
- node bin/md-preview.js --port 8080 --api-port 3000 file.md
22
+ ```sh
23
+ md-review README.md
202
24
  ```
203
25
 
204
- ### ブラウザが自動的に開かない
205
-
206
- `--no-open` オプションを付けずに実行してください。または、手動で以下のURLを開いてください:
26
+ ### Options
207
27
 
28
+ ```sh
29
+ -p, --port <port> Vite server port (default: 6060)
30
+ --api-port <port> API server port (default: 3030)
31
+ --no-open Do not open browser automatically
32
+ -h, --help Show help
33
+ -v, --version Show version
208
34
  ```
209
- http://localhost:6060
210
- ```
211
-
212
- ### Markdownが表示されない
213
-
214
- 1. APIサーバーが正常に起動しているか確認してください(`http://localhost:3030/api/health` にアクセス)
215
- 2. ファイルパスが正しいか確認してください
216
- 3. ファイルが読み取り可能か確認してください
217
35
 
218
- ## ライセンス
36
+ ## License
219
37
 
220
- MIT
38
+ [MIT](./LICENSE)
package/bin/md-review.js CHANGED
@@ -126,10 +126,11 @@ apiProcess.stdout.on('data', (data) => {
126
126
 
127
127
  if (!serverReady && output.includes(SERVER_READY_MESSAGE)) {
128
128
  serverReady = true;
129
- console.log('Starting Vite dev server...');
129
+ console.log('Starting Vite preview server...');
130
130
 
131
131
  viteProcess = spawn('node', [
132
132
  'node_modules/vite/bin/vite.js',
133
+ 'preview',
133
134
  '--port', port,
134
135
  ...(shouldOpen ? ['--open'] : [])
135
136
  ], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "md-review",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Review Markdown files in your browser with inline comments",
5
5
  "type": "module",
6
6
  "bin": {
@@ -35,6 +35,7 @@
35
35
  "packageManager": "pnpm@10.23.0",
36
36
  "dependencies": {
37
37
  "@hono/node-server": "^1.19.6",
38
+ "@vitejs/plugin-react": "^4.3.4",
38
39
  "highlight.js": "^11.11.1",
39
40
  "hono": "^4.10.6",
40
41
  "mri": "^1.2.0",
@@ -43,16 +44,15 @@
43
44
  "react-dom": "^19.0.0",
44
45
  "react-markdown": "^10.1.0",
45
46
  "rehype-highlight": "^7.0.2",
46
- "remark-gfm": "^4.0.1"
47
+ "remark-gfm": "^4.0.1",
48
+ "vite": "^6.0.3"
47
49
  },
48
50
  "devDependencies": {
49
51
  "@types/hast": "^3.0.4",
50
52
  "@types/node": "^22.0.0",
51
53
  "@types/react": "^19.0.0",
52
54
  "@types/react-dom": "^19.0.0",
53
- "@vitejs/plugin-react": "^4.3.4",
54
55
  "concurrently": "^9.2.1",
55
- "typescript": "^5.6.3",
56
- "vite": "^6.0.3"
56
+ "typescript": "^5.6.3"
57
57
  }
58
58
  }
package/server/index.js CHANGED
@@ -14,6 +14,31 @@ function validatePort(value) {
14
14
  return port;
15
15
  }
16
16
 
17
+ // Try to start server on port, incrementing if busy
18
+ async function startServer(app, port, maxRetries = 10) {
19
+ for (let i = 0; i < maxRetries; i++) {
20
+ const tryPort = port + i;
21
+ try {
22
+ await new Promise((resolve, reject) => {
23
+ const server = serve({
24
+ fetch: app.fetch,
25
+ port: tryPort
26
+ });
27
+ server.once('listening', () => resolve(server));
28
+ server.once('error', reject);
29
+ });
30
+ return tryPort;
31
+ } catch (err) {
32
+ if (err.code === 'EADDRINUSE') {
33
+ console.log(`Port ${tryPort} is in use, trying ${tryPort + 1}...`);
34
+ continue;
35
+ }
36
+ throw err;
37
+ }
38
+ }
39
+ throw new Error(`Could not find an available port after ${maxRetries} attempts`);
40
+ }
41
+
17
42
  const app = new Hono();
18
43
  const PORT = validatePort(process.env.API_PORT || 3030);
19
44
  const VITE_PORT = process.env.VITE_PORT || 6060;
@@ -58,12 +83,12 @@ async function scanMarkdownFiles(dir, baseDir = dir) {
58
83
  return files;
59
84
  }
60
85
 
61
- // CORS設定
86
+ // CORS configuration
62
87
  app.use('/*', cors({
63
88
  origin: CORS_ORIGIN
64
89
  }));
65
90
 
66
- // ヘルスチェック
91
+ // Health check
67
92
  app.get('/api/health', (c) => {
68
93
  return c.json({ status: 'ok' });
69
94
  });
@@ -81,7 +106,7 @@ app.get('/api/files', async (c) => {
81
106
  }
82
107
  });
83
108
 
84
- // Markdownファイル取得API (CLI mode)
109
+ // Get markdown file API (CLI mode)
85
110
  app.get('/api/markdown', async (c) => {
86
111
  if (!MARKDOWN_FILE_PATH) {
87
112
  return c.json({
@@ -126,10 +151,11 @@ app.get('/api/markdown/:path{.+}', async (c) => {
126
151
  });
127
152
 
128
153
  const SERVER_READY_MESSAGE = 'md-review server started';
129
- console.log(`API Server running on http://localhost:${PORT}`);
130
- console.log(SERVER_READY_MESSAGE);
131
154
 
132
- serve({
133
- fetch: app.fetch,
134
- port: PORT
155
+ startServer(app, PORT).then((actualPort) => {
156
+ console.log(`API Server running on http://localhost:${actualPort}`);
157
+ console.log(SERVER_READY_MESSAGE);
158
+ }).catch((err) => {
159
+ console.error('Failed to start server:', err.message);
160
+ process.exit(1);
135
161
  });