easc 0.0.5 → 0.0.6
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/package.json +10 -9
- package/src/utils/upload.ts +20 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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,6 +12,14 @@
|
|
|
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": {
|
|
16
24
|
"chalk": "5.6.0",
|
|
17
25
|
"ora": "^9.0.0",
|
|
@@ -44,12 +52,5 @@
|
|
|
44
52
|
],
|
|
45
53
|
"publishConfig": {
|
|
46
54
|
"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
55
|
}
|
|
55
|
-
}
|
|
56
|
+
}
|
package/src/utils/upload.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
+
import { readFile } from "fs/promises";
|
|
2
3
|
import { IAppJson } from "./runtime";
|
|
3
4
|
import { IMetadata } from "./files";
|
|
4
5
|
import { IConfig } from "./schema";
|
|
@@ -20,6 +21,7 @@ export interface IUploadOptions {
|
|
|
20
21
|
* Upload a bundle and assets for a platform
|
|
21
22
|
*/
|
|
22
23
|
export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
24
|
+
const startTime = Date.now();
|
|
23
25
|
const {
|
|
24
26
|
config,
|
|
25
27
|
channel,
|
|
@@ -44,7 +46,8 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
// Add bundle
|
|
47
|
-
const
|
|
49
|
+
const fileReadStartTime = Date.now();
|
|
50
|
+
const bundleBuffer = await readFile(bundlePath);
|
|
48
51
|
const bundleBlob = new Blob([bundleBuffer]);
|
|
49
52
|
const bundleFileName = bundlePath.split("/").pop();
|
|
50
53
|
if (!bundleFileName) {
|
|
@@ -52,9 +55,17 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
52
55
|
}
|
|
53
56
|
form.append("bundle", bundleBlob, bundleFileName);
|
|
54
57
|
|
|
55
|
-
// Add assets
|
|
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
|
+
|
|
56
64
|
assetPaths.forEach((assetPath, index) => {
|
|
57
|
-
const assetBuffer =
|
|
65
|
+
const assetBuffer = assetBuffers[index];
|
|
66
|
+
if (!assetBuffer) {
|
|
67
|
+
throw new Error(`Failed to read asset: ${assetPath}`);
|
|
68
|
+
}
|
|
58
69
|
const assetBlob = new Blob([assetBuffer]);
|
|
59
70
|
const assetFileName = assetPath.split("/").pop();
|
|
60
71
|
if (!assetFileName) {
|
|
@@ -66,6 +77,8 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
66
77
|
// Upload
|
|
67
78
|
const url = new URL("/upload", config.otaServer);
|
|
68
79
|
|
|
80
|
+
console.log(`⏱️ Uploading ${assetPaths.length + 1} files...`);
|
|
81
|
+
const uploadStartTime = Date.now();
|
|
69
82
|
const response = await fetch(url.toString(), {
|
|
70
83
|
method: "POST",
|
|
71
84
|
headers: {
|
|
@@ -73,6 +86,7 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
73
86
|
},
|
|
74
87
|
body: form,
|
|
75
88
|
});
|
|
89
|
+
console.log(`⏱️ Network upload completed in ${Date.now() - uploadStartTime}ms`);
|
|
76
90
|
|
|
77
91
|
if (!response.ok) {
|
|
78
92
|
let errorText = "";
|
|
@@ -83,6 +97,9 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
|
|
|
83
97
|
}
|
|
84
98
|
throw new Error(`Upload failed: ${response.status} ${errorText}`);
|
|
85
99
|
}
|
|
100
|
+
|
|
101
|
+
const totalTime = Date.now() - startTime;
|
|
102
|
+
console.log(`⏱️ Total upload time: ${totalTime}ms (${(totalTime / 1000).toFixed(1)}s)`);
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
/**
|