easc 0.0.33 → 0.0.34
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 +5 -5
- package/src/commands/update.ts +14 -10
- package/src/utils/cli.ts +1 -1
- package/src/utils/files.ts +1 -2
- package/src/utils/schema.ts +24 -23
- package/src/utils/upload.ts +11 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "Expo App Services for Cloudflare - Deploy tool for Expo OTA updates to Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"test:coverage": "vp test --coverage"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@expo/fingerprint": "^0.
|
|
38
|
+
"@expo/fingerprint": "^0.20.2",
|
|
39
39
|
"@inquirer/prompts": "^8.3.2",
|
|
40
40
|
"chalk": "5.6.2",
|
|
41
41
|
"tsx": "^4.21.0",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
42
|
+
"valibot": "^1.1.0",
|
|
43
|
+
"yargs": "^18.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^
|
|
46
|
+
"@types/node": "^26.1.0",
|
|
47
47
|
"@types/yargs": "^17.0.35",
|
|
48
48
|
"@vitest/ui": "^4.1.0",
|
|
49
49
|
"vite-plus": "latest",
|
package/src/commands/update.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
getAssetFiles,
|
|
10
10
|
checkExportDirectory,
|
|
11
11
|
} from "../utils/files";
|
|
12
|
-
import { uploadBundle, createDryRunSummary } from "../utils/upload";
|
|
12
|
+
import { uploadBundle, createDryRunSummary, getUpdateSize, formatBytes } from "../utils/upload";
|
|
13
13
|
import { createFingerprintAsync } from "@expo/fingerprint";
|
|
14
14
|
import { Logger } from "../utils/logger";
|
|
15
15
|
import { runx } from "../utils/runx";
|
|
@@ -106,6 +106,12 @@ export const update: CommandModule = {
|
|
|
106
106
|
const { hash: fingerprint } = await createFingerprintAsync(process.cwd());
|
|
107
107
|
logger.success(`Fingerprint: ${fingerprint}`);
|
|
108
108
|
|
|
109
|
+
const platformUploads = platforms.map((platform) => ({
|
|
110
|
+
platform,
|
|
111
|
+
bundlePath: findBundleFile(exportDir, metadata, platform),
|
|
112
|
+
assetPaths: getAssetFiles(exportDir, metadata, platform),
|
|
113
|
+
}));
|
|
114
|
+
|
|
109
115
|
logger.section("📤 Deployment Info");
|
|
110
116
|
logger.table([
|
|
111
117
|
["Server", config.otaServer],
|
|
@@ -114,14 +120,12 @@ export const update: CommandModule = {
|
|
|
114
120
|
["Fingerprint", fingerprint || ""],
|
|
115
121
|
["Export Dir", args.exportDir],
|
|
116
122
|
["Channel", channel],
|
|
123
|
+
...platformUploads.map(({ platform, bundlePath, assetPaths }): [string, string] => [
|
|
124
|
+
`Size (${platform})`,
|
|
125
|
+
formatBytes(getUpdateSize(bundlePath, assetPaths)),
|
|
126
|
+
]),
|
|
117
127
|
]);
|
|
118
128
|
|
|
119
|
-
const platformUploads = platforms.map((platform) => ({
|
|
120
|
-
platform,
|
|
121
|
-
bundlePath: findBundleFile(exportDir, metadata, platform),
|
|
122
|
-
assetPaths: getAssetFiles(exportDir, metadata, platform),
|
|
123
|
-
}));
|
|
124
|
-
|
|
125
129
|
if (args.dryRun) {
|
|
126
130
|
for (const { platform, bundlePath, assetPaths } of platformUploads) {
|
|
127
131
|
logger.section(platform.toUpperCase());
|
|
@@ -167,9 +171,9 @@ export const update: CommandModule = {
|
|
|
167
171
|
|
|
168
172
|
logger.stopSpinner();
|
|
169
173
|
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
throw
|
|
174
|
+
const firstFailure = results.find((r): r is PromiseRejectedResult => r.status === "rejected");
|
|
175
|
+
if (firstFailure) {
|
|
176
|
+
throw firstFailure.reason;
|
|
173
177
|
}
|
|
174
178
|
}
|
|
175
179
|
|
package/src/utils/cli.ts
CHANGED
package/src/utils/files.ts
CHANGED
|
@@ -168,8 +168,7 @@ function _isAppJson(value: unknown): value is IAppJson {
|
|
|
168
168
|
if (typeof value !== "object" || value === null || !("expo" in value)) {
|
|
169
169
|
return false;
|
|
170
170
|
}
|
|
171
|
-
|
|
172
|
-
return typeof record["expo"] === "object" && record["expo"] !== null;
|
|
171
|
+
return typeof value.expo === "object" && value.expo !== null;
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
/**
|
package/src/utils/schema.ts
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import
|
|
2
|
+
import * as v from "valibot";
|
|
3
3
|
|
|
4
|
-
const envSchema =
|
|
5
|
-
OTA_SERVER:
|
|
6
|
-
OTA_API_KEY:
|
|
4
|
+
const envSchema = v.object({
|
|
5
|
+
OTA_SERVER: v.pipe(v.string(), v.url("OTA_SERVER must be a valid URL")),
|
|
6
|
+
OTA_API_KEY: v.pipe(v.string(), v.minLength(1, "OTA_API_KEY is required")),
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
const channelSchema =
|
|
10
|
-
.string()
|
|
11
|
-
.
|
|
12
|
-
.regex(
|
|
9
|
+
const channelSchema = v.pipe(
|
|
10
|
+
v.string(),
|
|
11
|
+
v.minLength(1, "Channel name is required"),
|
|
12
|
+
v.regex(
|
|
13
13
|
/^[a-zA-Z0-9-_]+$/,
|
|
14
14
|
"Channel names can only contain letters, numbers, hyphens, and underscores",
|
|
15
|
-
)
|
|
15
|
+
),
|
|
16
|
+
);
|
|
16
17
|
|
|
17
|
-
const configSchema =
|
|
18
|
+
const configSchema = v.object({
|
|
18
19
|
channel: channelSchema,
|
|
19
|
-
otaServer:
|
|
20
|
-
apiKey:
|
|
20
|
+
otaServer: v.pipe(v.string(), v.url()),
|
|
21
|
+
apiKey: v.pipe(v.string(), v.minLength(1)),
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
export type IConfig =
|
|
24
|
+
export type IConfig = v.InferOutput<typeof configSchema>;
|
|
24
25
|
|
|
25
26
|
export interface IValidationResult {
|
|
26
27
|
valid: boolean;
|
|
@@ -28,11 +29,11 @@ export interface IValidationResult {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* Format
|
|
32
|
+
* Format valibot issues into user-friendly messages
|
|
32
33
|
*/
|
|
33
|
-
function
|
|
34
|
-
return
|
|
35
|
-
const path = err.path.join(".");
|
|
34
|
+
function formatIssues(issues: v.BaseIssue<unknown>[], context?: string): string[] {
|
|
35
|
+
return issues.map((err) => {
|
|
36
|
+
const path = (err.path ?? []).map((p) => p.key).join(".");
|
|
36
37
|
const message = err.message;
|
|
37
38
|
|
|
38
39
|
if (context === "environment") {
|
|
@@ -66,10 +67,10 @@ function formatZodError(error: z.ZodError, context?: string): string[] {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
|
-
* Validate environment variables
|
|
70
|
+
* Validate environment variables
|
|
70
71
|
*/
|
|
71
72
|
export function validateEnvironment(): IValidationResult {
|
|
72
|
-
const result =
|
|
73
|
+
const result = v.safeParse(envSchema, {
|
|
73
74
|
OTA_SERVER: process.env["OTA_SERVER"],
|
|
74
75
|
OTA_API_KEY: process.env["OTA_API_KEY"],
|
|
75
76
|
});
|
|
@@ -77,7 +78,7 @@ export function validateEnvironment(): IValidationResult {
|
|
|
77
78
|
if (!result.success) {
|
|
78
79
|
return {
|
|
79
80
|
valid: false,
|
|
80
|
-
errors:
|
|
81
|
+
errors: formatIssues(result.issues, "environment"),
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -85,7 +86,7 @@ export function validateEnvironment(): IValidationResult {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
/**
|
|
88
|
-
* Validate a channel name
|
|
89
|
+
* Validate a channel name
|
|
89
90
|
*/
|
|
90
91
|
export function validateChannel(channel: string | undefined): IValidationResult {
|
|
91
92
|
if (!channel) {
|
|
@@ -100,12 +101,12 @@ export function validateChannel(channel: string | undefined): IValidationResult
|
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
const result =
|
|
104
|
+
const result = v.safeParse(channelSchema, channel);
|
|
104
105
|
|
|
105
106
|
if (!result.success) {
|
|
106
107
|
return {
|
|
107
108
|
valid: false,
|
|
108
|
-
errors:
|
|
109
|
+
errors: formatIssues(result.issues, "channel"),
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
|
package/src/utils/upload.ts
CHANGED
|
@@ -118,9 +118,7 @@ export function createDryRunSummary(options: {
|
|
|
118
118
|
const { channel, platform, bundlePath, assetPaths, commitHash, runtimeVersion } = options;
|
|
119
119
|
|
|
120
120
|
const bundleSize = fs.statSync(bundlePath).size;
|
|
121
|
-
const totalAssetSize =
|
|
122
|
-
return sum + fs.statSync(path).size;
|
|
123
|
-
}, 0);
|
|
121
|
+
const totalAssetSize = getUpdateSize(bundlePath, assetPaths) - bundleSize;
|
|
124
122
|
|
|
125
123
|
const lines = [
|
|
126
124
|
`Platform: ${platform}`,
|
|
@@ -140,10 +138,19 @@ export function createDryRunSummary(options: {
|
|
|
140
138
|
return lines.join("\n");
|
|
141
139
|
}
|
|
142
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Total size on disk of a bundle plus its assets
|
|
143
|
+
*/
|
|
144
|
+
export function getUpdateSize(bundlePath: string, assetPaths: string[]): number {
|
|
145
|
+
return assetPaths.reduce((sum, path) => {
|
|
146
|
+
return sum + fs.statSync(path).size;
|
|
147
|
+
}, fs.statSync(bundlePath).size);
|
|
148
|
+
}
|
|
149
|
+
|
|
143
150
|
/**
|
|
144
151
|
* Format bytes to human readable string
|
|
145
152
|
*/
|
|
146
|
-
function formatBytes(bytes: number): string {
|
|
153
|
+
export function formatBytes(bytes: number): string {
|
|
147
154
|
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
148
155
|
if (bytes === 0) return "0 Bytes";
|
|
149
156
|
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|