pup-recorder 0.0.8
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/Cargo.lock +230 -0
- package/Cargo.toml +23 -0
- package/LICENSE +26 -0
- package/README.md +96 -0
- package/build.rs +5 -0
- package/build.ts +55 -0
- package/build_rust.ts +51 -0
- package/dist/cjs/app.cjs +633 -0
- package/dist/cjs/app.cjs.map +7 -0
- package/dist/cjs/cli.cjs +691 -0
- package/dist/cjs/cli.cjs.map +7 -0
- package/dist/cjs/index.cjs +781 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cli.js +667 -0
- package/dist/cli.js.map +7 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +728 -0
- package/dist/index.js.map +7 -0
- package/package.json +37 -0
- package/rust/darwin-arm64.node +0 -0
- package/rust/darwin-x64.node +0 -0
- package/rust/linux-arm64.node +0 -0
- package/rust/linux-x64.node +0 -0
- package/src/app.ts +19 -0
- package/src/base/abort.ts +75 -0
- package/src/base/constants.ts +18 -0
- package/src/base/electron.ts +51 -0
- package/src/base/encoder.ts +35 -0
- package/src/base/env.ts +21 -0
- package/src/base/ffmpeg.ts +188 -0
- package/src/base/frame_sync.ts +139 -0
- package/src/base/image.ts +9 -0
- package/src/base/lazy.ts +20 -0
- package/src/base/limiter.ts +58 -0
- package/src/base/logging.ts +123 -0
- package/src/base/noerr.ts +18 -0
- package/src/base/parser.ts +12 -0
- package/src/base/process.ts +35 -0
- package/src/base/proxy.ts +33 -0
- package/src/base/record.ts +228 -0
- package/src/base/retry.ts +40 -0
- package/src/base/stream.ts +74 -0
- package/src/base/timing.ts +23 -0
- package/src/base/types.ts +19 -0
- package/src/cli.ts +6 -0
- package/src/common.ts +53 -0
- package/src/index.ts +14 -0
- package/src/pup.ts +142 -0
- package/src/rust/lib.rs +105 -0
- package/src/rust/lib.ts +28 -0
- package/tsconfig.json +25 -0
- package/x265/darwin-arm64 +0 -0
- package/x265/darwin-x64 +0 -0
- package/x265/linux-arm64 +0 -0
- package/x265/linux-x64 +0 -0
package/Cargo.lock
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "aho-corasick"
|
|
7
|
+
version = "1.1.4"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"memchr",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[package]]
|
|
15
|
+
name = "bitflags"
|
|
16
|
+
version = "2.10.0"
|
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
18
|
+
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
|
|
19
|
+
|
|
20
|
+
[[package]]
|
|
21
|
+
name = "cfg-if"
|
|
22
|
+
version = "1.0.4"
|
|
23
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
24
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
25
|
+
|
|
26
|
+
[[package]]
|
|
27
|
+
name = "convert_case"
|
|
28
|
+
version = "0.6.0"
|
|
29
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
30
|
+
checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
|
|
31
|
+
dependencies = [
|
|
32
|
+
"unicode-segmentation",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[[package]]
|
|
36
|
+
name = "ctor"
|
|
37
|
+
version = "0.2.9"
|
|
38
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
39
|
+
checksum = "32a2785755761f3ddc1492979ce1e48d2c00d09311c39e4466429188f3dd6501"
|
|
40
|
+
dependencies = [
|
|
41
|
+
"quote",
|
|
42
|
+
"syn",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[[package]]
|
|
46
|
+
name = "libloading"
|
|
47
|
+
version = "0.8.9"
|
|
48
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
49
|
+
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
|
50
|
+
dependencies = [
|
|
51
|
+
"cfg-if",
|
|
52
|
+
"windows-link",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[[package]]
|
|
56
|
+
name = "memchr"
|
|
57
|
+
version = "2.7.6"
|
|
58
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
59
|
+
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
|
60
|
+
|
|
61
|
+
[[package]]
|
|
62
|
+
name = "napi"
|
|
63
|
+
version = "2.16.17"
|
|
64
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
65
|
+
checksum = "55740c4ae1d8696773c78fdafd5d0e5fe9bc9f1b071c7ba493ba5c413a9184f3"
|
|
66
|
+
dependencies = [
|
|
67
|
+
"bitflags",
|
|
68
|
+
"ctor",
|
|
69
|
+
"napi-derive",
|
|
70
|
+
"napi-sys",
|
|
71
|
+
"once_cell",
|
|
72
|
+
"tokio",
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
[[package]]
|
|
76
|
+
name = "napi-build"
|
|
77
|
+
version = "2.3.1"
|
|
78
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
79
|
+
checksum = "d376940fd5b723c6893cd1ee3f33abbfd86acb1cd1ec079f3ab04a2a3bc4d3b1"
|
|
80
|
+
|
|
81
|
+
[[package]]
|
|
82
|
+
name = "napi-derive"
|
|
83
|
+
version = "2.16.13"
|
|
84
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
85
|
+
checksum = "7cbe2585d8ac223f7d34f13701434b9d5f4eb9c332cccce8dee57ea18ab8ab0c"
|
|
86
|
+
dependencies = [
|
|
87
|
+
"cfg-if",
|
|
88
|
+
"convert_case",
|
|
89
|
+
"napi-derive-backend",
|
|
90
|
+
"proc-macro2",
|
|
91
|
+
"quote",
|
|
92
|
+
"syn",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[[package]]
|
|
96
|
+
name = "napi-derive-backend"
|
|
97
|
+
version = "1.0.75"
|
|
98
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
99
|
+
checksum = "1639aaa9eeb76e91c6ae66da8ce3e89e921cd3885e99ec85f4abacae72fc91bf"
|
|
100
|
+
dependencies = [
|
|
101
|
+
"convert_case",
|
|
102
|
+
"once_cell",
|
|
103
|
+
"proc-macro2",
|
|
104
|
+
"quote",
|
|
105
|
+
"regex",
|
|
106
|
+
"semver",
|
|
107
|
+
"syn",
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
[[package]]
|
|
111
|
+
name = "napi-sys"
|
|
112
|
+
version = "2.4.0"
|
|
113
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
114
|
+
checksum = "427802e8ec3a734331fec1035594a210ce1ff4dc5bc1950530920ab717964ea3"
|
|
115
|
+
dependencies = [
|
|
116
|
+
"libloading",
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
[[package]]
|
|
120
|
+
name = "native"
|
|
121
|
+
version = "0.1.0"
|
|
122
|
+
dependencies = [
|
|
123
|
+
"napi",
|
|
124
|
+
"napi-build",
|
|
125
|
+
"napi-derive",
|
|
126
|
+
"tokio",
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
[[package]]
|
|
130
|
+
name = "once_cell"
|
|
131
|
+
version = "1.21.3"
|
|
132
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
133
|
+
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
|
134
|
+
|
|
135
|
+
[[package]]
|
|
136
|
+
name = "pin-project-lite"
|
|
137
|
+
version = "0.2.16"
|
|
138
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
139
|
+
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
|
140
|
+
|
|
141
|
+
[[package]]
|
|
142
|
+
name = "proc-macro2"
|
|
143
|
+
version = "1.0.106"
|
|
144
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
145
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
146
|
+
dependencies = [
|
|
147
|
+
"unicode-ident",
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
[[package]]
|
|
151
|
+
name = "quote"
|
|
152
|
+
version = "1.0.44"
|
|
153
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
154
|
+
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
|
|
155
|
+
dependencies = [
|
|
156
|
+
"proc-macro2",
|
|
157
|
+
]
|
|
158
|
+
|
|
159
|
+
[[package]]
|
|
160
|
+
name = "regex"
|
|
161
|
+
version = "1.12.2"
|
|
162
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
163
|
+
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
|
|
164
|
+
dependencies = [
|
|
165
|
+
"aho-corasick",
|
|
166
|
+
"memchr",
|
|
167
|
+
"regex-automata",
|
|
168
|
+
"regex-syntax",
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
[[package]]
|
|
172
|
+
name = "regex-automata"
|
|
173
|
+
version = "0.4.13"
|
|
174
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
175
|
+
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
|
176
|
+
dependencies = [
|
|
177
|
+
"aho-corasick",
|
|
178
|
+
"memchr",
|
|
179
|
+
"regex-syntax",
|
|
180
|
+
]
|
|
181
|
+
|
|
182
|
+
[[package]]
|
|
183
|
+
name = "regex-syntax"
|
|
184
|
+
version = "0.8.8"
|
|
185
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
186
|
+
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
|
187
|
+
|
|
188
|
+
[[package]]
|
|
189
|
+
name = "semver"
|
|
190
|
+
version = "1.0.27"
|
|
191
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
192
|
+
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
|
193
|
+
|
|
194
|
+
[[package]]
|
|
195
|
+
name = "syn"
|
|
196
|
+
version = "2.0.114"
|
|
197
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
198
|
+
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
|
199
|
+
dependencies = [
|
|
200
|
+
"proc-macro2",
|
|
201
|
+
"quote",
|
|
202
|
+
"unicode-ident",
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
[[package]]
|
|
206
|
+
name = "tokio"
|
|
207
|
+
version = "1.49.0"
|
|
208
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
209
|
+
checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
|
|
210
|
+
dependencies = [
|
|
211
|
+
"pin-project-lite",
|
|
212
|
+
]
|
|
213
|
+
|
|
214
|
+
[[package]]
|
|
215
|
+
name = "unicode-ident"
|
|
216
|
+
version = "1.0.22"
|
|
217
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
218
|
+
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
|
219
|
+
|
|
220
|
+
[[package]]
|
|
221
|
+
name = "unicode-segmentation"
|
|
222
|
+
version = "1.12.0"
|
|
223
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
224
|
+
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
|
|
225
|
+
|
|
226
|
+
[[package]]
|
|
227
|
+
name = "windows-link"
|
|
228
|
+
version = "0.2.1"
|
|
229
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
230
|
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
package/Cargo.toml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "native"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
|
|
6
|
+
[lib]
|
|
7
|
+
path = "src/rust/lib.rs"
|
|
8
|
+
crate-type = ["cdylib"]
|
|
9
|
+
|
|
10
|
+
[profile.release]
|
|
11
|
+
opt-level = 3
|
|
12
|
+
lto = true
|
|
13
|
+
codegen-units = 1
|
|
14
|
+
panic = "abort"
|
|
15
|
+
strip = true
|
|
16
|
+
|
|
17
|
+
[build-dependencies]
|
|
18
|
+
napi-build = "2"
|
|
19
|
+
|
|
20
|
+
[dependencies]
|
|
21
|
+
napi = { version = "2", features = ["napi4", "tokio_rt"] }
|
|
22
|
+
napi-derive = "2"
|
|
23
|
+
tokio = { version = "1", features = ["rt"] }
|
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Autokaka <qq1909698494@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
This project includes x265 binaries, which are licensed under GPL v2.
|
|
26
|
+
x265 source code is available at: https://bitbucket.org/multicoreware/x265_git
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# pup(1) -- High-performance webview recorder
|
|
2
|
+
|
|
3
|
+
## NAME
|
|
4
|
+
|
|
5
|
+
pup - record web pages as video
|
|
6
|
+
|
|
7
|
+
## SYNOPSIS
|
|
8
|
+
|
|
9
|
+
**pup** \<source\> [**-w** _width_] [**-h** _height_] [**-f** _fps_] [**-t** _duration_] [**-o** _dir_] [**-a**] [**--use-inner-proxy**]
|
|
10
|
+
|
|
11
|
+
## DESCRIPTION
|
|
12
|
+
|
|
13
|
+
**pup** captures a web page as video using Electron offscreen rendering.
|
|
14
|
+
|
|
15
|
+
Without **-a**, produces MP4 (H.264). With **-a**, produces WebM (VP9) and
|
|
16
|
+
MOV (HEVC with alpha channel). A cover image (PNG) is extracted from the
|
|
17
|
+
first frame.
|
|
18
|
+
|
|
19
|
+
## OPTIONS
|
|
20
|
+
|
|
21
|
+
- **\<source\>**
|
|
22
|
+
URL or HTML string to record.
|
|
23
|
+
|
|
24
|
+
- **-w**, **--width** _number_
|
|
25
|
+
Video width. Default: 1920.
|
|
26
|
+
|
|
27
|
+
- **-h**, **--height** _number_
|
|
28
|
+
Video height. Default: 1080.
|
|
29
|
+
|
|
30
|
+
- **-f**, **--fps** _number_
|
|
31
|
+
Frames per second. Default: 30.
|
|
32
|
+
|
|
33
|
+
- **-t**, **--duration** _number_
|
|
34
|
+
Recording duration in seconds. Default: 5.
|
|
35
|
+
|
|
36
|
+
- **-o**, **--out-dir** _path_
|
|
37
|
+
Output directory. Default: out.
|
|
38
|
+
|
|
39
|
+
- **-a**, **--with-alpha-channel**
|
|
40
|
+
Produce WebM + MOV with alpha channel instead of MP4.
|
|
41
|
+
|
|
42
|
+
- **--use-inner-proxy**
|
|
43
|
+
Use Bilibili internal proxy. Default: `$PUP_USE_INNER_PROXY`.
|
|
44
|
+
|
|
45
|
+
## ENVIRONMENT
|
|
46
|
+
|
|
47
|
+
- `PUP_LOG_LEVEL` (default: 2)
|
|
48
|
+
0=error, 1=warn, 2=info, 3=debug.
|
|
49
|
+
|
|
50
|
+
- `PUP_USE_INNER_PROXY` (default: 0)
|
|
51
|
+
Set to 1 to enable Bilibili internal proxy.
|
|
52
|
+
|
|
53
|
+
- `FFMPEG_BIN` (default: ffmpeg)
|
|
54
|
+
Path to FFmpeg binary.
|
|
55
|
+
|
|
56
|
+
## API
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { pup, type PupOptions } from "pup-recorder";
|
|
60
|
+
|
|
61
|
+
const result = await pup("https://example.com", {
|
|
62
|
+
width: 1920,
|
|
63
|
+
height: 1080,
|
|
64
|
+
fps: 30,
|
|
65
|
+
duration: 5,
|
|
66
|
+
outDir: "out",
|
|
67
|
+
withAlphaChannel: false,
|
|
68
|
+
onProgress: (progress) => console.log(progress),
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**PupOptions**: `width`, `height`, `fps`, `duration`, `outDir`,
|
|
73
|
+
`withAlphaChannel`, `cancelQuery`, `onProgress`.
|
|
74
|
+
|
|
75
|
+
**Returns**: `{ mp4?, webm?, mov?, cover, width, height, fps, duration }`.
|
|
76
|
+
|
|
77
|
+
## FILES
|
|
78
|
+
|
|
79
|
+
bin/pup.js CLI entry point
|
|
80
|
+
dist/index.js Library entry point
|
|
81
|
+
rust/*.node Precompiled native binaries
|
|
82
|
+
x265/* Precompiled x265 binaries
|
|
83
|
+
|
|
84
|
+
## EXAMPLES
|
|
85
|
+
|
|
86
|
+
pup https://example.com -w 1280 -h 720 -t 5
|
|
87
|
+
pup "file:///path/to/page.html" -a
|
|
88
|
+
pup https://example.com -f 60 -o ./output
|
|
89
|
+
|
|
90
|
+
## SEE ALSO
|
|
91
|
+
|
|
92
|
+
**pup-server**(1), **pup**(7)
|
|
93
|
+
|
|
94
|
+
## AUTHOR
|
|
95
|
+
|
|
96
|
+
qq1909698494@gmail.com
|
package/build.rs
ADDED
package/build.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Created by Autokaka (qq1909698494@gmail.com) on 2026/01/30.
|
|
2
|
+
|
|
3
|
+
import { $ } from "bun";
|
|
4
|
+
import { build } from "esbuild";
|
|
5
|
+
import { mkdir, rm } from "fs/promises";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const tsPath = require.resolve("@typescript/native-preview/package.json");
|
|
11
|
+
const dtsbPath = require.resolve("dts-bundle-generator");
|
|
12
|
+
|
|
13
|
+
const tsgo = join(tsPath, "..", "bin", "tsgo.js");
|
|
14
|
+
const dtsb = join(dtsbPath, "..", "bin", "dts-bundle-generator.js");
|
|
15
|
+
|
|
16
|
+
const common = {
|
|
17
|
+
platform: "node",
|
|
18
|
+
packages: "external",
|
|
19
|
+
bundle: true,
|
|
20
|
+
sourcemap: true,
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await $`${tsgo}`;
|
|
25
|
+
|
|
26
|
+
await rm("dist", { recursive: true, force: true });
|
|
27
|
+
await mkdir("dist", { recursive: true });
|
|
28
|
+
|
|
29
|
+
await Promise.all([
|
|
30
|
+
// library tsd
|
|
31
|
+
$`${dtsb} --silent -o dist/index.d.ts src/index.ts`,
|
|
32
|
+
build({
|
|
33
|
+
...common,
|
|
34
|
+
entryPoints: [
|
|
35
|
+
"src/index.ts", // library
|
|
36
|
+
"src/cli.ts", // cli
|
|
37
|
+
],
|
|
38
|
+
format: "esm",
|
|
39
|
+
outdir: "dist",
|
|
40
|
+
}),
|
|
41
|
+
build({
|
|
42
|
+
...common,
|
|
43
|
+
entryPoints: [
|
|
44
|
+
"src/index.ts", // library
|
|
45
|
+
"src/cli.ts", // cli
|
|
46
|
+
"src/app.ts", // electron app
|
|
47
|
+
],
|
|
48
|
+
format: "cjs",
|
|
49
|
+
outdir: "dist/cjs",
|
|
50
|
+
outExtension: { ".js": ".cjs" },
|
|
51
|
+
}),
|
|
52
|
+
]);
|
|
53
|
+
} catch {
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
package/build_rust.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Created by Autokaka (qq1909698494@gmail.com) on 2026/02/10.
|
|
2
|
+
|
|
3
|
+
import { $ } from "bun";
|
|
4
|
+
import { copyFile, mkdir } from "fs/promises";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
|
|
7
|
+
function getTriple(platform: string, arch: string) {
|
|
8
|
+
if (platform === "darwin") {
|
|
9
|
+
if (arch === "x64") return "x86_64-apple-darwin";
|
|
10
|
+
if (arch === "arm64") return "aarch64-apple-darwin";
|
|
11
|
+
}
|
|
12
|
+
if (platform === "linux") {
|
|
13
|
+
if (arch === "x64") return "x86_64-unknown-linux-gnu";
|
|
14
|
+
if (arch === "arm64") return "aarch64-unknown-linux-gnu";
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function copyArtifact(platform: string, arch: string, dir: string) {
|
|
20
|
+
const ext = platform === "darwin" ? "dylib" : "so";
|
|
21
|
+
const libName = `libnative.${ext}`;
|
|
22
|
+
const src = join(dir, libName);
|
|
23
|
+
const destDir = join("rust");
|
|
24
|
+
const dest = join(destDir, `${platform}-${arch}.node`);
|
|
25
|
+
await mkdir(destDir, { recursive: true });
|
|
26
|
+
await copyFile(src, dest);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function build(platform: string, arch: string) {
|
|
30
|
+
const triple = getTriple(platform, arch);
|
|
31
|
+
if (triple) {
|
|
32
|
+
await $`rustup target add ${triple}`;
|
|
33
|
+
await $`cargo zigbuild --release --target ${triple}`;
|
|
34
|
+
await copyArtifact(platform, arch, `target/${triple}/release`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function buildRust() {
|
|
39
|
+
const platforms = ["darwin", "linux"];
|
|
40
|
+
const archs = ["x64", "arm64"];
|
|
41
|
+
|
|
42
|
+
await $`cargo install cargo-zigbuild`;
|
|
43
|
+
|
|
44
|
+
for (const platform of platforms) {
|
|
45
|
+
for (const arch of archs) {
|
|
46
|
+
await build(platform, arch);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
buildRust();
|