easc 0.0.6 → 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 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.6",
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",
@@ -21,6 +21,7 @@
21
21
  "prepublishOnly": "pnpm run test"
22
22
  },
23
23
  "dependencies": {
24
+ "axios": "^1.12.2",
24
25
  "chalk": "5.6.0",
25
26
  "ora": "^9.0.0",
26
27
  "tsx": "^4.20.6",
@@ -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
  */
@@ -1,5 +1,5 @@
1
1
  import fs from "fs";
2
- import { readFile } from "fs/promises";
2
+ import axios from "axios";
3
3
  import { IAppJson } from "./runtime";
4
4
  import { IMetadata } from "./files";
5
5
  import { IConfig } from "./schema";
@@ -15,13 +15,13 @@ export interface IUploadOptions {
15
15
  platform: PlatformType;
16
16
  runtimeVersion: string;
17
17
  expoConfig: IAppJson["expo"];
18
+ onProgress?: (loaded: number, total: number) => void;
18
19
  }
19
20
 
20
21
  /**
21
22
  * Upload a bundle and assets for a platform
22
23
  */
23
24
  export async function uploadBundle(options: IUploadOptions): Promise<void> {
24
- const startTime = Date.now();
25
25
  const {
26
26
  config,
27
27
  channel,
@@ -32,6 +32,7 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
32
32
  assetPaths,
33
33
  expoConfig,
34
34
  runtimeVersion,
35
+ onProgress,
35
36
  } = options;
36
37
 
37
38
  const form = new FormData();
@@ -46,8 +47,7 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
46
47
  }
47
48
 
48
49
  // Add bundle
49
- const fileReadStartTime = Date.now();
50
- const bundleBuffer = await readFile(bundlePath);
50
+ const bundleBuffer = fs.readFileSync(bundlePath);
51
51
  const bundleBlob = new Blob([bundleBuffer]);
52
52
  const bundleFileName = bundlePath.split("/").pop();
53
53
  if (!bundleFileName) {
@@ -55,17 +55,9 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
55
55
  }
56
56
  form.append("bundle", bundleBlob, bundleFileName);
57
57
 
58
- // Add assets in parallel
59
- const assetBuffers = await Promise.all(
60
- assetPaths.map((assetPath) => readFile(assetPath))
61
- );
62
- console.log(`⏱️ Files read in ${Date.now() - fileReadStartTime}ms`);
63
-
58
+ // Add assets
64
59
  assetPaths.forEach((assetPath, index) => {
65
- const assetBuffer = assetBuffers[index];
66
- if (!assetBuffer) {
67
- throw new Error(`Failed to read asset: ${assetPath}`);
68
- }
60
+ const assetBuffer = fs.readFileSync(assetPath);
69
61
  const assetBlob = new Blob([assetBuffer]);
70
62
  const assetFileName = assetPath.split("/").pop();
71
63
  if (!assetFileName) {
@@ -77,29 +69,24 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
77
69
  // Upload
78
70
  const url = new URL("/upload", config.otaServer);
79
71
 
80
- console.log(`⏱️ Uploading ${assetPaths.length + 1} files...`);
81
- const uploadStartTime = Date.now();
82
- const response = await fetch(url.toString(), {
83
- method: "POST",
84
- headers: {
85
- "x-ota-api-key": config.apiKey,
86
- },
87
- body: form,
88
- });
89
- console.log(`⏱️ Network upload completed in ${Date.now() - uploadStartTime}ms`);
90
-
91
- if (!response.ok) {
92
- let errorText = "";
93
- try {
94
- errorText = await response.text();
95
- } catch (e) {
96
- errorText = "Unable to read error response";
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}`);
97
87
  }
98
- throw new Error(`Upload failed: ${response.status} ${errorText}`);
88
+ throw error;
99
89
  }
100
-
101
- const totalTime = Date.now() - startTime;
102
- console.log(`⏱️ Total upload time: ${totalTime}ms (${(totalTime / 1000).toFixed(1)}s)`);
103
90
  }
104
91
 
105
92
  /**