@wbytts/byi 0.0.1
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 +42 -0
- package/bin/byi.cjs +68 -0
- package/dist/x86_64-unknown-linux-gnu/byi +0 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @wbytts/byi npm 包
|
|
2
|
+
|
|
3
|
+
这个目录用于把仓库根目录已经构建好的 Rust CLI 产物打包成 npm 包。
|
|
4
|
+
|
|
5
|
+
## 用法
|
|
6
|
+
|
|
7
|
+
先在仓库根目录构建 Rust 二进制:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
cargo build --release
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
如果需要一起发布多个平台,也可以预先构建对应 target:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cargo build --release --target x86_64-apple-darwin
|
|
17
|
+
cargo build --release --target aarch64-apple-darwin
|
|
18
|
+
cargo build --release --target x86_64-unknown-linux-gnu
|
|
19
|
+
cargo build --release --target aarch64-unknown-linux-gnu
|
|
20
|
+
cargo build --release --target x86_64-pc-windows-msvc
|
|
21
|
+
cargo build --release --target aarch64-pc-windows-msvc
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
然后进入发布目录执行:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm pack
|
|
28
|
+
npm publish
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`prepack` 会自动扫描仓库根目录 `target/` 下已有的 `byi` / `byi.exe`,复制到当前 npm 包的 `dist/` 中。
|
|
32
|
+
|
|
33
|
+
CI 场景下也支持从指定目录收集各平台二进制:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
BYI_PKG_SOURCE_DIR=/path/to/artifacts npm pack
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
正式发布时,建议先保证:
|
|
40
|
+
|
|
41
|
+
- Git tag 版本和当前 `package.json` 的 `version` 一致
|
|
42
|
+
- GitHub Actions 已收集到各平台 runner 的构建产物
|
package/bin/byi.cjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
|
|
7
|
+
const TARGET_MAP = {
|
|
8
|
+
darwin: {
|
|
9
|
+
x64: { triple: "x86_64-apple-darwin", binary: "byi" },
|
|
10
|
+
arm64: { triple: "aarch64-apple-darwin", binary: "byi" }
|
|
11
|
+
},
|
|
12
|
+
linux: {
|
|
13
|
+
x64: { triple: "x86_64-unknown-linux-gnu", binary: "byi" },
|
|
14
|
+
arm64: { triple: "aarch64-unknown-linux-gnu", binary: "byi" }
|
|
15
|
+
},
|
|
16
|
+
win32: {
|
|
17
|
+
x64: { triple: "x86_64-pc-windows-msvc", binary: "byi.exe" },
|
|
18
|
+
arm64: { triple: "aarch64-pc-windows-msvc", binary: "byi.exe" }
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function resolveBinary() {
|
|
23
|
+
const platformTargets = TARGET_MAP[process.platform];
|
|
24
|
+
if (!platformTargets) {
|
|
25
|
+
throw new Error(`不支持的运行平台: ${process.platform}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const target = platformTargets[process.arch];
|
|
29
|
+
if (!target) {
|
|
30
|
+
throw new Error(`不支持的系统架构: ${process.platform}/${process.arch}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const binaryPath = path.resolve(
|
|
34
|
+
__dirname,
|
|
35
|
+
"..",
|
|
36
|
+
"dist",
|
|
37
|
+
target.triple,
|
|
38
|
+
target.binary
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (!fs.existsSync(binaryPath)) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`npm 包内缺少当前平台的 Rust 产物: ${target.triple}/${target.binary}`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return binaryPath;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const binaryPath = resolveBinary();
|
|
51
|
+
|
|
52
|
+
if (process.platform !== "win32") {
|
|
53
|
+
try {
|
|
54
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(`无法为二进制设置执行权限: ${error.message}`);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
|
62
|
+
|
|
63
|
+
if (result.error) {
|
|
64
|
+
console.error(result.error.message);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
process.exit(result.status ?? 0);
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wbytts/byi",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "BYI CLI distributed through npm",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"bin": {
|
|
7
|
+
"byi": "bin/byi.cjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "node scripts/prepare-package.mjs",
|
|
16
|
+
"prepack": "node scripts/prepare-package.mjs",
|
|
17
|
+
"pack:dry-run": "npm pack --dry-run"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/wbytts/byi.git"
|
|
25
|
+
}
|
|
26
|
+
}
|