@mcesystems/apple-kit 1.0.69 → 1.0.71

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.
@@ -1,222 +1,222 @@
1
- #!/usr/bin/env tsx
2
- import { spawn } from "node:child_process";
3
- import { createWriteStream } from "node:fs";
4
- import { access, copyFile, mkdir, rename, rm } from "node:fs/promises";
5
- import https from "node:https";
6
- import path from "node:path";
7
- import { fileURLToPath } from "node:url";
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
-
12
- const PACKAGE_ROOT = path.resolve(__dirname, "..");
13
- const RESOURCES_DIR = path.join(PACKAGE_ROOT, "resources");
14
- const GO_IOS_DIST_DIR = path.join(PACKAGE_ROOT, "node_modules", "go-ios", "dist");
15
-
16
- const WINTUN_VERSION = "0.14.1";
17
- const WINTUN_ZIP_NAME = `wintun-${WINTUN_VERSION}.zip`;
18
- const WINTUN_URL = `https://www.wintun.net/builds/${WINTUN_ZIP_NAME}`;
19
- const WINTUN_ZIP_PATH = path.join(RESOURCES_DIR, WINTUN_ZIP_NAME);
20
- const WINTUN_EXTRACT_DIR = path.join(RESOURCES_DIR, ".wintun-extract");
21
-
22
- async function pathExists(targetPath: string): Promise<boolean> {
23
- try {
24
- await access(targetPath);
25
- return true;
26
- } catch {
27
- return false;
28
- }
29
- }
30
-
31
- function runCommand(command: string, args: string[]): Promise<void> {
32
- return new Promise((resolve, reject) => {
33
- const child = spawn(command, args, { stdio: "inherit" });
34
- child.on("error", (error) => reject(error));
35
- child.on("close", (code) => {
36
- if (code === 0) {
37
- resolve();
38
- return;
39
- }
40
- reject(new Error(`${command} exited with code ${code ?? "unknown"}`));
41
- });
42
- });
43
- }
44
-
45
- function downloadFile(url: string, destinationPath: string): Promise<void> {
46
- return new Promise((resolve, reject) => {
47
- const tempPath = `${destinationPath}.download`;
48
- const request = https.get(url, (response) => {
49
- if (!response.statusCode) {
50
- reject(new Error("No status code from download response."));
51
- return;
52
- }
53
-
54
- if ([301, 302, 307, 308].includes(response.statusCode)) {
55
- const redirect = response.headers.location;
56
- if (!redirect) {
57
- reject(new Error("Redirected without location header."));
58
- return;
59
- }
60
- const redirectUrl = new URL(redirect, url).toString();
61
- downloadFile(redirectUrl, destinationPath).then(resolve).catch(reject);
62
- return;
63
- }
64
-
65
- if (response.statusCode !== 200) {
66
- reject(new Error(`Download failed with status ${response.statusCode}`));
67
- return;
68
- }
69
-
70
- const fileStream = createWriteStream(tempPath);
71
- response.pipe(fileStream);
72
- fileStream.on("finish", () => {
73
- fileStream.close(() => {
74
- rename(tempPath, destinationPath).then(resolve).catch(reject);
75
- });
76
- });
77
- fileStream.on("error", async (error) => {
78
- await rm(tempPath, { force: true });
79
- reject(error);
80
- });
81
- });
82
-
83
- request.on("error", async (error) => {
84
- await rm(`${destinationPath}.download`, { force: true });
85
- reject(error);
86
- });
87
- });
88
- }
89
-
90
- async function ensureWintunZip(): Promise<void> {
91
- if (await pathExists(WINTUN_ZIP_PATH)) {
92
- console.log(`Wintun zip already exists: ${WINTUN_ZIP_NAME}`);
93
- return;
94
- }
95
-
96
- console.log(`Downloading Wintun zip from ${WINTUN_URL}`);
97
- await downloadFile(WINTUN_URL, WINTUN_ZIP_PATH);
98
- console.log(`Downloaded: ${WINTUN_ZIP_NAME}`);
99
- }
100
-
101
- async function extractWintunZip(): Promise<void> {
102
- await rm(WINTUN_EXTRACT_DIR, { recursive: true, force: true });
103
- await mkdir(WINTUN_EXTRACT_DIR, { recursive: true });
104
-
105
- try {
106
- await runCommand("tar", ["-xf", WINTUN_ZIP_PATH, "-C", WINTUN_EXTRACT_DIR]);
107
- return;
108
- } catch (error) {
109
- if (process.platform === "win32") {
110
- await runCommand("powershell", [
111
- "-NoProfile",
112
- "-Command",
113
- `Expand-Archive -Path "${WINTUN_ZIP_PATH}" -DestinationPath "${WINTUN_EXTRACT_DIR}" -Force`,
114
- ]);
115
- return;
116
- }
117
- throw error;
118
- }
119
- }
120
-
121
- function getWintunArchFolder(): string {
122
- if (process.arch === "x64") {
123
- return "amd64";
124
- }
125
- if (process.arch === "arm64") {
126
- return "arm64";
127
- }
128
- if (process.arch === "ia32") {
129
- return "x86";
130
- }
131
- throw new Error(`Unsupported Windows architecture: ${process.arch}`);
132
- }
133
-
134
- function getGoIosBinaryPath(): { sourcePath: string; destinationName: string } {
135
- if (process.platform === "win32") {
136
- if (process.arch !== "x64") {
137
- throw new Error(`Unsupported Windows architecture for go-ios: ${process.arch}`);
138
- }
139
- return {
140
- sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-windows-amd64_windows_amd64", "ios.exe"),
141
- destinationName: "ios.exe",
142
- };
143
- }
144
-
145
- if (process.platform === "darwin") {
146
- if (process.arch === "arm64") {
147
- return {
148
- sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-darwin-arm64_darwin_arm64", "ios"),
149
- destinationName: "ios",
150
- };
151
- }
152
- if (process.arch === "x64") {
153
- return {
154
- sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-darwin-amd64_darwin_amd64", "ios"),
155
- destinationName: "ios",
156
- };
157
- }
158
- }
159
-
160
- if (process.platform === "linux") {
161
- if (process.arch === "arm64") {
162
- return {
163
- sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-linux-arm64_linux_arm64", "ios"),
164
- destinationName: "ios",
165
- };
166
- }
167
- if (process.arch === "x64") {
168
- return {
169
- sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-linux-amd64_linux_amd64", "ios"),
170
- destinationName: "ios",
171
- };
172
- }
173
- }
174
-
175
- throw new Error(`Unsupported platform/arch for go-ios: ${process.platform}/${process.arch}`);
176
- }
177
-
178
- async function copyGoIosBinary(): Promise<void> {
179
- const { sourcePath, destinationName } = getGoIosBinaryPath();
180
- if (!(await pathExists(sourcePath))) {
181
- throw new Error(`go-ios binary not found: ${sourcePath}`);
182
- }
183
- await copyFile(sourcePath, path.join(RESOURCES_DIR, destinationName));
184
- console.log(`Copied go-ios binary to resources/${destinationName}`);
185
- }
186
-
187
- async function copyWintunDll(): Promise<void> {
188
- if (process.platform !== "win32") {
189
- console.log("Skipping Wintun: non-Windows platform detected.");
190
- return;
191
- }
192
-
193
- await ensureWintunZip();
194
- await extractWintunZip();
195
-
196
- const archFolder = getWintunArchFolder();
197
- const dllPath = path.join(WINTUN_EXTRACT_DIR, "wintun", "bin", archFolder, "wintun.dll");
198
- const licensePath = path.join(WINTUN_EXTRACT_DIR, "wintun", "LICENSE.txt");
199
-
200
- if (!(await pathExists(dllPath))) {
201
- throw new Error(`wintun.dll not found after extraction: ${dllPath}`);
202
- }
203
-
204
- await copyFile(dllPath, path.join(RESOURCES_DIR, "wintun.dll"));
205
- console.log(`Copied wintun.dll (${archFolder}) to resources/`);
206
-
207
- if (await pathExists(licensePath)) {
208
- await copyFile(licensePath, path.join(RESOURCES_DIR, "wintun-LICENSE.txt"));
209
- console.log("Copied Wintun license to resources/wintun-LICENSE.txt");
210
- }
211
- }
212
-
213
- async function main(): Promise<void> {
214
- await mkdir(RESOURCES_DIR, { recursive: true });
215
- await copyGoIosBinary();
216
- await copyWintunDll();
217
- }
218
-
219
- main().catch((error) => {
220
- console.error("Failed to prepare iOS resources:", error);
221
- process.exit(1);
222
- });
1
+ #!/usr/bin/env tsx
2
+ import { spawn } from "node:child_process";
3
+ import { createWriteStream } from "node:fs";
4
+ import { access, copyFile, mkdir, rename, rm } from "node:fs/promises";
5
+ import https from "node:https";
6
+ import path from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ const PACKAGE_ROOT = path.resolve(__dirname, "..");
13
+ const RESOURCES_DIR = path.join(PACKAGE_ROOT, "resources");
14
+ const GO_IOS_DIST_DIR = path.join(PACKAGE_ROOT, "node_modules", "go-ios", "dist");
15
+
16
+ const WINTUN_VERSION = "0.14.1";
17
+ const WINTUN_ZIP_NAME = `wintun-${WINTUN_VERSION}.zip`;
18
+ const WINTUN_URL = `https://www.wintun.net/builds/${WINTUN_ZIP_NAME}`;
19
+ const WINTUN_ZIP_PATH = path.join(RESOURCES_DIR, WINTUN_ZIP_NAME);
20
+ const WINTUN_EXTRACT_DIR = path.join(RESOURCES_DIR, ".wintun-extract");
21
+
22
+ async function pathExists(targetPath: string): Promise<boolean> {
23
+ try {
24
+ await access(targetPath);
25
+ return true;
26
+ } catch {
27
+ return false;
28
+ }
29
+ }
30
+
31
+ function runCommand(command: string, args: string[]): Promise<void> {
32
+ return new Promise((resolve, reject) => {
33
+ const child = spawn(command, args, { stdio: "inherit" });
34
+ child.on("error", (error) => reject(error));
35
+ child.on("close", (code) => {
36
+ if (code === 0) {
37
+ resolve();
38
+ return;
39
+ }
40
+ reject(new Error(`${command} exited with code ${code ?? "unknown"}`));
41
+ });
42
+ });
43
+ }
44
+
45
+ function downloadFile(url: string, destinationPath: string): Promise<void> {
46
+ return new Promise((resolve, reject) => {
47
+ const tempPath = `${destinationPath}.download`;
48
+ const request = https.get(url, (response) => {
49
+ if (!response.statusCode) {
50
+ reject(new Error("No status code from download response."));
51
+ return;
52
+ }
53
+
54
+ if ([301, 302, 307, 308].includes(response.statusCode)) {
55
+ const redirect = response.headers.location;
56
+ if (!redirect) {
57
+ reject(new Error("Redirected without location header."));
58
+ return;
59
+ }
60
+ const redirectUrl = new URL(redirect, url).toString();
61
+ downloadFile(redirectUrl, destinationPath).then(resolve).catch(reject);
62
+ return;
63
+ }
64
+
65
+ if (response.statusCode !== 200) {
66
+ reject(new Error(`Download failed with status ${response.statusCode}`));
67
+ return;
68
+ }
69
+
70
+ const fileStream = createWriteStream(tempPath);
71
+ response.pipe(fileStream);
72
+ fileStream.on("finish", () => {
73
+ fileStream.close(() => {
74
+ rename(tempPath, destinationPath).then(resolve).catch(reject);
75
+ });
76
+ });
77
+ fileStream.on("error", async (error) => {
78
+ await rm(tempPath, { force: true });
79
+ reject(error);
80
+ });
81
+ });
82
+
83
+ request.on("error", async (error) => {
84
+ await rm(`${destinationPath}.download`, { force: true });
85
+ reject(error);
86
+ });
87
+ });
88
+ }
89
+
90
+ async function ensureWintunZip(): Promise<void> {
91
+ if (await pathExists(WINTUN_ZIP_PATH)) {
92
+ console.log(`Wintun zip already exists: ${WINTUN_ZIP_NAME}`);
93
+ return;
94
+ }
95
+
96
+ console.log(`Downloading Wintun zip from ${WINTUN_URL}`);
97
+ await downloadFile(WINTUN_URL, WINTUN_ZIP_PATH);
98
+ console.log(`Downloaded: ${WINTUN_ZIP_NAME}`);
99
+ }
100
+
101
+ async function extractWintunZip(): Promise<void> {
102
+ await rm(WINTUN_EXTRACT_DIR, { recursive: true, force: true });
103
+ await mkdir(WINTUN_EXTRACT_DIR, { recursive: true });
104
+
105
+ try {
106
+ await runCommand("tar", ["-xf", WINTUN_ZIP_PATH, "-C", WINTUN_EXTRACT_DIR]);
107
+ return;
108
+ } catch (error) {
109
+ if (process.platform === "win32") {
110
+ await runCommand("powershell", [
111
+ "-NoProfile",
112
+ "-Command",
113
+ `Expand-Archive -Path "${WINTUN_ZIP_PATH}" -DestinationPath "${WINTUN_EXTRACT_DIR}" -Force`,
114
+ ]);
115
+ return;
116
+ }
117
+ throw error;
118
+ }
119
+ }
120
+
121
+ function getWintunArchFolder(): string {
122
+ if (process.arch === "x64") {
123
+ return "amd64";
124
+ }
125
+ if (process.arch === "arm64") {
126
+ return "arm64";
127
+ }
128
+ if (process.arch === "ia32") {
129
+ return "x86";
130
+ }
131
+ throw new Error(`Unsupported Windows architecture: ${process.arch}`);
132
+ }
133
+
134
+ function getGoIosBinaryPath(): { sourcePath: string; destinationName: string } {
135
+ if (process.platform === "win32") {
136
+ if (process.arch !== "x64") {
137
+ throw new Error(`Unsupported Windows architecture for go-ios: ${process.arch}`);
138
+ }
139
+ return {
140
+ sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-windows-amd64_windows_amd64", "ios.exe"),
141
+ destinationName: "ios.exe",
142
+ };
143
+ }
144
+
145
+ if (process.platform === "darwin") {
146
+ if (process.arch === "arm64") {
147
+ return {
148
+ sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-darwin-arm64_darwin_arm64", "ios"),
149
+ destinationName: "ios",
150
+ };
151
+ }
152
+ if (process.arch === "x64") {
153
+ return {
154
+ sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-darwin-amd64_darwin_amd64", "ios"),
155
+ destinationName: "ios",
156
+ };
157
+ }
158
+ }
159
+
160
+ if (process.platform === "linux") {
161
+ if (process.arch === "arm64") {
162
+ return {
163
+ sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-linux-arm64_linux_arm64", "ios"),
164
+ destinationName: "ios",
165
+ };
166
+ }
167
+ if (process.arch === "x64") {
168
+ return {
169
+ sourcePath: path.join(GO_IOS_DIST_DIR, "go-ios-linux-amd64_linux_amd64", "ios"),
170
+ destinationName: "ios",
171
+ };
172
+ }
173
+ }
174
+
175
+ throw new Error(`Unsupported platform/arch for go-ios: ${process.platform}/${process.arch}`);
176
+ }
177
+
178
+ async function copyGoIosBinary(): Promise<void> {
179
+ const { sourcePath, destinationName } = getGoIosBinaryPath();
180
+ if (!(await pathExists(sourcePath))) {
181
+ throw new Error(`go-ios binary not found: ${sourcePath}`);
182
+ }
183
+ await copyFile(sourcePath, path.join(RESOURCES_DIR, destinationName));
184
+ console.log(`Copied go-ios binary to resources/${destinationName}`);
185
+ }
186
+
187
+ async function copyWintunDll(): Promise<void> {
188
+ if (process.platform !== "win32") {
189
+ console.log("Skipping Wintun: non-Windows platform detected.");
190
+ return;
191
+ }
192
+
193
+ await ensureWintunZip();
194
+ await extractWintunZip();
195
+
196
+ const archFolder = getWintunArchFolder();
197
+ const dllPath = path.join(WINTUN_EXTRACT_DIR, "wintun", "bin", archFolder, "wintun.dll");
198
+ const licensePath = path.join(WINTUN_EXTRACT_DIR, "wintun", "LICENSE.txt");
199
+
200
+ if (!(await pathExists(dllPath))) {
201
+ throw new Error(`wintun.dll not found after extraction: ${dllPath}`);
202
+ }
203
+
204
+ await copyFile(dllPath, path.join(RESOURCES_DIR, "wintun.dll"));
205
+ console.log(`Copied wintun.dll (${archFolder}) to resources/`);
206
+
207
+ if (await pathExists(licensePath)) {
208
+ await copyFile(licensePath, path.join(RESOURCES_DIR, "wintun-LICENSE.txt"));
209
+ console.log("Copied Wintun license to resources/wintun-LICENSE.txt");
210
+ }
211
+ }
212
+
213
+ async function main(): Promise<void> {
214
+ await mkdir(RESOURCES_DIR, { recursive: true });
215
+ await copyGoIosBinary();
216
+ await copyWintunDll();
217
+ }
218
+
219
+ main().catch((error) => {
220
+ console.error("Failed to prepare iOS resources:", error);
221
+ process.exit(1);
222
+ });