From 7c27a8334089206e68feb8bd4224fb41507b9785 Mon Sep 17 00:00:00 2001 From: jackwener Date: Fri, 17 Apr 2026 09:13:03 +0800 Subject: [PATCH] fix: add missing wx.js launcher to git (was gitignored by global config) --- npm/wx-cli/bin/wx.js | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 npm/wx-cli/bin/wx.js diff --git a/npm/wx-cli/bin/wx.js b/npm/wx-cli/bin/wx.js new file mode 100644 index 0000000..40a8427 --- /dev/null +++ b/npm/wx-cli/bin/wx.js @@ -0,0 +1,53 @@ +#!/usr/bin/env node +'use strict'; + +const { execFileSync } = require('child_process'); +const path = require('path'); +const fs = require('fs'); + +const PLATFORM_PACKAGES = { + 'darwin-arm64': '@jackwener/wx-cli-darwin-arm64', + 'darwin-x64': '@jackwener/wx-cli-darwin-x64', + 'linux-x64': '@jackwener/wx-cli-linux-x64', + 'linux-arm64': '@jackwener/wx-cli-linux-arm64', + 'win32-x64': '@jackwener/wx-cli-win32-x64', +}; + +const platformKey = `${process.platform}-${process.arch}`; +const ext = process.platform === 'win32' ? '.exe' : ''; + +function getBinaryPath() { + if (process.env.WX_CLI_BINARY) { + return process.env.WX_CLI_BINARY; + } + + const pkg = PLATFORM_PACKAGES[platformKey]; + if (!pkg) { + console.error(`wx-cli: unsupported platform ${platformKey}`); + process.exit(1); + } + + try { + return require.resolve(`${pkg}/bin/wx${ext}`); + } catch { + const modPath = path.join( + path.dirname(require.resolve(`${pkg}/package.json`)), + `bin/wx${ext}` + ); + if (fs.existsSync(modPath)) return modPath; + } + + console.error(`wx-cli: binary not found for ${platformKey}`); + console.error('Try: npm install -g @jackwener/wx-cli'); + process.exit(1); +} + +try { + execFileSync(getBinaryPath(), process.argv.slice(2), { + stdio: 'inherit', + env: { ...process.env }, + }); +} catch (e) { + if (e && e.status != null) process.exit(e.status); + throw e; +}