Global

Methods

buildSpawnArgs(command, args) → {Object}

Description:
  • 將command + args轉為Windows安全的spawn參數 策略優先順序:

    1. .exe → 直接spawn
    2. .cmd → 解析JS入口, 用node直接執行(繞過cmd.exe, 支援多行參數)
    3. .cmd但無法解析JS入口 → 透過cmd.exe /d /s /c執行(fallback, 不支援多行參數)
Source:
Parameters:
Name Type Description
command String

輸入執行檔名稱字串

args Array

輸入參數陣列

Returns:

回傳spawn參數物件, 內含file, args, opt

Type
Object

buildValidator(rule) → {function|null}

Description:
  • 建立驗證函式 支援'nonempty', 'json', 'min:100'或自訂函式, 多規則可用逗號串接

Source:
Parameters:
Name Type Description
rule String | function

輸入驗證規則字串或自訂函式

Returns:

回傳驗證函式, 無有效規則回傳null

Type
function | null

escapeWinArg(arg) → {String}

Description:
  • 轉義cmd.exe的單一參數(cross-spawn escapeArgument邏輯) 參考: https://qntm.org/cmd

Source:
Parameters:
Name Type Description
arg String

輸入參數字串

Returns:

回傳轉義後參數字串

Type
String

escapeWinCmd(cmd) → {String}

Description:
  • 轉義cmd.exe的命令部分

Source:
Parameters:
Name Type Description
cmd String

輸入命令字串

Returns:

回傳轉義後命令字串

Type
String

execCliOnce(command, argsopt, optopt) → {Promise}

Description:
  • 單次非同步呼叫(內部使用, 不含重試邏輯)

Source:
Parameters:
Name Type Attributes Default Description
command String

輸入執行檔名稱字串

args Array <optional>
[]

輸入參數陣列

opt Object <optional>
{}

輸入設定物件

Returns:

回傳Promise, resolve回傳結果物件

Type
Promise

parseJsEntryFromCmd(cmdPath) → {String|null}

Description:
  • 從.cmd shim中解析出實際入口檔案路徑(可能為JS, 亦可能為原生.exe) npm全域安裝的.cmd格式固定, 末行為: ... "%_prog%" "%dp0%\node_modules...\entry" %* 入口可能為.js / .cjs / .mjs / 無副檔名 / .exe(如opencode的bin/opencode.exe), 故一律抓引號內node_modules後的相對路徑, 再以fsIsFile驗證實體檔存在 (只匹配.js會讓無副檔名入口落入cmd.exe fallback, 破壞多行prompt) 回傳後由buildSpawnArgs依副檔名決定: .exe直接spawn, 其餘交給node

Source:
Parameters:
Name Type Description
cmdPath String

輸入.cmd檔案路徑字串

Returns:

回傳入口檔案路徑字串, 無法解析回傳null

Type
String | null

resolveCommand(cmd) → {String}

Description:
  • 用where指令找到命令的實際路徑(.cmd / .exe)

Source:
Parameters:
Name Type Description
cmd String

輸入命令字串

Returns:

回傳解析後之命令路徑字串

Type
String