Files
wehub-resource-sync d68f003000
CI / Change detection (push) Has been cancelled
CI / Version drift (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Workflow RLM cache (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / npm wrapper smoke (push) Has been cancelled
CI / Mobile runtime smoke (push) Has been cancelled
CI / Workflow lint (push) Has been cancelled
CI / Documentation (push) Has been cancelled
Web Frontend / Lint & Type Check (push) Failing after 1s
Auto-close harvested PRs / close (push) Failing after 1s
cargo-deny / cargo-deny (bans licenses sources) (push) Failing after 1s
Security audit / cargo-audit (push) Failing after 1s
Sync to CNB / sync (push) Failing after 1s
cargo-deny / cargo-deny (advisories) (push) Failing after 3s
Web Frontend / Deploy to Cloudflare (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:08:23 +08:00

72 lines
1.7 KiB
JavaScript

const { spawnSync } = require("child_process");
const { getBinaryPath } = require("./install");
const pkg = require("../package.json");
function isVersionFlag(args = process.argv.slice(2)) {
return args.includes("--version") || args.includes("-V");
}
function printVersionFallback(binaryName) {
const binVersion =
pkg.codewhaleBinaryVersion || pkg.deepseekBinaryVersion || pkg.version;
console.log(`${binaryName} (npm wrapper) v${pkg.version}`);
console.log(`binary version: v${binVersion}`);
console.log(`repo: ${pkg.repository?.url || "N/A"}`);
}
async function run(binaryName, options = {}) {
const args = options.args || process.argv.slice(2);
const resolveBinaryPath = options.getBinaryPath || getBinaryPath;
const spawn = options.spawnSync || spawnSync;
const exit = options.exit || process.exit;
const versionFlag = isVersionFlag(args);
let binaryPath;
try {
binaryPath = await resolveBinaryPath(binaryName);
} catch (error) {
if (versionFlag) {
printVersionFallback(binaryName);
return exit(0);
}
throw error;
}
const result = spawn(binaryPath, args, {
stdio: "inherit",
});
if (result.error) {
if (versionFlag) {
printVersionFallback(binaryName);
return exit(0);
}
throw result.error;
}
return exit(result.status ?? 1);
}
async function runCodeWhale() {
await run("codewhale");
}
async function runCodeWhaleTui() {
await run("codewhale-tui");
}
module.exports = {
run,
runCodeWhale,
runCodeWhaleTui,
_internal: { isVersionFlag, printVersionFallback },
};
if (require.main === module) {
const command = process.argv[1] || "";
if (command.includes("tui")) {
runCodeWhaleTui();
} else {
runCodeWhale();
}
}