@canghe_ai/wechat-cli 0.2.0
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/bin/wechat-cli.js +55 -0
- package/install.js +36 -0
- package/package.json +30 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const PLATFORM_PACKAGES = {
|
|
8
|
+
'darwin-arm64': '@canghe_ai/wechat-cli-darwin-arm64',
|
|
9
|
+
'darwin-x64': '@canghe_ai/wechat-cli-darwin-x64',
|
|
10
|
+
'linux-x64': '@canghe_ai/wechat-cli-linux-x64',
|
|
11
|
+
'linux-arm64': '@canghe_ai/wechat-cli-linux-arm64',
|
|
12
|
+
'win32-x64': '@canghe_ai/wechat-cli-win32-x64',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
16
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
17
|
+
|
|
18
|
+
function getBinaryPath() {
|
|
19
|
+
// 1. 环境变量覆盖
|
|
20
|
+
if (process.env.WECHAT_CLI_BINARY) {
|
|
21
|
+
return process.env.WECHAT_CLI_BINARY;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 2. 从平台包解析
|
|
25
|
+
const pkg = PLATFORM_PACKAGES[platformKey];
|
|
26
|
+
if (!pkg) {
|
|
27
|
+
console.error(`wechat-cli: unsupported platform ${platformKey}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
return require.resolve(`${pkg}/bin/wechat-cli${ext}`);
|
|
33
|
+
} catch {
|
|
34
|
+
// 3. fallback: 直接找 node_modules 下的路径
|
|
35
|
+
const modPath = path.join(
|
|
36
|
+
path.dirname(require.resolve(`${pkg}/package.json`)),
|
|
37
|
+
`bin/wechat-cli${ext}`
|
|
38
|
+
);
|
|
39
|
+
if (fs.existsSync(modPath)) return modPath;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.error(`wechat-cli: binary not found for ${platformKey}`);
|
|
43
|
+
console.error('Try: npm install --force @canghe/wechat-cli');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
execFileSync(getBinaryPath(), process.argv.slice(2), {
|
|
49
|
+
stdio: 'inherit',
|
|
50
|
+
env: { ...process.env },
|
|
51
|
+
});
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if (e && e.status != null) process.exit(e.status);
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
|
|
7
|
+
const PLATFORM_PACKAGES = {
|
|
8
|
+
'darwin-arm64': '@canghe_ai/wechat-cli-darwin-arm64',
|
|
9
|
+
'darwin-x64': '@canghe_ai/wechat-cli-darwin-x64',
|
|
10
|
+
'linux-x64': '@canghe_ai/wechat-cli-linux-x64',
|
|
11
|
+
'linux-arm64': '@canghe_ai/wechat-cli-linux-arm64',
|
|
12
|
+
'win32-x64': '@canghe_ai/wechat-cli-win32-x64',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
16
|
+
const pkg = PLATFORM_PACKAGES[platformKey];
|
|
17
|
+
|
|
18
|
+
if (!pkg) {
|
|
19
|
+
console.log(`wechat-cli: no binary for ${platformKey}, skipping`);
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Try to find and chmod the binary
|
|
24
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const binaryPath = require.resolve(`${pkg}/bin/wechat-cli${ext}`);
|
|
28
|
+
if (process.platform !== 'win32') {
|
|
29
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
30
|
+
console.log(`wechat-cli: set executable permission for ${platformKey}`);
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
// Platform package was not installed (npm --no-optional or unsupported)
|
|
34
|
+
console.log(`wechat-cli: platform package ${pkg} not installed`);
|
|
35
|
+
console.log('To fix: npm install --force @canghe_ai/wechat-cli');
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@canghe_ai/wechat-cli",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "WeChat data query CLI — chat history, contacts, sessions, favorites, and more. Designed for LLM integration.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"wechat-cli": "bin/wechat-cli.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin/",
|
|
13
|
+
"install.js"
|
|
14
|
+
],
|
|
15
|
+
"optionalDependencies": {
|
|
16
|
+
"@canghe_ai/wechat-cli-darwin-arm64": "0.2.0"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=14"
|
|
20
|
+
},
|
|
21
|
+
"keywords": ["wechat", "cli", "wechat-cli", "llm", "ai"],
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/freestylefly/wechat-cli"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|