tsbuild 1.0.0__py3-none-any.whl

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.
tsbuild/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "1.0.0"
tsbuild/__main__.py ADDED
@@ -0,0 +1,171 @@
1
+ import sys
2
+ import subprocess
3
+ import urllib.request
4
+ import webbrowser
5
+ import re
6
+ import time
7
+ import signal
8
+ import threading
9
+ from pathlib import Path
10
+
11
+ from . import __version__
12
+
13
+ # --- Console setup (Windows: enable ANSI + force UTF-8) ---
14
+
15
+ def _setup_console():
16
+ if sys.platform == "win32":
17
+ try:
18
+ import ctypes
19
+ ctypes.windll.kernel32.SetConsoleMode(
20
+ ctypes.windll.kernel32.GetStdHandle(-11), 7)
21
+ except Exception:
22
+ pass
23
+ if hasattr(sys.stdout, "reconfigure"):
24
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace")
25
+ sys.stderr.reconfigure(encoding="utf-8", errors="replace")
26
+
27
+ _setup_console()
28
+
29
+ R = "\033[0m"
30
+ CYAN = "\033[36m"
31
+ GREEN = "\033[32m"
32
+ YELLOW = "\033[33m"
33
+ WHITE = "\033[97m"
34
+ GRAY = "\033[90m"
35
+ RED = "\033[31m"
36
+
37
+ def c(text, color): return f"{color}{text}{R}"
38
+
39
+
40
+ # --- Version check ---
41
+
42
+ def fetch_remote_version() -> str | None:
43
+ try:
44
+ url = "https://raw.githubusercontent.com/Lapius7/tsbuild/main/version.txt"
45
+ with urllib.request.urlopen(url, timeout=3) as r:
46
+ return r.read().decode().strip()
47
+ except Exception:
48
+ return None
49
+
50
+
51
+ # --- Info screen ---
52
+
53
+ def show_info(remote: str | None):
54
+ print()
55
+ print(c("⚡ tsbuild", CYAN) + c(f" v{__version__}", GRAY))
56
+ print("Bun + TypeScript 開発サーバーをホットリロード付きで1コマンド起動するツール")
57
+ print()
58
+ print(c("開発者 : ", YELLOW) + "Lapius7")
59
+ print(c("X : ", YELLOW) + "https://x.com/Lapius7")
60
+ print(c("GitHub : ", YELLOW) + "https://github.com/Lapius7/tsbuild")
61
+ print()
62
+ if remote is None:
63
+ print(f"バージョン : {__version__} " + c("(バージョン確認失敗)", GRAY))
64
+ elif remote == __version__:
65
+ print(f"バージョン : {__version__} " + c("✅ 最新です", GREEN))
66
+ else:
67
+ print(f"バージョン : {__version__} " + c(f"⬆ 最新: {remote}", YELLOW))
68
+ print()
69
+ print(c("使い方 : tssetup でプロジェクトを作成してから、そのフォルダ内で tsbuild を実行してください", GRAY))
70
+ print(c("ヘルプ : tsbuild --help", GRAY))
71
+ print()
72
+
73
+
74
+ # --- Dev server ---
75
+
76
+ def run_server():
77
+ if not Path("package.json").exists() or not Path("server.ts").exists():
78
+ remote = fetch_remote_version()
79
+ show_info(remote)
80
+ return
81
+
82
+ print(c("🚀 開発環境を起動中(ホットリロード有効)...", CYAN))
83
+
84
+ server_proc = subprocess.Popen(
85
+ ["bun", "server.ts"],
86
+ stdout=subprocess.PIPE,
87
+ stderr=subprocess.STDOUT,
88
+ text=True,
89
+ encoding="utf-8",
90
+ errors="replace",
91
+ )
92
+
93
+ # Initial compile
94
+ tsc_result = subprocess.run(
95
+ ["bun", "x", "tsc"],
96
+ capture_output=True, text=True, encoding="utf-8", errors="replace"
97
+ )
98
+ if tsc_result.returncode != 0:
99
+ print(c("⚠ TypeScript コンパイルエラー:", YELLOW))
100
+ for line in (tsc_result.stdout + tsc_result.stderr).splitlines():
101
+ print(c(f" {line}", YELLOW))
102
+
103
+ # Wait for server URL
104
+ target_url = "http://localhost:53000"
105
+ deadline = time.time() + 5
106
+
107
+ def _read_url():
108
+ nonlocal target_url
109
+ while time.time() < deadline:
110
+ line = server_proc.stdout.readline()
111
+ if not line:
112
+ break
113
+ m = re.search(r"http://localhost:\d+", line)
114
+ if m:
115
+ target_url = m.group()
116
+ break
117
+
118
+ t = threading.Thread(target=_read_url, daemon=True)
119
+ t.start()
120
+ t.join(timeout=5)
121
+
122
+ webbrowser.open(target_url)
123
+
124
+ print(c("=" * 50, YELLOW))
125
+ print(c(" 🔥 ホットリロード稼働中!コードを変更するとブラウザが自動更新されます。", GREEN))
126
+ print(c(" [Ctrl + C] を押すと、すべてのプロセスを終了します。", YELLOW))
127
+ print(c("=" * 50, YELLOW))
128
+
129
+ def cleanup(signum=None, frame=None):
130
+ print(c("\n🛑 開発環境を停止しています...", RED))
131
+ server_proc.terminate()
132
+ try:
133
+ server_proc.wait(timeout=3)
134
+ except subprocess.TimeoutExpired:
135
+ server_proc.kill()
136
+ print(c("✨ すべてのプロセスが正常に終了しました。", GREEN))
137
+ sys.exit(0)
138
+
139
+ signal.signal(signal.SIGINT, cleanup)
140
+
141
+ try:
142
+ subprocess.run(["bun", "x", "tsc", "--watch"])
143
+ finally:
144
+ cleanup()
145
+
146
+
147
+ # --- Entry point ---
148
+
149
+ def main():
150
+ import argparse
151
+ parser = argparse.ArgumentParser(
152
+ prog="tsbuild",
153
+ description="Bun + TypeScript 開発サーバーをホットリロード付きで起動するツール",
154
+ )
155
+ parser.add_argument("--version", "-v", action="store_true", help="バージョンを表示")
156
+ args = parser.parse_args()
157
+
158
+ if args.version:
159
+ print(f"tsbuild v{__version__}")
160
+ return
161
+
162
+ remote = fetch_remote_version()
163
+ if remote and remote != __version__:
164
+ print()
165
+ print(c(f"🔄 新しいバージョン ({remote}) があります。pip install --upgrade tsbuild で更新できます。", YELLOW))
166
+
167
+ run_server()
168
+
169
+
170
+ if __name__ == "__main__":
171
+ main()
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: tsbuild
3
+ Version: 1.0.0
4
+ Summary: Bun + TypeScript 開発サーバーをホットリロード付きで1コマンド起動するツール
5
+ Project-URL: Homepage, https://github.com/Lapius7/tsbuild
6
+ Project-URL: Issues, https://github.com/Lapius7/tsbuild/issues
7
+ Author-email: Lapius7 <me@lapius7.com>
8
+ License: MIT
9
+ Keywords: bun,cli,dev-server,hot-reload,typescript
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Software Development
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+
19
+ # tsbuild
20
+
21
+ `tssetup` で構築した Bun + TypeScript プロジェクトにおいて、開発サーバーの起動・TypeScript の自動ビルド・ブラウザのホットリロードを1コマンドで一元管理する開発支援ツールです。
22
+
23
+ ## 🚀 特徴
24
+
25
+ - **1コマンド起動:** ローカルWebサーバー起動・ブラウザ自動起動・TS監視ビルドをすべて開始します。
26
+ - **ポート衝突の自動回避:** デフォルトの 53000 番ポートが使用中の場合、空いているポートを自動で探します。
27
+ - **404エラー防止:** 起動と同時に初回コンパイルを実行し、ブラウザ起動直後の404エラーを防ぎます。
28
+ - **ホットリロード:** `src/` 内のコード変更や `index.html` の編集を検知し、ブラウザを自動でリロードします。
29
+ - **ゾンビプロセス防止:** `Ctrl + C` で終了した際に、バックグラウンドの Bun サーバーを自動停止・クリーンアップします。
30
+ - **自動バージョン確認:** 実行時に最新バージョンを確認し、更新がある場合は通知します。
31
+
32
+ ---
33
+
34
+ ## 🛠️ インストール方法
35
+
36
+ ```bash
37
+ pip install tsbuild
38
+ ```
39
+
40
+ > [!NOTE]
41
+ >
42
+ > - PowerShell・CMD・Windows Terminal どれからでも使えます。
43
+ > - 動作には **Python 3.9+** と **Bun** が必要です。
44
+
45
+ ---
46
+
47
+ ## ⚙️ 動作に必要な環境(依存関係)
48
+
49
+ | ツール | 用途 | インストール |
50
+ | :--- | :--- | :--- |
51
+ | **Python 3.9+** | tsbuild 本体の実行 | [python.org](https://www.python.org/) |
52
+ | **Bun** | 開発サーバー起動・TSコンパイル | `powershell -c "irm bun.sh/install.ps1 \| iex"` |
53
+
54
+ ---
55
+
56
+ ## ⚡ 使い方
57
+
58
+ `tssetup` で構築したプロジェクトのルートディレクトリ(`package.json` と `server.ts` があるフォルダ)で実行します。
59
+
60
+ ```bash
61
+ tsbuild
62
+ ```
63
+
64
+ プロジェクト外(`package.json` / `server.ts` がないディレクトリ)で実行するとバージョン情報・インフォ画面が表示されます。
65
+
66
+ ### パラメータ
67
+
68
+ | パラメータ | 短縮形 | 説明 |
69
+ | :--- | :--- | :--- |
70
+ | `--version` | `-v` | バージョンを表示 |
71
+ | `--help` | `-h` | ヘルプを表示 |
72
+
73
+ ---
74
+
75
+ ## 📁 対象プロジェクトの構成
76
+
77
+ `tsbuild` は `tssetup` で作成した以下の構成を前提としています。
78
+
79
+ ```
80
+ my-app/
81
+ ├── src/
82
+ │ └── index.ts ← 編集対象の TypeScript ファイル
83
+ ├── dist/ ← tsc が自動生成する JS 出力先
84
+ ├── index.html ← フロントエンドの HTML
85
+ ├── server.ts ← tsbuild が起動する Bun サーバー
86
+ ├── tsconfig.json ← TypeScript コンパイラ設定
87
+ └── package.json ← Bun プロジェクト設定
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 🚀 プロジェクトの始め方
93
+
94
+ ```bash
95
+ # 1. プロジェクトを作成(カレントディレクトリが自動で移動)
96
+ tssetup my-app
97
+
98
+ # 2. 開発サーバーを起動
99
+ tsbuild
100
+ ```
101
+
102
+ ---
103
+
104
+ ## コマンド実行時の挙動
105
+
106
+ 1. **ポート自動探索** — `53000` 番から順に空きポートを検索してサーバーを起動
107
+ 2. **初回ビルド** — `bun x tsc` で初回コンパイルを実行(ブラウザ起動前に JS を生成)
108
+ 3. **ブラウザ自動起動** — `http://localhost:53000`(または自動検出したポート)を開く
109
+ 4. **リアルタイム監視** — `bun x tsc --watch` でファイル変更を検知して自動コンパイル
110
+ 5. **ホットリロード** — ビルド完了後、WebSocket 経由でブラウザに通知してリロード
111
+
112
+ ### 終了方法
113
+
114
+ **`Ctrl + C`** を押すと、バックグラウンドの Bun サーバーを自動停止してクリーンアップします。
115
+
116
+ ---
117
+
118
+ ## 🔄 アップデート
119
+
120
+ ```bash
121
+ pip install --upgrade tsbuild
122
+ ```
123
+
124
+ ---
125
+
126
+ ## ✉️ 問い合わせ先
127
+
128
+ - **X (旧Twitter):** [@Lapius7](https://x.com/Lapius7)
129
+ - **GitHub Issues:** [Lapius7/tsbuild/issues](https://github.com/Lapius7/tsbuild/issues)
130
+
131
+ ---
132
+
133
+ ## ⚠️ 免責事項
134
+
135
+ 本ソフトウェアの使用によって生じた直接的・間接的な損害について、作者は一切の責任を負いません。自己責任のもとでご使用ください。
136
+
137
+ ---
138
+
139
+ ## 📄 ライセンス & コピーライト
140
+
141
+ 本プロジェクトは [MIT License](https://opensource.org/licenses/MIT) のもとで公開されています。
142
+
143
+ Copyright (c) 2026 Lapius7
@@ -0,0 +1,6 @@
1
+ tsbuild/__init__.py,sha256=J-j-u0itpEFT6irdmWmixQqYMadNl1X91TxUmoiLHMI,22
2
+ tsbuild/__main__.py,sha256=Mdx1Skxt-eMo0ePSKTauzOj2K_5YCyTi_DVTlRzbgYY,5171
3
+ tsbuild-1.0.0.dist-info/METADATA,sha256=-9rvwYLePNyGFQ_mDT7P8e8rACzknDqCOCk7FFXe1Wc,5163
4
+ tsbuild-1.0.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
5
+ tsbuild-1.0.0.dist-info/entry_points.txt,sha256=6EUeqQPlLXM13rxwTDgS0L_OOuKrzafFzLrxX8bTVzo,50
6
+ tsbuild-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ tsbuild = tsbuild.__main__:main