keyapi-cli 0.0.0-stage → 1.0.2
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 +209 -2
- package/README.zh.md +118 -0
- package/npm/keyapi.js +50 -0
- package/package.json +37 -4
- package/scripts/platform.js +62 -0
- package/scripts/prepare-platform-packages.js +44 -0
package/README.md
CHANGED
|
@@ -1,3 +1,210 @@
|
|
|
1
|
-
#
|
|
1
|
+
# KeyAPI CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
[Chinese](https://github.com/EchoSell/keyapi-cli/blob/main/README.zh.md) | [English](https://github.com/EchoSell/keyapi-cli/blob/main/README.md)
|
|
6
|
+
|
|
7
|
+
KeyAPI CLI is a lightweight command line client for the [KeyAPI](https://keyapi.ai) platform. It helps you configure authentication, discover supported API platforms, inspect endpoint schemas, and call APIs without writing request code.
|
|
8
|
+
|
|
9
|
+
## Why KeyAPI CLI?
|
|
10
|
+
|
|
11
|
+
KeyAPI provides many APIs across platforms such as Google, TikTok, Instagram, and more. When a project uses many endpoints, manually writing and maintaining request code can become repetitive.
|
|
12
|
+
|
|
13
|
+
KeyAPI CLI provides one consistent entry point:
|
|
14
|
+
|
|
15
|
+
- configure your API token once
|
|
16
|
+
- list supported platforms
|
|
17
|
+
- list endpoints under each platform
|
|
18
|
+
- inspect endpoint methods, paths, descriptions, parameters, and request body fields
|
|
19
|
+
- execute API requests from the terminal
|
|
20
|
+
- save large responses to files
|
|
21
|
+
|
|
22
|
+
The CLI reads the latest KeyAPI OpenAPI documentation when endpoint details are requested, so endpoint descriptions and schemas stay aligned with the current KeyAPI API documentation.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- Simple configuration commands: `keyapi set`, `keyapi get`, `keyapi show`, `keyapi clear`
|
|
27
|
+
- API discovery commands: `keyapi spec list-platforms`, `keyapi spec list-endpoints`, `keyapi schema`
|
|
28
|
+
- One request command: `keyapi call`
|
|
29
|
+
- JSON output by default for `spec` and `call`
|
|
30
|
+
- Built-in `--help` output designed for humans, scripts, and agents
|
|
31
|
+
- `--dry-run` support before sending requests
|
|
32
|
+
- `--output "path"` support for large responses
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
Requires Node.js 18 or later:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install -g keyapi-cli
|
|
40
|
+
keyapi --help
|
|
41
|
+
keyapi --version
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The npm package installs a small JavaScript launcher plus the matching native
|
|
45
|
+
KeyAPI binary package for your operating system. If you already have a custom
|
|
46
|
+
KeyAPI binary, set `KEYAPI_CLI_BINARY` to its path before running `keyapi`.
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
Configure your KeyAPI token:
|
|
51
|
+
|
|
52
|
+
```powershell
|
|
53
|
+
keyapi set token sk_xxx
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Check the current configuration:
|
|
57
|
+
|
|
58
|
+
```powershell
|
|
59
|
+
keyapi show
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
List supported platforms:
|
|
63
|
+
|
|
64
|
+
```powershell
|
|
65
|
+
keyapi spec list-platforms
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
List endpoints for a platform:
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
keyapi spec list-endpoints google
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Inspect an endpoint before calling it:
|
|
75
|
+
|
|
76
|
+
```powershell
|
|
77
|
+
keyapi schema google/search
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Dry-run a request:
|
|
81
|
+
|
|
82
|
+
```powershell
|
|
83
|
+
keyapi call "/v1/google/search?q=openai&gl=us&hl=en" --dry-run
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Execute the request:
|
|
87
|
+
|
|
88
|
+
```powershell
|
|
89
|
+
keyapi call "/v1/google/search?q=openai&gl=us&hl=en"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Save a large response:
|
|
93
|
+
|
|
94
|
+
```powershell
|
|
95
|
+
keyapi call "/v1/google/search?q=openai&gl=us&hl=en" --output "google-search.json"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Clear the saved token when needed:
|
|
99
|
+
|
|
100
|
+
```powershell
|
|
101
|
+
keyapi clear token
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Commands
|
|
105
|
+
|
|
106
|
+
| Command | Purpose |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| `keyapi --help` | Show the main help, recommended order, and command help entry points. |
|
|
109
|
+
| `keyapi set token <value>` | Save the API token locally. |
|
|
110
|
+
| `keyapi set language <en\|zh>` | Set OpenAPI documentation language for endpoint descriptions. |
|
|
111
|
+
| `keyapi get <key>` | Read one local configuration value. |
|
|
112
|
+
| `keyapi show` | Show current local configuration. |
|
|
113
|
+
| `keyapi clear <key>` | Clear one local configuration value. |
|
|
114
|
+
| `keyapi spec list-platforms` | Return a JSON array of supported platforms. |
|
|
115
|
+
| `keyapi spec list-endpoints <platform...\|all>` | Return endpoint summaries for one or more platforms. |
|
|
116
|
+
| `keyapi spec get-endpoint <endpoint-or-path>` | Return method, path, description, parameters, and body fields for one endpoint. |
|
|
117
|
+
| `keyapi schema <endpoint-or-path>` | Short alias for `keyapi spec get-endpoint`. |
|
|
118
|
+
| `keyapi call <endpoint-or-path>` | Execute a KeyAPI request. |
|
|
119
|
+
|
|
120
|
+
Every command supports `--help`:
|
|
121
|
+
|
|
122
|
+
```powershell
|
|
123
|
+
keyapi --help
|
|
124
|
+
keyapi set --help
|
|
125
|
+
keyapi spec --help
|
|
126
|
+
keyapi spec list-platforms --help
|
|
127
|
+
keyapi spec list-endpoints --help
|
|
128
|
+
keyapi spec get-endpoint --help
|
|
129
|
+
keyapi schema --help
|
|
130
|
+
keyapi call --help
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Advanced Usage
|
|
134
|
+
|
|
135
|
+
### JSON Output
|
|
136
|
+
|
|
137
|
+
`spec` and `call` commands return JSON by default.
|
|
138
|
+
|
|
139
|
+
`keyapi spec list-platforms`:
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
["google", "tiktok"]
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`keyapi spec list-endpoints tiktok`:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"tiktok": [
|
|
150
|
+
{
|
|
151
|
+
"method": "GET",
|
|
152
|
+
"path": "/v1/tiktok/influencer/detail",
|
|
153
|
+
"summary": "User detail",
|
|
154
|
+
"description": "Get TikTok user detail."
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Save Large Responses
|
|
161
|
+
|
|
162
|
+
Some endpoints return large JSON responses, such as product details, images, SKU lists, or description fields. Use `--output "path"` to write the full response body to a file instead of printing it in the terminal:
|
|
163
|
+
|
|
164
|
+
```powershell
|
|
165
|
+
keyapi call "/v1/google/search?q=openai&gl=us" --output "outputs/google-search.json"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Relative output paths are resolved from the current working directory.
|
|
169
|
+
|
|
170
|
+
### Dry Run
|
|
171
|
+
|
|
172
|
+
Use `--dry-run` to print the request without sending it:
|
|
173
|
+
|
|
174
|
+
```powershell
|
|
175
|
+
keyapi call "/v1/google/search?q=openai&gl=us" --dry-run
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Request Body
|
|
179
|
+
|
|
180
|
+
Use `--body-json` for JSON request bodies:
|
|
181
|
+
|
|
182
|
+
```powershell
|
|
183
|
+
keyapi call "/v1/example/post-endpoint" --method POST --body-json '{"page":1,"verified":true}'
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Use `--body-raw` for raw text request bodies:
|
|
187
|
+
|
|
188
|
+
```powershell
|
|
189
|
+
keyapi call "/v1/example/text-endpoint" --method POST --body-raw "plain text"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
For GET endpoints, prefer putting query parameters directly in the endpoint path:
|
|
193
|
+
|
|
194
|
+
```powershell
|
|
195
|
+
keyapi call "/v1/google/search?q=openai&gl=us"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Use `--params "k=v"` or `--query "k=v"` when query parameters are easier to append programmatically.
|
|
199
|
+
|
|
200
|
+
## Documentation
|
|
201
|
+
|
|
202
|
+
`docs/` contains usage documentation for installing, configuring, and using the CLI. The CLI help output is the primary built-in reference for command usage.
|
|
203
|
+
|
|
204
|
+
| File | Purpose |
|
|
205
|
+
| --- | --- |
|
|
206
|
+
| [docs/index.md](docs/index.md) | Documentation entry point. |
|
|
207
|
+
| [docs/commands.md](docs/commands.md) | Full command and parameter reference. |
|
|
208
|
+
| [docs/config.md](docs/config.md) | Config file and environment variables. |
|
|
209
|
+
| [README.zh.md](README.zh.md) | Chinese README. |
|
|
210
|
+
| [docs/zh/index.md](docs/zh/index.md) | Chinese documentation entry point. |
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# KeyAPI CLI
|
|
2
|
+
|
|
3
|
+
[中文](https://github.com/EchoSell/keyapi-cli/blob/main/README.zh.md) | [English](https://github.com/EchoSell/keyapi-cli/blob/main/README.md)
|
|
4
|
+
|
|
5
|
+
KeyAPI CLI 是用于 [KeyAPI](https://keyapi.ai) 的轻量级命令行工具。它可以配置认证信息、发现支持的平台、查看接口 schema,并直接从终端调用 API。
|
|
6
|
+
|
|
7
|
+
## 功能
|
|
8
|
+
|
|
9
|
+
- 配置命令:`keyapi set`、`keyapi get`、`keyapi show`、`keyapi clear`
|
|
10
|
+
- 接口发现:`keyapi spec list-platforms`、`keyapi spec list-endpoints`
|
|
11
|
+
- schema 查看:`keyapi schema`
|
|
12
|
+
- 请求执行:`keyapi call`
|
|
13
|
+
- 默认 JSON 输出,适合脚本和 Agent 使用
|
|
14
|
+
- 支持 `--dry-run` 预览请求
|
|
15
|
+
- 支持 `--output "path"` 保存大响应
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
需要 Node.js 18 或更高版本:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g keyapi-cli
|
|
23
|
+
keyapi --help
|
|
24
|
+
keyapi --version
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
npm 包会安装一个 JavaScript 启动器,并自动安装当前系统对应的 KeyAPI 原生二进制包。如果你已经有自定义 KeyAPI 二进制文件,可以在运行 `keyapi` 前设置 `KEYAPI_CLI_BINARY` 指向该文件路径。
|
|
28
|
+
|
|
29
|
+
## 快速开始
|
|
30
|
+
|
|
31
|
+
配置 KeyAPI token:
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
keyapi set token sk_xxx
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
查看当前配置:
|
|
38
|
+
|
|
39
|
+
```powershell
|
|
40
|
+
keyapi show
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
列出支持的平台:
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
keyapi spec list-platforms
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
列出某个平台的接口:
|
|
50
|
+
|
|
51
|
+
```powershell
|
|
52
|
+
keyapi spec list-endpoints google
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
调用前查看接口 schema:
|
|
56
|
+
|
|
57
|
+
```powershell
|
|
58
|
+
keyapi schema google/search
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
预览请求:
|
|
62
|
+
|
|
63
|
+
```powershell
|
|
64
|
+
keyapi call "/v1/google/search?q=openai&gl=us&hl=en" --dry-run
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
执行请求:
|
|
68
|
+
|
|
69
|
+
```powershell
|
|
70
|
+
keyapi call "/v1/google/search?q=openai&gl=us&hl=en"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
保存大响应:
|
|
74
|
+
|
|
75
|
+
```powershell
|
|
76
|
+
keyapi call "/v1/google/search?q=openai&gl=us&hl=en" --output "google-search.json"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
清除 token:
|
|
80
|
+
|
|
81
|
+
```powershell
|
|
82
|
+
keyapi clear token
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 常用命令
|
|
86
|
+
|
|
87
|
+
| 命令 | 作用 |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| `keyapi --help` | 查看帮助 |
|
|
90
|
+
| `keyapi set token <value>` | 保存 API token |
|
|
91
|
+
| `keyapi set language <en|zh>` | 设置 OpenAPI 文档语言 |
|
|
92
|
+
| `keyapi show` | 查看当前配置 |
|
|
93
|
+
| `keyapi spec list-platforms` | 列出支持的平台 |
|
|
94
|
+
| `keyapi spec list-endpoints <platform...|all>` | 列出平台接口 |
|
|
95
|
+
| `keyapi schema <endpoint-or-path>` | 查看接口 schema |
|
|
96
|
+
| `keyapi call <endpoint-or-path>` | 调用接口 |
|
|
97
|
+
|
|
98
|
+
每个命令都支持 `--help`:
|
|
99
|
+
|
|
100
|
+
```powershell
|
|
101
|
+
keyapi --help
|
|
102
|
+
keyapi spec --help
|
|
103
|
+
keyapi schema --help
|
|
104
|
+
keyapi call --help
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 使用建议
|
|
108
|
+
|
|
109
|
+
推荐流程:
|
|
110
|
+
|
|
111
|
+
1. `keyapi set token sk_xxx`
|
|
112
|
+
2. `keyapi spec list-platforms`
|
|
113
|
+
3. `keyapi spec list-endpoints <platform>`
|
|
114
|
+
4. `keyapi schema <endpoint-or-path>`
|
|
115
|
+
5. `keyapi call <endpoint-or-path> --dry-run`
|
|
116
|
+
6. `keyapi call <endpoint-or-path>`
|
|
117
|
+
|
|
118
|
+
对于较大的 JSON 响应,使用 `--output "path"` 保存到文件。
|
package/npm/keyapi.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require('node:child_process');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
binaryNameForPlatform,
|
|
7
|
+
packageNameForPlatform,
|
|
8
|
+
} = require('../scripts/platform');
|
|
9
|
+
|
|
10
|
+
function resolveBinaryPath(options = {}) {
|
|
11
|
+
const env = options.env || process.env;
|
|
12
|
+
const platform = options.platform || process.platform;
|
|
13
|
+
const arch = options.arch || process.arch;
|
|
14
|
+
const resolve = options.resolve || require.resolve;
|
|
15
|
+
|
|
16
|
+
if (env.KEYAPI_CLI_BINARY) {
|
|
17
|
+
return env.KEYAPI_CLI_BINARY;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const packageName = packageNameForPlatform({ platform, arch });
|
|
21
|
+
return resolve(path.join(packageName, 'bin', binaryNameForPlatform({ platform })));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function main() {
|
|
25
|
+
const binaryPath = resolveBinaryPath();
|
|
26
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
27
|
+
stdio: 'inherit',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (result.error) {
|
|
31
|
+
console.error(`Failed to start KeyAPI CLI: ${result.error.message}`);
|
|
32
|
+
console.error('Try reinstalling keyapi-cli, or set KEYAPI_CLI_BINARY.');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (result.signal) {
|
|
37
|
+
process.kill(process.pid, result.signal);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
process.exit(result.status ?? 1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (require.main === module) {
|
|
45
|
+
main();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
resolveBinaryPath,
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keyapi-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "KeyAPI CLI for discovering endpoint schemas and calling KeyAPI APIs.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/EchoSell/keyapi-cli.git"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"keyapi": "npm/keyapi.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"npm",
|
|
15
|
+
"scripts",
|
|
16
|
+
"README.md",
|
|
17
|
+
"README.zh.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepare-platform-packages": "node scripts/prepare-platform-packages.js",
|
|
21
|
+
"test": "node --test test/*.test.js"
|
|
22
|
+
},
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"keyapi-cli-darwin-arm64": "1.0.2",
|
|
25
|
+
"keyapi-cli-darwin-x64": "1.0.2",
|
|
26
|
+
"keyapi-cli-linux-arm64": "1.0.2",
|
|
27
|
+
"keyapi-cli-linux-x64": "1.0.2",
|
|
28
|
+
"keyapi-cli-win32-x64": "1.0.2"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"keyapi",
|
|
32
|
+
"cli",
|
|
33
|
+
"api",
|
|
34
|
+
"openapi"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const osByPlatform = {
|
|
2
|
+
win32: 'windows',
|
|
3
|
+
darwin: 'darwin',
|
|
4
|
+
linux: 'linux',
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const archByArch = {
|
|
8
|
+
x64: 'amd64',
|
|
9
|
+
arm64: 'arm64',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const npmArchByArch = {
|
|
13
|
+
x64: 'x64',
|
|
14
|
+
arm64: 'arm64',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function targetForPlatform(options = {}) {
|
|
18
|
+
const platform = options.platform || process.platform;
|
|
19
|
+
const arch = options.arch || process.arch;
|
|
20
|
+
const os = osByPlatform[platform];
|
|
21
|
+
const goarch = archByArch[arch];
|
|
22
|
+
|
|
23
|
+
if (!os || !goarch) {
|
|
24
|
+
throw new Error(`Unsupported platform: ${platform}/${arch}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { os, arch: goarch };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function assetNameForPlatform(options = {}) {
|
|
31
|
+
if (!options.version) {
|
|
32
|
+
throw new Error('version is required');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const target = targetForPlatform(options);
|
|
36
|
+
const suffix = target.os === 'windows' ? '.exe' : '';
|
|
37
|
+
return `keyapi_${options.version}_${target.os}_${target.arch}${suffix}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function binaryNameForPlatform(options = {}) {
|
|
41
|
+
const platform = options.platform || process.platform;
|
|
42
|
+
return platform === 'win32' ? 'keyapi.exe' : 'keyapi';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function packageNameForPlatform(options = {}) {
|
|
46
|
+
const platform = options.platform || process.platform;
|
|
47
|
+
const arch = options.arch || process.arch;
|
|
48
|
+
const npmArch = npmArchByArch[arch];
|
|
49
|
+
|
|
50
|
+
if (!npmArch || !osByPlatform[platform]) {
|
|
51
|
+
throw new Error(`Unsupported platform: ${platform}/${arch}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return `keyapi-cli-${platform}-${npmArch}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
assetNameForPlatform,
|
|
59
|
+
binaryNameForPlatform,
|
|
60
|
+
packageNameForPlatform,
|
|
61
|
+
targetForPlatform,
|
|
62
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
const targets = [
|
|
6
|
+
{ goos: 'windows', goarch: 'amd64', packageName: 'keyapi-cli-win32-x64', binaryName: 'keyapi.exe' },
|
|
7
|
+
{ goos: 'linux', goarch: 'amd64', packageName: 'keyapi-cli-linux-x64', binaryName: 'keyapi' },
|
|
8
|
+
{ goos: 'linux', goarch: 'arm64', packageName: 'keyapi-cli-linux-arm64', binaryName: 'keyapi' },
|
|
9
|
+
{ goos: 'darwin', goarch: 'amd64', packageName: 'keyapi-cli-darwin-x64', binaryName: 'keyapi' },
|
|
10
|
+
{ goos: 'darwin', goarch: 'arm64', packageName: 'keyapi-cli-darwin-arm64', binaryName: 'keyapi' },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
function preparePlatformPackages(options = {}) {
|
|
14
|
+
const rootDir = options.rootDir || path.resolve(__dirname, '..');
|
|
15
|
+
const version = options.version || require(path.join(rootDir, 'package.json')).version;
|
|
16
|
+
const distDir = options.distDir || path.join(rootDir, 'dist');
|
|
17
|
+
const packagesDir = options.packagesDir || path.join(rootDir, 'npm-packages');
|
|
18
|
+
|
|
19
|
+
for (const target of targets) {
|
|
20
|
+
const source = path.join(
|
|
21
|
+
distDir,
|
|
22
|
+
`keyapi_${version}_${target.goos}_${target.goarch}${target.binaryName.endsWith('.exe') ? '.exe' : ''}`,
|
|
23
|
+
);
|
|
24
|
+
const binDir = path.join(packagesDir, target.packageName, 'bin');
|
|
25
|
+
const destination = path.join(binDir, target.binaryName);
|
|
26
|
+
|
|
27
|
+
if (!fs.existsSync(source)) {
|
|
28
|
+
throw new Error(`missing built binary: ${source}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
32
|
+
fs.copyFileSync(source, destination);
|
|
33
|
+
fs.chmodSync(destination, 0o755);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (require.main === module) {
|
|
38
|
+
preparePlatformPackages();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = {
|
|
42
|
+
preparePlatformPackages,
|
|
43
|
+
targets,
|
|
44
|
+
};
|