hmdev-cli 1.0.3 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hmdev-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "HarmonyOS 开发 CLI 工具 — 文档查询、项目构建、设备部署",
5
5
  "keywords": [
6
6
  "harmonyos",
package/python/builder.py CHANGED
@@ -193,6 +193,10 @@ class HDCTool:
193
193
  )
194
194
  return subprocess.run([self._hdc_path] + args, capture_output=True, text=True, timeout=timeout)
195
195
 
196
+ @staticmethod
197
+ def succeeded(result: subprocess.CompletedProcess) -> bool:
198
+ return result.returncode == 0 and "[Fail]" not in result.stdout and "[Fail]" not in result.stderr
199
+
196
200
  def list_devices(self) -> list[dict]:
197
201
  result = self._run(["list", "targets"])
198
202
  devices = []
@@ -221,5 +225,5 @@ class HDCTool:
221
225
  args.extend(["shell", "aa", "start", "-a", ability, "-b", bundle])
222
226
  return self._run(args, timeout=30)
223
227
 
224
- def connect_wireless(self, ip_port: str, timeout: int = 10) -> subprocess.CompletedProcess:
228
+ def connect_wireless(self, ip_port: str, timeout: int = 30) -> subprocess.CompletedProcess:
225
229
  return self._run(["tconn", ip_port], timeout=timeout)
package/python/cli.py CHANGED
@@ -16,6 +16,8 @@ Usage:
16
16
  import asyncio
17
17
  import json
18
18
  import re
19
+ import shutil
20
+ import subprocess
19
21
  import subprocess
20
22
  import time
21
23
  from argparse import ArgumentParser, RawDescriptionHelpFormatter, SUPPRESS
@@ -477,7 +479,7 @@ async def cmd_deploy(args):
477
479
  if args.tconn:
478
480
  print(f"[hmdev] 无线连接: {args.tconn}")
479
481
  tr = hdc.connect_wireless(args.tconn)
480
- if tr.returncode != 0:
482
+ if not HDCTool.succeeded(tr):
481
483
  print(f"[hmdev] ❌ 无线连接失败: {tr.stderr.strip()}")
482
484
  return
483
485
  print(f"[hmdev] ✅ 无线连接成功")
@@ -493,7 +495,7 @@ async def cmd_deploy(args):
493
495
 
494
496
  print(f"[hmdev] 正在安装: {hap_path}")
495
497
  ir = hdc.install_hap(hap_path, device_id)
496
- if ir.returncode != 0:
498
+ if not HDCTool.succeeded(ir):
497
499
  err = ir.stderr.strip() or ir.stdout.strip()
498
500
  print(f"[hmdev] ❌ 安装失败: {err}")
499
501
  return
@@ -507,7 +509,7 @@ async def cmd_deploy(args):
507
509
  else:
508
510
  print(f"[hmdev] 正在启动: {bundle}")
509
511
  sr = hdc.start_app(bundle, args.ability, device_id)
510
- if sr.returncode != 0:
512
+ if not HDCTool.succeeded(sr):
511
513
  print(f"[hmdev] ❌ 启动失败: {sr.stderr.strip()}")
512
514
  else:
513
515
  print(f"[hmdev] ✅ 应用已启动")
@@ -668,6 +670,20 @@ async def cmd_config(args):
668
670
  print()
669
671
 
670
672
 
673
+ async def cmd_update(args):
674
+ npm = shutil.which("npm") or shutil.which("npm.cmd")
675
+ if not npm:
676
+ print("[hmdev] ❌ 未找到 npm。请确保 Node.js 已安装。")
677
+ return
678
+ print("[hmdev] 正在更新 hmdev-cli ...")
679
+ result = subprocess.run([npm, "update", "-g", "hmdev-cli"], capture_output=True, text=True)
680
+ if result.returncode == 0:
681
+ print("[hmdev] ✅ 更新成功")
682
+ else:
683
+ err = result.stderr.strip() or result.stdout.strip()
684
+ print(f"[hmdev] ❌ 更新失败: {err}")
685
+
686
+
671
687
  # ── CLI Registration ──────────────────────────────────────────────────────────
672
688
 
673
689
  CLI_COMMANDS = {
@@ -682,6 +698,7 @@ CLI_COMMANDS = {
682
698
  "run": cmd_run,
683
699
  "connect": cmd_connect,
684
700
  "config": cmd_config,
701
+ "update": cmd_update,
685
702
  }
686
703
 
687
704
 
@@ -765,6 +782,10 @@ def build_cli_parser():
765
782
  p.add_argument("--reset", metavar="KEY", help="重置配置项")
766
783
  p.add_argument("--json", action="store_true", dest="json", help=SUPPRESS)
767
784
 
785
+ # update
786
+ p = sub.add_parser("update", help="更新 hmdev-cli 到最新版本 (npm update -g)")
787
+ p.add_argument("--json", action="store_true", dest="json", help=SUPPRESS)
788
+
768
789
  return parser
769
790
 
770
791