vimd 0.1.12 → 0.2.1
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/README.md +111 -193
- package/dist/cli/commands/build.d.ts +1 -0
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +19 -10
- package/dist/cli/commands/dev.d.ts +1 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +27 -14
- package/dist/cli/commands/kill.d.ts +7 -0
- package/dist/cli/commands/kill.d.ts.map +1 -0
- package/dist/cli/commands/kill.js +110 -0
- package/dist/cli/index.js +11 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +3 -1
- package/dist/config/types.d.ts +7 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/core/converter.d.ts +18 -0
- package/dist/core/converter.d.ts.map +1 -1
- package/dist/core/converter.js +30 -1
- package/dist/core/pandoc-detector.d.ts.map +1 -1
- package/dist/core/pandoc-detector.js +7 -2
- package/dist/core/parser/index.d.ts +5 -0
- package/dist/core/parser/index.d.ts.map +1 -0
- package/dist/core/parser/index.js +4 -0
- package/dist/core/parser/markdown-it-parser.d.ts +23 -0
- package/dist/core/parser/markdown-it-parser.d.ts.map +1 -0
- package/dist/core/parser/markdown-it-parser.js +49 -0
- package/dist/core/parser/pandoc-parser.d.ts +27 -0
- package/dist/core/parser/pandoc-parser.d.ts.map +1 -0
- package/dist/core/parser/pandoc-parser.js +83 -0
- package/dist/core/parser/parser-factory.d.ts +36 -0
- package/dist/core/parser/parser-factory.d.ts.map +1 -0
- package/dist/core/parser/parser-factory.js +63 -0
- package/dist/core/parser/types.d.ts +26 -0
- package/dist/core/parser/types.d.ts.map +1 -0
- package/dist/core/parser/types.js +2 -0
- package/dist/core/server.d.ts +8 -1
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +32 -3
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -2,128 +2,128 @@
|
|
|
2
2
|
|
|
3
3
|
🌐 [English](README-en.md) | 日本語
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> 書きながら見る。Markdownプレビュー
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/vimd)
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://nodejs.org/)
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
---
|
|
11
12
|
|
|
12
|
-
##
|
|
13
|
+
## デモ
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
- **複数テーマ**: 5つの組み込みテーマ (GitHub, Minimal, Dark, Academic, Technical)
|
|
16
|
-
- **pandoc連携**: pandocによる高品質なMarkdown変換
|
|
17
|
-
- **グローバル設定**: プロジェクトディレクトリを汚さない `~/.vimd/config.js`
|
|
18
|
-
- **対話的設定**: `vimd theme` や `vimd config` で簡単に設定変更
|
|
19
|
-
- **クロスプラットフォーム**: macOS, Linux, Windows で動作
|
|
15
|
+

|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
---
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
npm install -g vimd
|
|
25
|
-
```
|
|
19
|
+
## テーマ
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
<details open>
|
|
22
|
+
<summary><strong>GitHub</strong> (デフォルト)</summary>
|
|
28
23
|
|
|
29
|
-
|
|
24
|
+

|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
- **pandoc** >= 2.0 (別途インストールが必要)
|
|
26
|
+
</details>
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
<details>
|
|
29
|
+
<summary><strong>Dark</strong></summary>
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
# macOS
|
|
38
|
-
brew install pandoc
|
|
31
|
+

|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
sudo apt install pandoc
|
|
33
|
+
</details>
|
|
42
34
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
```
|
|
35
|
+
<details>
|
|
36
|
+
<summary><strong>Academic</strong></summary>
|
|
46
37
|
|
|
47
|
-
|
|
38
|
+

|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
# ライブプレビューを開始
|
|
51
|
-
vimd dev draft.md
|
|
40
|
+
</details>
|
|
52
41
|
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
<details>
|
|
43
|
+
<summary><strong>Minimal</strong></summary>
|
|
55
44
|
|
|
56
|
-
|
|
57
|
-
vimd theme
|
|
45
|
+

