@windaka-erp/erp-cli 0.1.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/README.md +47 -0
- package/package.json +40 -0
- package/scripts/install.js +100 -0
- package/scripts/run.js +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @windaka-erp/erp-cli
|
|
2
|
+
|
|
3
|
+
物达通(WindaKa)物业管理 ERP 系统命令行工具。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @windaka-erp/erp-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# 初始化配置
|
|
15
|
+
erp-cli --as me config init
|
|
16
|
+
|
|
17
|
+
# 登录
|
|
18
|
+
erp-cli --as me auth login
|
|
19
|
+
|
|
20
|
+
# 查看状态
|
|
21
|
+
erp-cli --as me auth status
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 命令
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
erp-cli --as <id> config init/show/set/remove # 配置管理
|
|
28
|
+
erp-cli --as <id> auth login/login-start/login-wait # 登录
|
|
29
|
+
erp-cli --as <id> auth status/logout/list # 认证状态
|
|
30
|
+
erp-cli --as <id> api GET/POST <path> # 原始 API 调用
|
|
31
|
+
erp-cli --as <id> knowledge +search/+list-datasets # 知识库检索
|
|
32
|
+
erp-cli --as <id> workorder +list/+create # 工单操作
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 参数
|
|
36
|
+
|
|
37
|
+
- `--as <id>` — 用户标识(必填),企业微信用 Sender ID,本地用任意稳定标识(如 `me`)
|
|
38
|
+
- `--dry-run` — 预览请求内容,不实际执行
|
|
39
|
+
|
|
40
|
+
## 要求
|
|
41
|
+
|
|
42
|
+
- Node.js >= 14.0.0
|
|
43
|
+
- 支持 Windows (x64/arm64)、macOS (x64/arm64)、Linux (x64/arm64)
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@windaka-erp/erp-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ERP CLI - command-line tool for Windaka ERP system",
|
|
5
|
+
"bin": {
|
|
6
|
+
"erp-cli": "scripts/run.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node scripts/install.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"scripts/",
|
|
13
|
+
"bin/",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"erp",
|
|
18
|
+
"cli",
|
|
19
|
+
"windaka",
|
|
20
|
+
"property-management"
|
|
21
|
+
],
|
|
22
|
+
"author": "Windaka",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=14.0.0"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/windaka-erp/erp-cli.git"
|
|
30
|
+
},
|
|
31
|
+
"os": [
|
|
32
|
+
"win32",
|
|
33
|
+
"darwin",
|
|
34
|
+
"linux"
|
|
35
|
+
],
|
|
36
|
+
"cpu": [
|
|
37
|
+
"x64",
|
|
38
|
+
"arm64"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
// ── 配置 ──
|
|
6
|
+
const BINARY_NAME = "erp-cli";
|
|
7
|
+
const VERSION = require("../package.json").version;
|
|
8
|
+
const GITHUB_REPO = "windaka-erp/erp-cli";
|
|
9
|
+
|
|
10
|
+
// ── 平台映射 ──
|
|
11
|
+
function getPlatformInfo() {
|
|
12
|
+
const platform = process.platform;
|
|
13
|
+
const arch = process.arch;
|
|
14
|
+
|
|
15
|
+
const map = {
|
|
16
|
+
win32_x64: { target: "windows-amd64", ext: ".exe" },
|
|
17
|
+
win32_arm64: { target: "windows-arm64", ext: ".exe" },
|
|
18
|
+
darwin_x64: { target: "darwin-amd64", ext: "" },
|
|
19
|
+
darwin_arm64: { target: "darwin-arm64", ext: "" },
|
|
20
|
+
linux_x64: { target: "linux-amd64", ext: "" },
|
|
21
|
+
linux_arm64: { target: "linux-arm64", ext: "" },
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const key = `${platform}_${arch}`;
|
|
25
|
+
const info = map[key];
|
|
26
|
+
if (!info) {
|
|
27
|
+
console.error(`Unsupported platform: ${platform}-${arch}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
return info;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ── 下载地址 ──
|
|
34
|
+
function getDownloadURL(info) {
|
|
35
|
+
const filename = `${BINARY_NAME}-${info.target}${info.ext}`;
|
|
36
|
+
return `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/${filename}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ── 主流程 ──
|
|
40
|
+
function install() {
|
|
41
|
+
const pkgDir = path.join(__dirname, "..");
|
|
42
|
+
const binDir = path.join(pkgDir, "bin");
|
|
43
|
+
if (!fs.existsSync(binDir)) {
|
|
44
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const info = getPlatformInfo();
|
|
48
|
+
const binaryPath = path.join(binDir, `${BINARY_NAME}${info.ext}`);
|
|
49
|
+
|
|
50
|
+
// 1. 检查 bin/ 目录是否已有对应平台的二进制(npm pack 打包时带进来的)
|
|
51
|
+
if (fs.existsSync(binaryPath)) {
|
|
52
|
+
console.log(`Found bundled binary: ${binaryPath}`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 2. 检查项目根目录是否有本地编译产物(开发模式)
|
|
57
|
+
const localBinary = path.join(pkgDir, `${BINARY_NAME}${info.ext}`);
|
|
58
|
+
if (fs.existsSync(localBinary)) {
|
|
59
|
+
console.log(`Found local binary, copying...`);
|
|
60
|
+
fs.copyFileSync(localBinary, binaryPath);
|
|
61
|
+
console.log(`Installed from local build: ${binaryPath}`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 3. 从 GitHub Releases 下载
|
|
66
|
+
const url = getDownloadURL(info);
|
|
67
|
+
console.log(`Downloading ${BINARY_NAME} v${VERSION} for ${info.target}...`);
|
|
68
|
+
console.log(` URL: ${url}`);
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
if (process.platform === "win32") {
|
|
72
|
+
// Windows: 使用 PowerShell 下载
|
|
73
|
+
execSync(
|
|
74
|
+
`powershell -Command "Invoke-WebRequest -Uri '${url}' -OutFile '${binaryPath}'"`,
|
|
75
|
+
{ stdio: "inherit" }
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
// macOS/Linux: 使用 curl
|
|
79
|
+
execSync(`curl -L -o "${binaryPath}" "${url}"`, {
|
|
80
|
+
stdio: "inherit",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 设置可执行权限(非 Windows)
|
|
85
|
+
if (process.platform !== "win32") {
|
|
86
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log(`Successfully installed ${BINARY_NAME} v${VERSION}`);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error(`Download failed: ${err.message}`);
|
|
92
|
+
console.error(`You can build from source:`);
|
|
93
|
+
console.error(` git clone https://github.com/${GITHUB_REPO}.git`);
|
|
94
|
+
console.error(` cd erp-cli && go build -o ${BINARY_NAME} .`);
|
|
95
|
+
console.error(` Then copy the binary to: ${binaryPath}`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
install();
|
package/scripts/run.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { execFileSync } = require("child_process");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
|
|
6
|
+
const BINARY_NAME = "erp-cli";
|
|
7
|
+
|
|
8
|
+
function getBinaryPath() {
|
|
9
|
+
const binDir = path.join(__dirname, "..", "bin");
|
|
10
|
+
|
|
11
|
+
// 按优先级查找二进制
|
|
12
|
+
const candidates = [
|
|
13
|
+
path.join(binDir, `${BINARY_NAME}.exe`), // bin/erp-cli.exe (Windows)
|
|
14
|
+
path.join(binDir, BINARY_NAME), // bin/erp-cli (macOS/Linux)
|
|
15
|
+
path.join(__dirname, "..", `${BINARY_NAME}.exe`), // 根目录编译产物 (Windows)
|
|
16
|
+
path.join(__dirname, "..", BINARY_NAME), // 根目录编译产物 (macOS/Linux)
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
for (const p of candidates) {
|
|
20
|
+
if (fs.existsSync(p)) return p;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
console.error(`Error: ${BINARY_NAME} binary not found.`);
|
|
24
|
+
console.error(`Please run: npm install`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function main() {
|
|
29
|
+
const binary = getBinaryPath();
|
|
30
|
+
const args = process.argv.slice(2);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
execFileSync(binary, args, {
|
|
34
|
+
stdio: "inherit",
|
|
35
|
+
env: { ...process.env },
|
|
36
|
+
});
|
|
37
|
+
} catch (err) {
|
|
38
|
+
// execFileSync throws on non-zero exit codes; the binary already
|
|
39
|
+
// wrote its output to stdout/stderr, so just exit with same code.
|
|
40
|
+
process.exitCode = err.status || 1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
main();
|