@gbits-jszx/gw-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/README.md +48 -0
- package/bin/gw-cli.js +49 -0
- package/bin/native/gw-cli-linux-amd64 +0 -0
- package/bin/native/gw-cli-windows-amd64.exe +0 -0
- package/package.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @gbits-jszx/gw-cli
|
|
2
|
+
|
|
3
|
+
GW-Framework 的跨平台构建、运行和交付工具。公网 registry 为 `https://registry.npmjs.org/`,包内包含 Windows amd64 和 Linux amd64(含 WSL)二进制。
|
|
4
|
+
|
|
5
|
+
打包过程和最终 `.tgz` 全部位于仓库根目录 `.gw-build/npm/`;源码目录不会生成 `bin/native` 或被 `npm version` 改写。
|
|
6
|
+
|
|
7
|
+
## 使用
|
|
8
|
+
|
|
9
|
+
首次发布成功后,在 GW-Framework 项目根目录执行:
|
|
10
|
+
|
|
11
|
+
```powershell
|
|
12
|
+
npx -y --prefer-online @gbits-jszx/gw-cli@latest --version
|
|
13
|
+
npx -y --prefer-online @gbits-jszx/gw-cli@latest doctor
|
|
14
|
+
npx -y --prefer-online @gbits-jszx/gw-cli@latest build all
|
|
15
|
+
npx -y --prefer-online @gbits-jszx/gw-cli@latest run all
|
|
16
|
+
# 另开终端
|
|
17
|
+
npx -y --prefer-online @gbits-jszx/gw-cli@latest test all
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`build`、`run`、`test` 统一接受 `core|mock|web|all`,`all` 只包含三个 app。`build`、`run` 需要源码和 Go,`run` 还需要 Docker(Windows 默认走 WSL)。npm 发布使用当前平台 npm;镜像命令优先使用当前平台 Docker,Windows 缺少 Docker 时转 WSL;Chart 推送在 Windows 默认走 WSL,可用 `--wsl=false` 切换。平台能力由 `doctor` 输出。
|
|
21
|
+
|
|
22
|
+
## 发布凭据
|
|
23
|
+
|
|
24
|
+
```powershell
|
|
25
|
+
npx -y --prefer-online @gbits-jszx/gw-cli@latest publish npm --version 0.2.1
|
|
26
|
+
npx -y --prefer-online @gbits-jszx/gw-cli@latest publish image --tag 0.2.1-dev
|
|
27
|
+
npx -y --prefer-online @gbits-jszx/gw-cli@latest publish chart --version 0.2.1
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
缺少 npm Token 或 Harbor Robot 账号/密码时,CLI 会询问并自动保存到 `~/jszx-infra/.gw-cli/config.yaml`;可用 `GW_CLI_CONFIG` 覆盖位置。已有配置不重复询问。命令参数、`NODE_AUTH_TOKEN` / `GW_HARBOR_USERNAME` / `GW_HARBOR_PASSWORD` 优先于用户配置。
|
|
31
|
+
|
|
32
|
+
Token 和密码在终端中不回显。配置文件保存明文凭据,Unix 下目录/文件权限为 0700/0600,Windows 使用用户目录 ACL。网关服务不读取此文件。
|
|
33
|
+
|
|
34
|
+
## 首次发布与本地验证
|
|
35
|
+
|
|
36
|
+
2026-09-09 查询公网 `@gbits-jszx/gw-cli` 返回 404;首次发布前直接运行源码 CLI:
|
|
37
|
+
|
|
38
|
+
```powershell
|
|
39
|
+
go run ./tools/cli npm package --version 0.2.0
|
|
40
|
+
npx -y --package ./.gw-build/npm/gbits-jszx-gw-cli-0.2.0.tgz gw-cli --version
|
|
41
|
+
npx -y --package ./.gw-build/npm/gbits-jszx-gw-cli-0.2.0.tgz gw-cli build all
|
|
42
|
+
# 只检查发布包,不上传、不询问 Token
|
|
43
|
+
go run ./tools/cli publish npm --dry-run
|
|
44
|
+
# 真正发布:输入具备 @gbits-jszx/gw-cli 发布权限的 npm Token
|
|
45
|
+
go run ./tools/cli publish npm --version 0.2.0
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
发布后的版本号不可复用。这里的 `gw-cli` 是包内命令名,公网下载始终使用 scoped 包 `@gbits-jszx/gw-cli`。
|
package/bin/gw-cli.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { spawn, spawnSync } = require('node:child_process');
|
|
5
|
+
|
|
6
|
+
const platform = process.platform === 'win32' ? 'windows' : process.platform;
|
|
7
|
+
const arch = process.arch === 'x64' ? 'amd64' : process.arch === 'arm64' ? 'arm64' : process.arch;
|
|
8
|
+
const extension = process.platform === 'win32' ? '.exe' : '';
|
|
9
|
+
const binary = path.join(__dirname, 'native', `gw-cli-${platform}-${arch}${extension}`);
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync(binary)) {
|
|
12
|
+
console.error(`gw-cli does not ship a binary for ${platform}/${arch}`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// npm may extract tarballs created on Windows without the executable bit.
|
|
17
|
+
// The package directory is user-owned, so repair it before spawning on Unix.
|
|
18
|
+
if (process.platform !== 'win32') {
|
|
19
|
+
try { fs.chmodSync(binary, 0o755); } catch (error) {
|
|
20
|
+
console.error(`cannot prepare gw-cli binary: ${error.message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Keep the native process in the console group so Ctrl+C reaches the Go
|
|
26
|
+
// supervisor and its deferred container/process cleanup runs on Windows.
|
|
27
|
+
const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit', windowsHide: false });
|
|
28
|
+
|
|
29
|
+
// Keep the wrapper alive while the native CLI stops its services and database.
|
|
30
|
+
// Windows console events already reach the child; child.kill('SIGINT') on
|
|
31
|
+
// Windows would force-terminate it and skip Go's deferred cleanup.
|
|
32
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
33
|
+
process.on(signal, () => {
|
|
34
|
+
if (process.platform !== 'win32') child.kill(signal);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
child.on('error', (error) => {
|
|
38
|
+
console.error(error.message);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
});
|
|
41
|
+
child.on('exit', (code) => {
|
|
42
|
+
// Run after the child exits; invoking Docker while a Windows Ctrl+C event is
|
|
43
|
+
// active can interrupt the cleanup subprocess itself.
|
|
44
|
+
// A test/build/publish in another terminal must not remove run all's DB.
|
|
45
|
+
if (process.argv[2] === 'run' && process.argv[3] === 'all') {
|
|
46
|
+
spawnSync(binary, ['cleanup'], { stdio: 'inherit', windowsHide: false });
|
|
47
|
+
}
|
|
48
|
+
process.exit(code === null ? 1 : code);
|
|
49
|
+
});
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bin": {
|
|
3
|
+
"gw-cli": "bin/gw-cli.js"
|
|
4
|
+
},
|
|
5
|
+
"description": "GW-Framework build, publish and k3s delivery CLI",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": "\u003e=18"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"name": "@gbits-jszx/gw-cli",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
},
|
|
18
|
+
"version": "0.2.0"
|
|
19
|
+
}
|