easc 0.0.1

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/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # easc
2
+
3
+ **E**xpo **A**pp **S**erver for **C**loudflare - Deploy tool for Expo OTA updates to Cloudflare Workers.
4
+
5
+ A drop in replacement for `eas`.
6
+
7
+ ## Usage
8
+
9
+ The tool requires the following environment variables to be set:
10
+
11
+ - `OTA_SERVER`: The URL of your OTA server
12
+ - `OTA_API_KEY`: Your API key for authentication
13
+
14
+ You can set these in a `.env` file or export them in your shell.
15
+
16
+ Then you can run:
17
+
18
+ ```bash
19
+ npx easc --channel production
20
+ ```
21
+
22
+ ### Deploy to a channel
23
+
24
+ ```bash
25
+ npx easc --channel production
26
+ ```
27
+
28
+ ## Development
29
+
30
+ To work on this package locally:
31
+
32
+ ```bash
33
+ # From the root of the monorepo
34
+ pnpm run build:deploy
35
+
36
+ # Test locally
37
+ cd packages/deploy
38
+ pnpm run dev -- --channel staging
39
+ ```
40
+
41
+ ## Publishing
42
+
43
+ To publish this package to npm:
44
+
45
+ ```bash
46
+ cd packages/deploy
47
+ pnpm run build
48
+ pnpm publish
49
+ ```
package/bin/easc.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'child_process';
3
+ import { fileURLToPath } from 'url';
4
+ import { dirname, join } from 'path';
5
+ import { existsSync } from 'fs';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const indexPath = join(__dirname, '..', 'index.ts');
9
+
10
+ // Detect if we're running in Bun
11
+ const isBun = typeof Bun !== 'undefined';
12
+
13
+ if (isBun) {
14
+ // Bun natively supports TypeScript, just import directly
15
+ await import(indexPath);
16
+ } else {
17
+ // Node.js - use tsx loader with --env-file if .env exists
18
+ const envPath = join(process.cwd(), '.env');
19
+ const nodeArgs = ['--import', 'tsx'];
20
+
21
+ // Add --env-file flag if .env exists in current directory
22
+ if (existsSync(envPath)) {
23
+ nodeArgs.push('--env-file', envPath);
24
+ }
25
+
26
+ nodeArgs.push(indexPath, ...process.argv.slice(2));
27
+
28
+ const child = spawn('node', nodeArgs, { stdio: 'inherit' });
29
+
30
+ child.on('exit', (code) => {
31
+ process.exit(code || 0);
32
+ });
33
+ }
package/index.ts ADDED
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from "child_process";
3
+ import fs from "fs";
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 { getCommitHash, getShortCommitHash, isGitClean } from "./src/utils/git";
9
+ import {
10
+ readAppJson,
11
+ readMetadata,
12
+ findBundleFile,
13
+ getAssetFiles,
14
+ checkExportDirectory,
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";
19
+
20
+ type IDeploymentResult = {
21
+ platform: PlatformType;
22
+ status: "dry_run" | "uploaded" | "failed";
23
+ bundle_size: number;
24
+ asset_count: number;
25
+ error?: string;
26
+ };
27
+
28
+ (async () => {
29
+ let logger: Logger;
30
+
31
+ try {
32
+ const options = parseArguments();
33
+
34
+ logger = new Logger();
35
+
36
+ const validation = validateConfig(options.channel);
37
+ if (!validation.valid) {
38
+ validation.errors.forEach((error) => logger.error(error));
39
+ process.exit(1);
40
+ }
41
+
42
+ const config = getConfig(options.channel!);
43
+
44
+ if (!isGitClean()) {
45
+ logger.warn("Working directory has uncommitted changes");
46
+ }
47
+
48
+ // Build if needed
49
+ if (!options.skipBuild) {
50
+ logger.startSpinner("Building app bundles...");
51
+
52
+ execSync(
53
+ options.exportDir !== "dist"
54
+ ? `npx expo export --output-dir ${options.exportDir}`
55
+ : "npx expo export",
56
+ {
57
+ cwd: process.cwd(),
58
+ stdio: "ignore",
59
+ }
60
+ );
61
+
62
+ logger.succeedSpinner("Build completed");
63
+ } else {
64
+ logger.info(
65
+ `Skipping build (using existing export from ${options.exportDir})`
66
+ );
67
+ }
68
+
69
+ const exportDir = checkExportDirectory(options.exportDir);
70
+ const appJson = readAppJson();
71
+ const metadata = readMetadata(exportDir);
72
+ const runtimeVersion = resolveRuntimeVersion(appJson);
73
+ const platforms = getPlatforms(appJson);
74
+ const commitHash = getCommitHash();
75
+ const shortCommit = getShortCommitHash();
76
+
77
+ logger.section("📤 Deployment Info");
78
+ logger.table([
79
+ ["Server", config.otaServer],
80
+ ["Runtime", runtimeVersion],
81
+ ["Commit", shortCommit || ""],
82
+ ["Export Dir", options.exportDir],
83
+ ["Channel", options.channel || ""],
84
+ ]);
85
+
86
+ const results: IDeploymentResult[] = [];
87
+
88
+ for (const platform of platforms) {
89
+ logger.section(platform.toUpperCase());
90
+
91
+ try {
92
+ // Find bundle and assets
93
+ const bundlePath = findBundleFile(exportDir, platform);
94
+ const assetPaths = getAssetFiles(exportDir, metadata, platform);
95
+
96
+ if (options.dryRun) {
97
+ // Dry run - just show what would be uploaded
98
+ const summary = createDryRunSummary({
99
+ platform,
100
+ bundlePath,
101
+ assetPaths,
102
+ channel: options.channel!,
103
+ runtimeVersion,
104
+ commitHash,
105
+ });
106
+
107
+ logger.box(summary);
108
+ logger.success(`${platform} (dry run)`);
109
+
110
+ results.push({
111
+ platform,
112
+ status: "dry_run",
113
+ bundle_size: fs.statSync(bundlePath).size,
114
+ asset_count: assetPaths.length,
115
+ });
116
+ } else {
117
+ // Actual upload
118
+ logger.startSpinner(`Uploading ${platform}...`);
119
+
120
+ await uploadBundle({
121
+ platform,
122
+ channel: options.channel!,
123
+ runtimeVersion,
124
+ commitHash,
125
+ bundlePath,
126
+ assetPaths,
127
+ expoConfig: appJson.expo,
128
+ metadata,
129
+ config,
130
+ });
131
+
132
+ logger.succeedSpinner(`${platform} uploaded`);
133
+
134
+ results.push({
135
+ platform,
136
+ status: "uploaded",
137
+ bundle_size: fs.statSync(bundlePath).size,
138
+ asset_count: assetPaths.length,
139
+ });
140
+ }
141
+ } catch (error) {
142
+ logger.failSpinner(`${platform} failed`);
143
+ results.push({
144
+ platform,
145
+ status: "failed",
146
+ bundle_size: 0,
147
+ asset_count: 0,
148
+ error: error instanceof Error ? error.message : String(error),
149
+ });
150
+ throw error;
151
+ }
152
+ }
153
+
154
+ logger.section("");
155
+ if (options.dryRun) {
156
+ logger.success("Dry run completed successfully!");
157
+ logger.info("Run without --dry-run to perform actual upload");
158
+ } else {
159
+ logger.success("✨ Updates published successfully!");
160
+ }
161
+ } catch (error) {
162
+ const errorMessage = error instanceof Error ? error.message : String(error);
163
+ console.error(chalk.red(`Deployment Failed: ${errorMessage}`));
164
+ process.exit(1);
165
+ }
166
+ })();
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "easc",
3
+ "version": "0.0.1",
4
+ "description": "Expo App Services for Cloudflare - Deploy tool for Expo OTA updates to Cloudflare Workers",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "bin": {
8
+ "easc": "./bin/easc.js"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "index.ts",
13
+ "src"
14
+ ],
15
+ "dependencies": {
16
+ "chalk": "5.6.0",
17
+ "ora": "^9.0.0",
18
+ "tsx": "^4.20.6",
19
+ "yargs": "^18.0.0",
20
+ "zod": "^3.24.1"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^24.7.0",
24
+ "@types/yargs": "^17.0.33",
25
+ "@vitest/ui": "^3.0.0",
26
+ "typescript": "^5.3.3",
27
+ "vitest": "^3.2.4"
28
+ },
29
+ "engines": {
30
+ "node": ">=18.0.0"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/Daniel-Griffiths/cloudflare-expo-ota-updates.git",
35
+ "directory": "packages/easc"
36
+ },
37
+ "keywords": [
38
+ "expo",
39
+ "ota",
40
+ "cloudflare",
41
+ "workers",
42
+ "deploy",
43
+ "updates"
44
+ ],
45
+ "publishConfig": {
46
+ "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
+ }
@@ -0,0 +1,6 @@
1
+ export enum Platform {
2
+ iOS = "ios",
3
+ Android = "android",
4
+ }
5
+
6
+ export type PlatformType = Platform.iOS | Platform.Android;
@@ -0,0 +1,118 @@
1
+ import yargs from "yargs";
2
+ import { hideBin } from "yargs/helpers";
3
+ import chalk from "chalk";
4
+
5
+ export interface ICliOptions {
6
+ channel?: string;
7
+ skipBuild: boolean;
8
+ dryRun: boolean;
9
+ environment?: "development" | "preview" | "production";
10
+ exportDir: string;
11
+ prod: boolean;
12
+ help?: boolean;
13
+ }
14
+
15
+ /**
16
+ * Map EAS environment to channel
17
+ */
18
+ function mapEnvironmentToChannel(
19
+ environment?: string,
20
+ prod?: boolean
21
+ ): string | undefined {
22
+ if (prod) return "production";
23
+ if (environment === "production") return "production";
24
+ if (environment === "preview") return "staging";
25
+ if (environment === "development") return "dev";
26
+ return undefined;
27
+ }
28
+
29
+ /**
30
+ * Parse command line arguments
31
+ */
32
+ export function parseArguments(argv: string[] = process.argv): ICliOptions {
33
+ const args = yargs(hideBin(argv))
34
+ .scriptName("easc")
35
+ .usage("$0 [options]")
36
+ .usage("$0 --channel <channel>")
37
+ .usage("$0 --prod")
38
+ .option("channel", {
39
+ alias: "c",
40
+ type: "string",
41
+ description: "Deployment channel (e.g., production, staging)",
42
+ })
43
+ .option("skip-build", {
44
+ type: "boolean",
45
+ description: "Skip running 'expo export' (use existing build)",
46
+ default: false,
47
+ })
48
+ .option("dry-run", {
49
+ type: "boolean",
50
+ description:
51
+ "Outputs deployment info instead of uploading (preview what would be deployed)",
52
+ default: false,
53
+ })
54
+ .option("environment", {
55
+ type: "string",
56
+ choices: ["development", "preview", "production"],
57
+ description: "Environment variable's environment",
58
+ })
59
+ .option("export-dir", {
60
+ type: "string",
61
+ description: "Directory where the Expo project was exported",
62
+ default: "dist",
63
+ })
64
+ .option("prod", {
65
+ type: "boolean",
66
+ description:
67
+ "Create a new production deployment (shorthand for --channel production)",
68
+ default: false,
69
+ })
70
+ .example("$0 --channel production", "Deploy to production channel")
71
+ .example("$0 --prod", "Deploy to production (EAS-style)")
72
+ .example("$0 --environment preview", "Deploy to preview environment")
73
+ .example("$0 -c staging --skip-build", "Deploy existing build to staging")
74
+ .example(
75
+ "$0 --dry-run --export-dir ./out",
76
+ "Dry run with custom export directory"
77
+ )
78
+ .help()
79
+ .alias("help", "h")
80
+ .alias("version", "V")
81
+ .strict()
82
+ .parseSync();
83
+
84
+ // Map EAS-style flags to our channel system
85
+ let channel = args.channel as string | undefined;
86
+
87
+ // If no channel specified, try to derive from EAS flags
88
+ if (!channel) {
89
+ channel = mapEnvironmentToChannel(
90
+ args.environment as string,
91
+ args.prod as boolean
92
+ );
93
+ }
94
+
95
+ // Validation: ensure we have a channel
96
+ if (!channel && !args.help) {
97
+ console.error(chalk.red("Error: Channel is required"));
98
+ console.log("Use one of the following:");
99
+ console.log(" easc --channel production");
100
+ console.log(" easc --prod");
101
+ console.log(" easc --environment production");
102
+ process.exit(1);
103
+ }
104
+
105
+ return {
106
+ channel,
107
+ skipBuild: args.skipBuild as boolean,
108
+ dryRun: args.dryRun as boolean,
109
+ environment: args.environment as
110
+ | "development"
111
+ | "preview"
112
+ | "production"
113
+ | undefined,
114
+ exportDir: args.exportDir as string,
115
+ prod: args.prod as boolean,
116
+ help: args.help as boolean | undefined,
117
+ };
118
+ }
@@ -0,0 +1,130 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import {
5
+ readAppJson,
6
+ readMetadata,
7
+ findBundleFile,
8
+ getAssetFiles,
9
+ checkDistDirectory,
10
+ } from "./files";
11
+
12
+ vi.mock("fs");
13
+ vi.mock("path");
14
+
15
+ describe("File utilities", () => {
16
+ beforeEach(() => {
17
+ vi.clearAllMocks();
18
+ vi.mocked(path.join).mockImplementation((...args) => args.join("/"));
19
+ });
20
+
21
+ describe("readAppJson", () => {
22
+ it("should read and parse app.json", () => {
23
+ const mockAppJson = {
24
+ expo: {
25
+ name: "TestApp",
26
+ version: "1.0.0",
27
+ },
28
+ };
29
+
30
+ vi.mocked(fs.existsSync).mockReturnValue(true);
31
+ vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockAppJson));
32
+
33
+ const result = readAppJson("/test/dir");
34
+
35
+ expect(fs.existsSync).toHaveBeenCalledWith("/test/dir/app.json");
36
+ expect(fs.readFileSync).toHaveBeenCalledWith("/test/dir/app.json", "utf-8");
37
+ expect(result).toEqual(mockAppJson);
38
+ });
39
+
40
+ it("should throw if app.json doesn't exist", () => {
41
+ vi.mocked(fs.existsSync).mockReturnValue(false);
42
+
43
+ expect(() => readAppJson("/test/dir")).toThrow("app.json not found");
44
+ });
45
+
46
+ it("should throw if app.json is invalid JSON", () => {
47
+ vi.mocked(fs.existsSync).mockReturnValue(true);
48
+ vi.mocked(fs.readFileSync).mockReturnValue("invalid json");
49
+
50
+ expect(() => readAppJson("/test/dir")).toThrow("Failed to parse app.json");
51
+ });
52
+ });
53
+
54
+ describe("readMetadata", () => {
55
+ it("should read and parse metadata.json", () => {
56
+ const mockMetadata = {
57
+ fileMetadata: {
58
+ ios: { assets: [] },
59
+ },
60
+ };
61
+
62
+ vi.mocked(fs.existsSync).mockReturnValue(true);
63
+ vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(mockMetadata));
64
+
65
+ const result = readMetadata("/test/dist");
66
+
67
+ expect(fs.existsSync).toHaveBeenCalledWith("/test/dist/metadata.json");
68
+ expect(result).toEqual(mockMetadata);
69
+ });
70
+
71
+ it("should throw if metadata.json doesn't exist", () => {
72
+ vi.mocked(fs.existsSync).mockReturnValue(false);
73
+
74
+ expect(() => readMetadata("/test/dist")).toThrow(
75
+ "metadata.json not found in /test/dist. Did you run 'expo export'?"
76
+ );
77
+ });
78
+ });
79
+
80
+ describe("findBundleFile", () => {
81
+ it("should find bundle file for platform", () => {
82
+ vi.mocked(fs.existsSync).mockReturnValue(true);
83
+ vi.mocked(fs.readdirSync).mockReturnValue([
84
+ "entry-abc123.hbc",
85
+ "other-file.js",
86
+ ] as any);
87
+
88
+ const result = findBundleFile("/dist", "ios");
89
+
90
+ expect(result).toBe("/dist/_expo/static/js/ios/entry-abc123.hbc");
91
+ });
92
+
93
+ it("should throw if bundle directory doesn't exist", () => {
94
+ vi.mocked(fs.existsSync).mockReturnValue(false);
95
+
96
+ expect(() => findBundleFile("/dist", "android")).toThrow(
97
+ "Bundle directory not found"
98
+ );
99
+ });
100
+
101
+ it("should throw if no bundle files found", () => {
102
+ vi.mocked(fs.existsSync).mockReturnValue(true);
103
+ vi.mocked(fs.readdirSync).mockReturnValue([]);
104
+
105
+ expect(() => findBundleFile("/dist", "ios")).toThrow(
106
+ "No bundle found for ios"
107
+ );
108
+ });
109
+ });
110
+
111
+ describe("checkDistDirectory", () => {
112
+ it("should return dist dir when valid", () => {
113
+ vi.mocked(fs.existsSync).mockReturnValue(true);
114
+
115
+ const result = checkDistDirectory("/test");
116
+
117
+ expect(result).toBe("/test/dist");
118
+ });
119
+
120
+ it("should throw if dist directory doesn't exist", () => {
121
+ vi.mocked(fs.existsSync).mockImplementation((path) => {
122
+ return path !== "/test/dist";
123
+ });
124
+
125
+ expect(() => checkDistDirectory("/test")).toThrow(
126
+ "Export directory not found"
127
+ );
128
+ });
129
+ });
130
+ });