feat: npm wrapper + CI publish, fix README YAML/JSON description

pull/2/head
jackwener 2026-04-16 22:33:53 +08:00
parent 6cdc806642
commit 47d17aeccf
9 changed files with 213 additions and 18 deletions

View File

@ -13,16 +13,29 @@ jobs:
include:
- os: macos-latest
target: aarch64-apple-darwin
name: wx-macos-arm64
asset: wx-macos-arm64
npm_dir: darwin-arm64
bin: wx
- os: macos-latest
target: x86_64-apple-darwin
name: wx-macos-x86_64
asset: wx-macos-x86_64
npm_dir: darwin-x64
bin: wx
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
name: wx-linux-x86_64
asset: wx-linux-x86_64
npm_dir: linux-x64
bin: wx
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
asset: wx-linux-arm64
npm_dir: linux-arm64
bin: wx
- os: windows-latest
target: x86_64-pc-windows-msvc
name: wx-windows-x86_64.exe
asset: wx-windows-x86_64.exe
npm_dir: win32-x64
bin: wx.exe
runs-on: ${{ matrix.os }}
@ -33,38 +46,98 @@ jobs:
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
- name: Install cross-compile tools (Linux arm64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update -q
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Build release
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Rename binary (Unix)
- name: Copy binary (Unix)
if: matrix.os != 'windows-latest'
run: |
cp target/${{ matrix.target }}/release/wx ${{ matrix.name }}
cp target/${{ matrix.target }}/release/wx ${{ matrix.asset }}
cp target/${{ matrix.target }}/release/wx npm/platforms/${{ matrix.npm_dir }}/bin/wx
- name: Rename binary (Windows)
- name: Copy binary (Windows)
if: matrix.os == 'windows-latest'
run: |
copy target\${{ matrix.target }}\release\wx.exe ${{ matrix.name }}
copy target\${{ matrix.target }}\release\wx.exe ${{ matrix.asset }}
copy target\${{ matrix.target }}\release\wx.exe npm\platforms\${{ matrix.npm_dir }}\bin\wx.exe
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}
name: ${{ matrix.asset }}
path: ${{ matrix.asset }}
- uses: actions/upload-artifact@v4
with:
name: npm-${{ matrix.npm_dir }}
path: npm/platforms/${{ matrix.npm_dir }}/bin/
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: ${{ matrix.name }}
files: ${{ matrix.asset }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-npm:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Download all platform binaries
uses: actions/download-artifact@v4
with:
pattern: npm-*
path: npm-bins/
- name: Place binaries into platform packages
run: |
for dir in darwin-arm64 darwin-x64 linux-x64 linux-arm64; do
mkdir -p npm/platforms/$dir/bin
cp npm-bins/npm-$dir/wx npm/platforms/$dir/bin/wx
chmod +x npm/platforms/$dir/bin/wx
done
mkdir -p npm/platforms/win32-x64/bin
cp npm-bins/npm-win32-x64/wx.exe npm/platforms/win32-x64/bin/wx.exe
- name: Publish platform packages
run: |
for dir in darwin-arm64 darwin-x64 linux-x64 linux-arm64 win32-x64; do
cd npm/platforms/$dir
npm publish
cd ../../..
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish main package
run: |
cd npm/wx-cli
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

View File

@ -18,14 +18,20 @@
- **零依赖安装** — 单一 Rust 二进制,一行命令装完
- **毫秒级响应** — 后台 daemon 持久缓存解密数据库mtime 不变则复用
- **AI 友好**`--json` 输出纯 JSON方便 LLM agent 直接调用
- **AI 友好**默认 YAML 输出,`--json` 切换为 JSON方便 LLM agent 直接调用
- **完全本地** — 数据不出本机,实时解密,无需全量预解密
---
## 安装
**macOS / Linux**
**npm推荐全平台**
```bash
npm install -g wx-cli
```
**macOS / Linuxcurl**
```bash
curl -fsSL https://raw.githubusercontent.com/jackwener/wx-cli/main/install.sh | bash
@ -49,6 +55,7 @@ irm https://raw.githubusercontent.com/jackwener/wx-cli/main/install.ps1 | iex
| macOS Apple Silicon | `wx-macos-arm64` |
| macOS Intel | `wx-macos-x86_64` |
| Linux x86_64 | `wx-linux-x86_64` |
| Linux arm64 | `wx-linux-arm64` |
| Windows x86_64 | `wx-windows-x86_64.exe` |
macOS / Linux`chmod +x wx && sudo mv wx /usr/local/bin/`
@ -137,9 +144,9 @@ wx export "张三" --format markdown -o chat.md
wx export "AI群" --since 2026-01-01 --format json
```
### JSON 输出AI agent 用)
### 输出格式
所有命令加 `--json` 输出机器可读的 JSON
默认输出 YAML`--json` 切换为 JSON适合 AI agent / `jq` 处理)
```bash
wx sessions --json

View File

@ -0,0 +1,10 @@
{
"name": "@wx-cli/darwin-arm64",
"version": "0.1.1",
"description": "wx-cli binary for macOS arm64",
"os": ["darwin"],
"cpu": ["arm64"],
"files": ["bin/"],
"license": "Apache-2.0",
"publishConfig": { "access": "public" }
}

View File

@ -0,0 +1,10 @@
{
"name": "@wx-cli/darwin-x64",
"version": "0.1.1",
"description": "wx-cli binary for macOS x64",
"os": ["darwin"],
"cpu": ["x64"],
"files": ["bin/"],
"license": "Apache-2.0",
"publishConfig": { "access": "public" }
}

View File

@ -0,0 +1,10 @@
{
"name": "@wx-cli/linux-arm64",
"version": "0.1.1",
"description": "wx-cli binary for Linux arm64",
"os": ["linux"],
"cpu": ["arm64"],
"files": ["bin/"],
"license": "Apache-2.0",
"publishConfig": { "access": "public" }
}

View File

@ -0,0 +1,10 @@
{
"name": "@wx-cli/linux-x64",
"version": "0.1.1",
"description": "wx-cli binary for Linux x64",
"os": ["linux"],
"cpu": ["x64"],
"files": ["bin/"],
"license": "Apache-2.0",
"publishConfig": { "access": "public" }
}

View File

@ -0,0 +1,10 @@
{
"name": "@wx-cli/win32-x64",
"version": "0.1.1",
"description": "wx-cli binary for Windows x64",
"os": ["win32"],
"cpu": ["x64"],
"files": ["bin/"],
"license": "Apache-2.0",
"publishConfig": { "access": "public" }
}

View File

@ -0,0 +1,31 @@
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const PLATFORM_PACKAGES = {
'darwin-arm64': '@wx-cli/darwin-arm64',
'darwin-x64': '@wx-cli/darwin-x64',
'linux-x64': '@wx-cli/linux-x64',
'linux-arm64': '@wx-cli/linux-arm64',
'win32-x64': '@wx-cli/win32-x64',
};
const platformKey = `${process.platform}-${process.arch}`;
const pkg = PLATFORM_PACKAGES[platformKey];
if (!pkg) {
console.log(`wx-cli: no binary for ${platformKey}, skipping`);
process.exit(0);
}
const ext = process.platform === 'win32' ? '.exe' : '';
try {
const binaryPath = require.resolve(`${pkg}/bin/wx${ext}`);
if (process.platform !== 'win32') {
fs.chmodSync(binaryPath, 0o755);
}
} catch {
console.log(`wx-cli: platform package ${pkg} not installed`);
}

View File

@ -0,0 +1,34 @@
{
"name": "wx-cli",
"version": "0.1.1",
"description": "Query your local WeChat data from the command line. Designed for LLM agent tool calls.",
"bin": {
"wx": "bin/wx.js"
},
"scripts": {
"postinstall": "node install.js"
},
"files": [
"bin/",
"install.js"
],
"optionalDependencies": {
"@wx-cli/darwin-arm64": "0.1.1",
"@wx-cli/darwin-x64": "0.1.1",
"@wx-cli/linux-x64": "0.1.1",
"@wx-cli/linux-arm64": "0.1.1",
"@wx-cli/win32-x64": "0.1.1"
},
"engines": {
"node": ">=14"
},
"keywords": ["wechat", "cli", "wx", "llm", "ai", "sqlite", "sqlcipher"],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/jackwener/wx-cli"
},
"publishConfig": {
"access": "public"
}
}