easc 0.0.5 → 0.0.7
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/index.ts +3 -0
- package/package.json +11 -9
- package/src/utils/logger.ts +22 -0
- package/src/utils/upload.ts +19 -15
package/index.ts
CHANGED
|
@@ -127,6 +127,9 @@ type IDeploymentResult = {
|
|
|
127
127
|
expoConfig: appJson.expo,
|
|
128
128
|
metadata,
|
|
129
129
|
config,
|
|
130
|
+
onProgress: (loaded, total) => {
|
|
131
|
+
logger.updateProgress(loaded, total, `Uploading ${platform}`);
|
|
132
|
+
},
|
|
130
133
|
});
|
|
131
134
|
|
|
132
135
|
logger.succeedSpinner(`${platform} uploaded`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Expo App Services for Cloudflare - Deploy tool for Expo OTA updates to Cloudflare Workers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,16 @@
|
|
|
12
12
|
"index.ts",
|
|
13
13
|
"src"
|
|
14
14
|
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "vitest",
|
|
17
|
+
"test:watch": "vitest --watch",
|
|
18
|
+
"test:ui": "vitest --ui",
|
|
19
|
+
"test:coverage": "vitest --coverage",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"prepublishOnly": "pnpm run test"
|
|
22
|
+
},
|
|
15
23
|
"dependencies": {
|
|
24
|
+
"axios": "^1.12.2",
|
|
16
25
|
"chalk": "5.6.0",
|
|
17
26
|
"ora": "^9.0.0",
|
|
18
27
|
"tsx": "^4.20.6",
|
|
@@ -44,12 +53,5 @@
|
|
|
44
53
|
],
|
|
45
54
|
"publishConfig": {
|
|
46
55
|
"access": "public"
|
|
47
|
-
},
|
|
48
|
-
"scripts": {
|
|
49
|
-
"test": "vitest",
|
|
50
|
-
"test:watch": "vitest --watch",
|
|
51
|
-
"test:ui": "vitest --ui",
|
|
52
|
-
"test:coverage": "vitest --coverage",
|
|
53
|
-
"typecheck": "tsc --noEmit"
|
|
54
56
|
}
|
|
55
|
-
}
|
|
57
|
+
}
|
package/src/utils/logger.ts
CHANGED
|
@@ -50,6 +50,28 @@ export class Logger {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Update spinner with progress bar
|
|
55
|
+
*/
|
|
56
|
+
updateProgress(
|
|
57
|
+
loaded: number,
|
|
58
|
+
total: number,
|
|
59
|
+
prefix: string = "Uploading"
|
|
60
|
+
): void {
|
|
61
|
+
const percent = Math.round((loaded / total) * 100);
|
|
62
|
+
const loadedMB = (loaded / 1024 / 1024).toFixed(1);
|
|
63
|
+
const totalMB = (total / 1024 / 1024).toFixed(1);
|
|
64
|
+
|
|
65
|
+
// Create progress bar (20 characters wide)
|
|
66
|
+
const barWidth = 20;
|
|
67
|
+
const filled = Math.round((loaded / total) * barWidth);
|
|
68
|
+
const empty = barWidth - filled;
|
|
69
|
+
const bar = "█".repeat(filled) + "░".repeat(empty);
|
|
70
|
+
|
|
71
|
+
const message = `${prefix}... [${bar}] ${loadedMB} MB / ${totalMB} MB (${percent}%)`;
|
|
72
|
+
this.updateSpinner(message);
|
|
73
|
+
}
|
|
74
|
+
|
|
53
75
|
/**
|
|
54
76
|
* Stop spinner with success
|
|
55
77
|
*/
|
package/src/utils/upload.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
+
import axios from "axios";
|
|
2
3
|
import { IAppJson } from "./runtime";
|
|
3
4
|
import { IMetadata } from "./files";
|
|
4
5
|
import { IConfig } from "./schema";
|
|
@@ -14,6 +15,7 @@ export interface IUploadOptions {
|
|
|
14
15
|
platform: PlatformType;
|
|
15
16
|
runtimeVersion: string;
|
|
16
17
|
expoConfig: IAppJson["expo"];
|
|
18
|
+
onProgress?: (loaded: number, total: number) => void;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -30,6 +32,7 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
30
32
|
assetPaths,
|
|
31
33
|
expoConfig,
|
|
32
34
|
runtimeVersion,
|
|
35
|
+
onProgress,
|
|
33
36
|
} = options;
|
|
34
37
|
|
|
35
38
|
const form = new FormData();
|
|
@@ -66,22 +69,23 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
66
69
|
// Upload
|
|
67
70
|
const url = new URL("/upload", config.otaServer);
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
errorText =
|
|
72
|
+
try {
|
|
73
|
+
await axios.post(url.toString(), form, {
|
|
74
|
+
headers: {
|
|
75
|
+
"x-ota-api-key": config.apiKey,
|
|
76
|
+
},
|
|
77
|
+
onUploadProgress: (progressEvent) => {
|
|
78
|
+
if (progressEvent.total && onProgress) {
|
|
79
|
+
onProgress(progressEvent.loaded, progressEvent.total);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (axios.isAxiosError(error)) {
|
|
85
|
+
const errorText = error.response?.data || error.message;
|
|
86
|
+
throw new Error(`Upload failed: ${error.response?.status || "unknown"} ${errorText}`);
|
|
83
87
|
}
|
|
84
|
-
throw
|
|
88
|
+
throw error;
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
|