easc 0.0.4 → 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/bin/easc.js +4 -1
- package/index.ts +8 -12
- package/package.json +12 -10
- package/src/enums/platform.ts +5 -2
- package/src/utils/files.ts +7 -7
- package/src/utils/logger.ts +1 -2
- package/src/utils/runtime.ts +1 -1
- package/src/utils/upload.ts +24 -7
package/bin/easc.js
CHANGED
|
@@ -3,12 +3,15 @@ import { spawn } from "child_process";
|
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
4
|
import { dirname, join } from "path";
|
|
5
5
|
import { existsSync } from "fs";
|
|
6
|
+
import { createRequire } from "module";
|
|
6
7
|
|
|
7
8
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const tsxPath = require.resolve("tsx/esm");
|
|
8
11
|
const indexPath = join(__dirname, "..", "index.ts");
|
|
9
12
|
|
|
10
13
|
const envPath = join(process.cwd(), ".env");
|
|
11
|
-
const nodeArgs = ["--
|
|
14
|
+
const nodeArgs = ["--import", tsxPath];
|
|
12
15
|
|
|
13
16
|
if (existsSync(envPath)) {
|
|
14
17
|
nodeArgs.push("--env-file", envPath);
|
package/index.ts
CHANGED
|
@@ -2,24 +2,20 @@
|
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import chalk from "chalk";
|
|
5
|
-
import { parseArguments } from "./src/utils/cli
|
|
6
|
-
import { validateConfig, getConfig } from "./src/utils/schema
|
|
7
|
-
import { resolveRuntimeVersion, getPlatforms } from "./src/utils/runtime
|
|
8
|
-
import {
|
|
9
|
-
getCommitHash,
|
|
10
|
-
getShortCommitHash,
|
|
11
|
-
isGitClean,
|
|
12
|
-
} from "./src/utils/git.ts";
|
|
5
|
+
import { parseArguments } from "./src/utils/cli";
|
|
6
|
+
import { validateConfig, getConfig } from "./src/utils/schema";
|
|
7
|
+
import { resolveRuntimeVersion, getPlatforms } from "./src/utils/runtime";
|
|
8
|
+
import { getCommitHash, getShortCommitHash, isGitClean } from "./src/utils/git";
|
|
13
9
|
import {
|
|
14
10
|
readAppJson,
|
|
15
11
|
readMetadata,
|
|
16
12
|
findBundleFile,
|
|
17
13
|
getAssetFiles,
|
|
18
14
|
checkExportDirectory,
|
|
19
|
-
} from "./src/utils/files
|
|
20
|
-
import { uploadBundle, createDryRunSummary } from "./src/utils/upload
|
|
21
|
-
import { Logger } from "./src/utils/logger
|
|
22
|
-
import
|
|
15
|
+
} from "./src/utils/files";
|
|
16
|
+
import { uploadBundle, createDryRunSummary } from "./src/utils/upload";
|
|
17
|
+
import { Logger } from "./src/utils/logger";
|
|
18
|
+
import { PlatformType } from "./src/enums/platform";
|
|
23
19
|
|
|
24
20
|
type IDeploymentResult = {
|
|
25
21
|
platform: PlatformType;
|
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,9 +12,18 @@
|
|
|
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",
|
|
26
|
+
"tsx": "^4.20.6",
|
|
18
27
|
"yargs": "^18.0.0",
|
|
19
28
|
"zod": "^4.1.12"
|
|
20
29
|
},
|
|
@@ -26,7 +35,7 @@
|
|
|
26
35
|
"vitest": "^3.2.4"
|
|
27
36
|
},
|
|
28
37
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
38
|
+
"node": ">=18.0.0"
|
|
30
39
|
},
|
|
31
40
|
"repository": {
|
|
32
41
|
"type": "git",
|
|
@@ -43,12 +52,5 @@
|
|
|
43
52
|
],
|
|
44
53
|
"publishConfig": {
|
|
45
54
|
"access": "public"
|
|
46
|
-
},
|
|
47
|
-
"scripts": {
|
|
48
|
-
"test": "vitest",
|
|
49
|
-
"test:watch": "vitest --watch",
|
|
50
|
-
"test:ui": "vitest --ui",
|
|
51
|
-
"test:coverage": "vitest --coverage",
|
|
52
|
-
"typecheck": "tsc --noEmit"
|
|
53
55
|
}
|
|
54
|
-
}
|
|
56
|
+
}
|
package/src/enums/platform.ts
CHANGED
package/src/utils/files.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { IAppJson } from "./runtime";
|
|
4
|
+
import { Platform, PlatformType } from "../enums/platform";
|
|
5
5
|
|
|
6
6
|
export interface IMetadata {
|
|
7
7
|
fileMetadata?: {
|
|
8
|
-
|
|
8
|
+
[Platform.iOS]?: {
|
|
9
9
|
assets: Array<{ path: string }>;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
[Platform.Android]?: {
|
|
12
12
|
assets: Array<{ path: string }>;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
@@ -96,9 +96,9 @@ export function getAssetFiles(
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
const platformMetadata =
|
|
99
|
-
platform ===
|
|
100
|
-
? metadata.fileMetadata?.
|
|
101
|
-
: metadata.fileMetadata?.
|
|
99
|
+
platform === Platform.iOS
|
|
100
|
+
? metadata.fileMetadata?.[Platform.iOS]
|
|
101
|
+
: metadata.fileMetadata?.[Platform.Android];
|
|
102
102
|
const platformAssets = platformMetadata?.assets || [];
|
|
103
103
|
|
|
104
104
|
if (platformAssets.length === 0) {
|
package/src/utils/logger.ts
CHANGED
package/src/utils/runtime.ts
CHANGED
package/src/utils/upload.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import { readFile } from "fs/promises";
|
|
3
|
+
import { IAppJson } from "./runtime";
|
|
4
|
+
import { IMetadata } from "./files";
|
|
5
|
+
import { IConfig } from "./schema";
|
|
6
|
+
import { PlatformType } from "../enums/platform";
|
|
6
7
|
|
|
7
8
|
export interface IUploadOptions {
|
|
8
9
|
config: IConfig;
|
|
@@ -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
|
/**
|