|
|
58
46
|
|
|
59
|
-
|
|
60
|
-
vimd config
|
|
61
|
-
```
|
|
47
|
+
</details>
|
|
62
48
|
|
|
63
|
-
|
|
49
|
+
<details>
|
|
50
|
+
<summary><strong>Technical</strong></summary>
|
|
64
51
|
|
|
65
|
-
|
|
52
|
+

|
|
66
53
|
|
|
67
|
-
|
|
54
|
+
</details>
|
|
68
55
|
|
|
69
|
-
|
|
70
|
-
vimd dev draft.md
|
|
71
|
-
vimd dev docs/guide.md --port 3000
|
|
72
|
-
vimd dev article.md --theme dark --no-open
|
|
73
|
-
```
|
|
56
|
+
---
|
|
74
57
|
|
|
75
|
-
|
|
58
|
+
## クイックスタート
|
|
76
59
|
|
|
77
|
-
|
|
78
|
-
- `-t, --theme <theme>`: テーマ名 (グローバル設定を上書き)
|
|
79
|
-
- `--no-open`: ブラウザを自動で開かない
|
|
60
|
+
### 必要要件
|
|
80
61
|
|
|
81
|
-
|
|
62
|
+
- **Node.js** >= 18.0.0
|
|
63
|
+
- **pandoc** >= 2.0(オプション、高品質ビルド時のみ)
|
|
82
64
|
|
|
83
|
-
|
|
65
|
+
### インストール
|
|
84
66
|
|
|
85
67
|
```bash
|
|
86
|
-
|
|
87
|
-
vimd build docs/guide.md -o dist/guide.html
|
|
88
|
-
vimd build article.md --theme academic
|
|
68
|
+
npm install -g vimd
|
|
89
69
|
```
|
|
90
70
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- `-o, --output <path>`: 出力ファイルパス (デフォルト: 同名で拡張子.html)
|
|
94
|
-
- `-t, --theme <theme>`: テーマ名 (グローバル設定を上書き)
|
|
71
|
+
v0.2.0 からは **pandoc なしで利用可能** になりました。
|
|
72
|
+
高品質な出力が必要な場合のみ pandoc をインストールしてください。
|
|
95
73
|
|
|
96
|
-
|
|
74
|
+
```bash
|
|
75
|
+
# pandocのインストール(オプション)
|
|
76
|
+
brew install pandoc # macOS
|
|
77
|
+
sudo apt install pandoc # Ubuntu/Debian
|
|
78
|
+
choco install pandoc # Windows
|
|
79
|
+
```
|
|
97
80
|
|
|
98
|
-
|
|
81
|
+
### 使い方
|
|
99
82
|
|
|
100
83
|
```bash
|
|
101
|
-
|
|
102
|
-
|
|
84
|
+
# ライブプレビューを開始(pandoc不要、高速)
|
|
85
|
+
vimd dev draft.md
|
|
103
86
|
|
|
104
|
-
|
|
87
|
+
# 静的HTMLを生成(pandoc使用、高品質)
|
|
88
|
+
vimd build draft.md
|
|
105
89
|
|
|
106
|
-
|
|
90
|
+
# 高速ビルド(pandoc不要)
|
|
91
|
+
vimd build draft.md --fast
|
|
107
92
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
vimd config
|
|
93
|
+
# テーマを変更
|
|
94
|
+
vimd theme
|
|
111
95
|
|
|
112
|
-
#
|
|
113
|
-
vimd config
|
|
96
|
+
# 設定を編集
|
|
97
|
+
vimd config
|
|
114
98
|
```
|
|
115
99
|
|
|
116
|
-
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## コマンド
|
|
117
103
|
|
|
118
|
-
|
|
104
|
+
| コマンド | 説明 |
|
|
105
|
+
|---------|------|
|
|
106
|
+
| `vimd dev <file>` | ライブプレビューサーバーを起動 |
|
|
107
|
+
| `vimd build <file>` | 静的HTMLを生成 |
|
|
108
|
+
| `vimd theme` | テーマを対話的に変更 |
|
|
109
|
+
| `vimd config` | 設定を対話的に編集 |
|
|
119
110
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
111
|
+
### オプション
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# dev コマンド
|
|
115
|
+
vimd dev draft.md --port 3000 # ポート指定
|
|
116
|
+
vimd dev draft.md --theme dark # テーマ指定
|
|
117
|
+
vimd dev draft.md --no-open # ブラウザを開かない
|
|
118
|
+
vimd dev draft.md --pandoc # pandocパーサーを使用
|
|
119
|
+
|
|
120
|
+
# build コマンド
|
|
121
|
+
vimd build draft.md -o output.html # 出力先指定
|
|
122
|
+
vimd build draft.md --fast # markdown-itで高速ビルド
|
|
123
|
+
vimd build draft.md --theme dark # テーマ指定
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
127
|
|
|
128
128
|
## 設定
|
|
129
129
|
|
|
@@ -133,138 +133,56 @@ vimdには5つの組み込みテーマがあります:
|
|
|
133
133
|
export default {
|
|
134
134
|
theme: 'github',
|
|
135
135
|
port: 8080,
|
|
136
|
-
host: 'localhost',
|
|
137
136
|
open: true,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
toc: false,
|
|
141
|
-
highlightStyle: 'github',
|
|
142
|
-
},
|
|
143
|
-
watch: {
|
|
144
|
-
ignored: ['node_modules', '.git'],
|
|
145
|
-
},
|
|
137
|
+
devParser: 'markdown-it', // dev用パーサー(デフォルト: markdown-it)
|
|
138
|
+
buildParser: 'pandoc', // build用パーサー(デフォルト: pandoc)
|
|
146
139
|
};
|
|
147
140
|
```
|
|
148
141
|
|
|
149
|
-
###
|
|
150
|
-
|
|
151
|
-
- `theme`: デフォルトテーマ名 (文字列)
|
|
152
|
-
- `port`: 開発サーバーのポート (数値、デフォルト: 8080)
|
|
153
|
-
- `host`: 開発サーバーのホスト (文字列、デフォルト: 'localhost')
|
|
154
|
-
- `open`: ブラウザを自動で開く (真偽値、デフォルト: true)
|
|
155
|
-
- `pandoc.standalone`: スタンドアロンHTMLを生成 (真偽値)
|
|
156
|
-
- `pandoc.toc`: 目次を生成 (真偽値)
|
|
157
|
-
- `pandoc.highlightStyle`: コードハイライトスタイル (文字列)
|
|
158
|
-
- `watch.ignored`: ファイル監視で無視するパターン (配列)
|
|
159
|
-
|
|
160
|
-
## API使用
|
|
161
|
-
|
|
162
|
-
vimdはNode.jsライブラリとしても使用できます:
|
|
163
|
-
|
|
164
|
-
```javascript
|
|
165
|
-
import { MarkdownConverter, ConfigLoader, ThemeManager } from 'vimd';
|
|
166
|
-
|
|
167
|
-
// 設定を読み込む
|
|
168
|
-
const config = await ConfigLoader.loadGlobal();
|
|
169
|
-
|
|
170
|
-
// コンバーターを作成
|
|
171
|
-
const converter = new MarkdownConverter({
|
|
172
|
-
theme: 'github',
|
|
173
|
-
pandocOptions: config.pandoc,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// MarkdownをHTMLに変換
|
|
177
|
-
const html = await converter.convertWithTemplate('draft.md');
|
|
178
|
-
|
|
179
|
-
// 利用可能なテーマを一覧表示
|
|
180
|
-
const themes = ThemeManager.list();
|
|
181
|
-
console.log(themes); // [{ name: 'github', displayName: 'GitHub' }, ...]
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
## 開発
|
|
185
|
-
|
|
186
|
-
```bash
|
|
187
|
-
# リポジトリをクローン
|
|
188
|
-
git clone https://github.com/notokeishou/vimd.git
|
|
189
|
-
cd vimd
|
|
190
|
-
|
|
191
|
-
# 依存関係をインストール
|
|
192
|
-
npm install
|
|
193
|
-
|
|
194
|
-
# ビルド
|
|
195
|
-
npm run build
|
|
196
|
-
|
|
197
|
-
# テストを実行
|
|
198
|
-
npm test
|
|
199
|
-
|
|
200
|
-
# カバレッジ付きでテスト
|
|
201
|
-
npm run test:coverage
|
|
202
|
-
|
|
203
|
-
# 開発モード
|
|
204
|
-
npm run dev -- dev test.md
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
### プロジェクト構造
|
|
142
|
+
### パーサー設定
|
|
208
143
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
│ ├── config/ # 設定管理
|
|
214
|
-
│ ├── core/ # コア機能 (converter, watcher, server)
|
|
215
|
-
│ ├── themes/ # テーマシステム
|
|
216
|
-
│ └── utils/ # ユーティリティ関数
|
|
217
|
-
├── tests/
|
|
218
|
-
│ ├── unit/ # ユニットテスト
|
|
219
|
-
│ └── integration/ # 統合テスト
|
|
220
|
-
├── templates/ # HTMLテンプレート
|
|
221
|
-
└── dist/ # ビルド済みファイル
|
|
222
|
-
```
|
|
144
|
+
| パーサー | 特徴 | 用途 |
|
|
145
|
+
|----------|------|------|
|
|
146
|
+
| `markdown-it` | 高速、pandoc不要 | 開発時のプレビュー |
|
|
147
|
+
| `pandoc` | 高品質、多機能 | 最終出力の生成 |
|
|
223
148
|
|
|
224
|
-
|
|
149
|
+
詳細な設定オプションは [docs/ja/api.md](docs/ja/api.md) を参照してください。
|
|
225
150
|
|
|
226
|
-
|
|
151
|
+
---
|
|
227
152
|
|
|
228
|
-
|
|
153
|
+
## Why vimd?
|
|
229
154
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
155
|
+
| 特徴 | vimd | 他のツール |
|
|
156
|
+
|------|------|-----------|
|
|
157
|
+
| セットアップ | `npm i -g vimd` | 複雑な設定が必要な場合も |
|
|
158
|
+
| 外部依存 | なし(pandocはオプション) | pandoc必須が多い |
|
|
159
|
+
| 変換品質 | markdown-it / pandoc 選択可 | 固定 |
|
|
160
|
+
| テーマ | 5種類組み込み | 別途設定が必要 |
|
|
161
|
+
| 設定ファイル | プロジェクト外 (`~/.vimd/`) | プロジェクト内が多い |
|
|
162
|
+
| ライブリロード | 自動 | 手動リロードが必要な場合も |
|
|
233
163
|
|
|
234
|
-
|
|
164
|
+
---
|
|
235
165
|
|
|
236
|
-
|
|
166
|
+
## ドキュメント
|
|
237
167
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
168
|
+
- [開発ガイド](docs/ja/development.md) - 開発環境構築
|
|
169
|
+
- [アーキテクチャ](docs/ja/architecture.md) - プロジェクト構造
|
|
170
|
+
- [APIリファレンス](docs/ja/api.md) - 詳細なオプション
|
|
171
|
+
- [テスト](docs/ja/testing.md) - テスト構成
|
|
172
|
+
- [トラブルシューティング](docs/ja/troubleshooting.md) - よくある問題
|
|
173
|
+
- [v0.2.0 リリースノート](docs/ja/releases/v0.2.0.md) - Dual Parser System
|
|
241
174
|
|
|
242
|
-
|
|
175
|
+
---
|
|
243
176
|
|
|
244
|
-
|
|
177
|
+
## リンク
|
|
245
178
|
|
|
246
|
-
|
|
179
|
+
- [CONTRIBUTING.md](CONTRIBUTING.md) - コントリビューションガイド
|
|
180
|
+
- [CHANGELOG.md](CHANGELOG.md) - 変更履歴
|
|
181
|
+
- [GitHub](https://github.com/notokeishou/vimd)
|
|
182
|
+
- [npm](https://www.npmjs.com/package/vimd)
|
|
247
183
|
|
|
248
|
-
|
|
249
|
-
2. 設定を確認: `vimd config --list`
|
|
250
|
-
3. ソースからの場合は再ビルド: `npm run build`
|
|
184
|
+
---
|
|
251
185
|
|
|
252
186
|
## ライセンス
|
|
253
187
|
|
|
254
188
|
MIT © notokeishou
|
|
255
|
-
|
|
256
|
-
## コントリビューション
|
|
257
|
-
|
|
258
|
-
コントリビューションを歓迎します! プルリクエストの提出方法については [CONTRIBUTING.md](CONTRIBUTING.md) をお読みください。
|
|
259
|
-
|
|
260
|
-
## 変更履歴
|
|
261
|
-
|
|
262
|
-
リリース履歴は [CHANGELOG.md](CHANGELOG.md) を参照してください。
|
|
263
|
-
|
|
264
|
-
## リンク
|
|
265
|
-
|
|
266
|
-
- [GitHubリポジトリ](https://github.com/notokeishou/vimd)
|
|
267
|
-
- [npmパッケージ](https://www.npmjs.com/package/vimd)
|
|
268
|
-
- [Issue Tracker](https://github.com/notokeishou/vimd/issues)
|
|
269
|
-
|
|
270
|
-
---
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build.ts"],"names":[],"mappings":"AASA,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CAmEf"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ConfigLoader } from '../../config/loader.js';
|
|
3
3
|
import { MarkdownConverter } from '../../core/converter.js';
|
|
4
4
|
import { PandocDetector } from '../../core/pandoc-detector.js';
|
|
5
|
+
import { ParserFactory } from '../../core/parser/index.js';
|
|
5
6
|
import { Logger } from '../../utils/logger.js';
|
|
6
7
|
import * as path from 'path';
|
|
7
8
|
import fs from 'fs-extra';
|
|
@@ -15,30 +16,38 @@ export async function buildCommand(filePath, options) {
|
|
|
15
16
|
config.theme = options.theme;
|
|
16
17
|
}
|
|
17
18
|
Logger.info(`Theme: ${config.theme}`);
|
|
18
|
-
// 2.
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// 2. Determine parser type
|
|
20
|
+
const parserType = options.fast ? 'markdown-it' : config.buildParser;
|
|
21
|
+
Logger.info(`Parser: ${parserType}`);
|
|
22
|
+
// 3. Check pandoc installation only if pandoc parser is selected
|
|
23
|
+
if (parserType === 'pandoc') {
|
|
24
|
+
PandocDetector.ensureInstalled();
|
|
25
|
+
}
|
|
26
|
+
// 4. Check file exists
|
|
21
27
|
const absolutePath = path.resolve(filePath);
|
|
22
28
|
if (!(await fs.pathExists(absolutePath))) {
|
|
23
29
|
Logger.error(`File not found: ${filePath}`);
|
|
24
30
|
process.exit(1);
|
|
25
31
|
}
|
|
26
|
-
//
|
|
32
|
+
// 5. Determine output path
|
|
27
33
|
const outputPath = options.output
|
|
28
34
|
? path.resolve(options.output)
|
|
29
35
|
: path.join(path.dirname(absolutePath), path.basename(filePath, path.extname(filePath)) + '.html');
|
|
30
36
|
Logger.info(`Output: ${outputPath}`);
|
|
31
|
-
//
|
|
37
|
+
// 6. Prepare converter with selected parser
|
|
38
|
+
const pandocOptions = {
|
|
39
|
+
...config.pandoc,
|
|
40
|
+
standalone: true, // build always uses standalone
|
|
41
|
+
};
|
|
42
|
+
const parser = ParserFactory.create(parserType, pandocOptions);
|
|
32
43
|
const converter = new MarkdownConverter({
|
|
33
44
|
theme: config.theme,
|
|
34
|
-
pandocOptions:
|
|
35
|
-
...config.pandoc,
|
|
36
|
-
standalone: true, // build always uses standalone
|
|
37
|
-
},
|
|
45
|
+
pandocOptions: pandocOptions,
|
|
38
46
|
customCSS: config.css,
|
|
39
47
|
template: config.template || undefined,
|
|
40
48
|
});
|
|
41
|
-
|
|
49
|
+
converter.setParser(parser);
|
|
50
|
+
// 7. Execute conversion
|
|
42
51
|
Logger.info('Converting...');
|
|
43
52
|
const html = await converter.convertWithTemplate(absolutePath);
|
|
44
53
|
await converter.writeHTML(html, outputPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"AAaA,UAAU,UAAU;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CA6Jf"}
|
package/dist/cli/commands/dev.js
CHANGED
|
@@ -4,6 +4,7 @@ import { FileWatcher } from '../../core/watcher.js';
|
|
|
4
4
|
import { MarkdownConverter } from '../../core/converter.js';
|
|
5
5
|
import { LiveServer } from '../../core/server.js';
|
|
6
6
|
import { PandocDetector } from '../../core/pandoc-detector.js';
|
|
7
|
+
import { ParserFactory } from '../../core/parser/index.js';
|
|
7
8
|
import { Logger } from '../../utils/logger.js';
|
|
8
9
|
import { ProcessManager } from '../../utils/process-manager.js';
|
|
9
10
|
import { SessionManager } from '../../utils/session-manager.js';
|
|
@@ -47,50 +48,62 @@ export async function devCommand(filePath, options) {
|
|
|
47
48
|
}
|
|
48
49
|
Logger.info(`Theme: ${config.theme}`);
|
|
49
50
|
Logger.info(`Port: ${port}`);
|
|
50
|
-
// 5.
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// 5. Determine parser type
|
|
52
|
+
const parserType = options.pandoc ? 'pandoc' : config.devParser;
|
|
53
|
+
Logger.info(`Parser: ${parserType}`);
|
|
54
|
+
// 6. Check pandoc installation only if pandoc parser is selected
|
|
55
|
+
if (parserType === 'pandoc') {
|
|
56
|
+
PandocDetector.ensureInstalled();
|
|
57
|
+
}
|
|
58
|
+
// 7. Check file exists
|
|
53
59
|
const absolutePath = path.resolve(filePath);
|
|
54
60
|
if (!(await fs.pathExists(absolutePath))) {
|
|
55
61
|
Logger.error(`File not found: ${filePath}`);
|
|
56
62
|
process.exit(1);
|
|
57
63
|
}
|
|
58
|
-
//
|
|
64
|
+
// 8. Prepare output HTML in source directory
|
|
59
65
|
const sourceDir = path.dirname(absolutePath);
|
|
60
66
|
const basename = path.basename(filePath, path.extname(filePath));
|
|
61
67
|
const htmlFileName = `vimd-preview-${basename}.html`;
|
|
62
68
|
const htmlPath = path.join(sourceDir, htmlFileName);
|
|
63
|
-
//
|
|
69
|
+
// 9. Prepare converter with selected parser
|
|
70
|
+
const parser = ParserFactory.create(parserType, config.pandoc);
|
|
64
71
|
const converter = new MarkdownConverter({
|
|
65
72
|
theme: config.theme,
|
|
66
73
|
pandocOptions: config.pandoc,
|
|
67
74
|
customCSS: config.css,
|
|
68
75
|
template: config.template,
|
|
69
76
|
});
|
|
70
|
-
|
|
77
|
+
converter.setParser(parser);
|
|
78
|
+
// 10. Initial conversion
|
|
71
79
|
Logger.info('Converting markdown...');
|
|
72
80
|
const html = await converter.convertWithTemplate(absolutePath);
|
|
73
81
|
await converter.writeHTML(html, htmlPath);
|
|
74
82
|
Logger.success('Conversion complete');
|
|
75
|
-
//
|
|
83
|
+
// 11. Start live server from source directory
|
|
76
84
|
const server = new LiveServer({
|
|
77
85
|
port: port,
|
|
78
86
|
host: config.host,
|
|
79
87
|
open: config.open,
|
|
80
88
|
root: sourceDir,
|
|
81
89
|
});
|
|
82
|
-
await server.start(htmlPath);
|
|
83
|
-
//
|
|
90
|
+
const startResult = await server.start(htmlPath);
|
|
91
|
+
// Update port if live-server used a different one
|
|
92
|
+
const actualPort = startResult.actualPort;
|
|
93
|
+
if (startResult.portChanged) {
|
|
94
|
+
port = actualPort;
|
|
95
|
+
}
|
|
96
|
+
// 12. Save session with actual port
|
|
84
97
|
await SessionManager.saveSession({
|
|
85
98
|
pid: process.pid,
|
|
86
|
-
port:
|
|
99
|
+
port: actualPort,
|
|
87
100
|
htmlPath: htmlPath,
|
|
88
101
|
sourcePath: absolutePath,
|
|
89
102
|
startedAt: new Date().toISOString(),
|
|
90
103
|
});
|
|
91
104
|
Logger.info(`Watching: ${filePath}`);
|
|
92
105
|
Logger.info('Press Ctrl+C to stop');
|
|
93
|
-
//
|
|
106
|
+
// 13. Start file watching
|
|
94
107
|
const watcher = new FileWatcher(absolutePath, config.watch);
|
|
95
108
|
watcher.onChange(async (changedPath) => {
|
|
96
109
|
Logger.info('File changed, reconverting...');
|
|
@@ -107,7 +120,7 @@ export async function devCommand(filePath, options) {
|
|
|
107
120
|
}
|
|
108
121
|
});
|
|
109
122
|
watcher.start();
|
|
110
|
-
//
|
|
123
|
+
// 14. Register cleanup - remove generated HTML file and session
|
|
111
124
|
ProcessManager.onExit(async () => {
|
|
112
125
|
Logger.info('Shutting down...');
|
|
113
126
|
await watcher.stop();
|
|
@@ -120,8 +133,8 @@ export async function devCommand(filePath, options) {
|
|
|
120
133
|
catch {
|
|
121
134
|
// Ignore errors when removing file
|
|
122
135
|
}
|
|
123
|
-
// Remove session from registry
|
|
124
|
-
await SessionManager.removeSession(
|
|
136
|
+
// Remove session from registry (use actual port)
|
|
137
|
+
await SessionManager.removeSession(actualPort);
|
|
125
138
|
Logger.info('Cleanup complete');
|
|
126
139
|
});
|
|
127
140
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kill.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/kill.ts"],"names":[],"mappings":"AAQA,UAAU,WAAW;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAsDD,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAyErE"}
|