easc 0.0.2 → 0.0.4

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 CHANGED
@@ -1,41 +1,25 @@
1
1
  # easc
2
2
 
3
- **E**xpo **A**pp **S**erver for **C**loudflare - Deploy tool for Expo OTA updates to Cloudflare Workers.
3
+ **E**xpo **A**pp **S**ervices for **C**loudflare - CLI tool for deploying Expo OTA updates to Cloudflare Workers.
4
4
 
5
- A drop in replacement for `eas`.
5
+ ## Getting Started
6
6
 
7
- ## Usage
7
+ ### 1. Link for Local Testing
8
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:
9
+ To test the easc locally, you link the package to replace the published package with your local copy.
17
10
 
18
11
  ```bash
19
- npx easc --channel production
20
- ```
21
-
22
- ### Deploy to a channel
12
+ # From this directory
13
+ pnpm link --global
23
14
 
24
- ```bash
25
- npx easc --channel production
15
+ # Now you can use 'easc' command globally
16
+ easc --help
26
17
  ```
27
18
 
28
- ## Development
29
-
30
- To work on this package locally:
19
+ Or can also run directly with tsx:
31
20
 
32
21
  ```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
22
+ tsx index.ts --help
39
23
  ```
40
24
 
41
25
  ## Publishing
@@ -47,3 +31,5 @@ cd packages/deploy
47
31
  pnpm run build
48
32
  pnpm publish
49
33
  ```
34
+
35
+ Keep in mind that you'll have to change the name to somthing other than easc if you are not a admin on this project. You may wish to publish your own custom version for extra security.
package/bin/easc.js CHANGED
@@ -1,33 +1,23 @@
1
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';
2
+ import { spawn } from "child_process";
3
+ import { fileURLToPath } from "url";
4
+ import { dirname, join } from "path";
5
+ import { existsSync } from "fs";
6
6
 
7
7
  const __dirname = dirname(fileURLToPath(import.meta.url));
8
- const indexPath = join(__dirname, '..', 'index.ts');
8
+ const indexPath = join(__dirname, "..", "index.ts");
9
9
 
10
- // Detect if we're running in Bun
11
- const isBun = typeof Bun !== 'undefined';
10
+ const envPath = join(process.cwd(), ".env");
11
+ const nodeArgs = ["--experimental-strip-types"];
12
12
 
13
- if (isBun) {
14
- // Bun natively supports TypeScript, just import directly
15
- await import(indexPath);
16
- } else {
17
- // Node.js - use tsx for TypeScript support
18
- const envPath = join(process.cwd(), '.env');
19
- const nodeArgs = ['--import', 'tsx/esm'];
20
-
21
- // Add --env-file flag if .env exists in current directory
22
- if (existsSync(envPath)) {
23
- nodeArgs.push('--env-file', envPath);
24
- }
13
+ if (existsSync(envPath)) {
14
+ nodeArgs.push("--env-file", envPath);
15
+ }
25
16
 
26
- nodeArgs.push(indexPath, ...process.argv.slice(2));
17
+ nodeArgs.push(indexPath, ...process.argv.slice(2));
27
18
 
28
- const child = spawn('node', nodeArgs, { stdio: 'inherit' });
19
+ const child = spawn("node", nodeArgs, { stdio: "inherit" });
29
20
 
30
- child.on('exit', (code) => {
31
- process.exit(code || 0);
32
- });
33
- }
21
+ child.on("exit", (code) => {
22
+ process.exit(code || 0);
23
+ });
package/index.ts CHANGED
@@ -5,7 +5,11 @@ import chalk from "chalk";
5
5
  import { parseArguments } from "./src/utils/cli.ts";
6
6
  import { validateConfig, getConfig } from "./src/utils/schema.ts";
7
7
  import { resolveRuntimeVersion, getPlatforms } from "./src/utils/runtime.ts";
8
- import { getCommitHash, getShortCommitHash, isGitClean } from "./src/utils/git.ts";
8
+ import {
9
+ getCommitHash,
10
+ getShortCommitHash,
11
+ isGitClean,
12
+ } from "./src/utils/git.ts";
9
13
  import {
10
14
  readAppJson,
11
15
  readMetadata,
@@ -15,7 +19,7 @@ import {
15
19
  } from "./src/utils/files.ts";
16
20
  import { uploadBundle, createDryRunSummary } from "./src/utils/upload.ts";
17
21
  import { Logger } from "./src/utils/logger.ts";
18
- import { PlatformType } from "./src/enums/platform.ts";
22
+ import type { PlatformType } from "./src/enums/platform.ts";
19
23
 
20
24
  type IDeploymentResult = {
21
25
  platform: PlatformType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easc",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
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",
@@ -15,24 +15,23 @@
15
15
  "dependencies": {
16
16
  "chalk": "5.6.0",
17
17
  "ora": "^9.0.0",
18
- "tsx": "^4.20.6",
19
18
  "yargs": "^18.0.0",
20
- "zod": "^3.24.1"
19
+ "zod": "^4.1.12"
21
20
  },
22
21
  "devDependencies": {
23
- "@types/node": "^24.7.0",
22
+ "@types/node": "^24.8.0",
24
23
  "@types/yargs": "^17.0.33",
25
24
  "@vitest/ui": "^3.0.0",
26
25
  "typescript": "^5.3.3",
27
26
  "vitest": "^3.2.4"
28
27
  },
29
28
  "engines": {
30
- "node": ">=18.0.0"
29
+ "node": ">=22.6.0"
31
30
  },
32
31
  "repository": {
33
32
  "type": "git",
34
33
  "url": "git+https://github.com/Daniel-Griffiths/cloudflare-expo-ota-updates.git",
35
- "directory": "packages/easc"
34
+ "directory": "apps/easc"
36
35
  },
37
36
  "keywords": [
38
37
  "expo",
@@ -1,6 +1,3 @@
1
- export enum Platform {
2
- iOS = "ios",
3
- Android = "android",
4
- }
1
+ export type Platform = "ios" | "android";
5
2
 
6
- export type PlatformType = Platform.iOS | Platform.Android;
3
+ export type PlatformType = Platform;
package/src/utils/cli.ts CHANGED
@@ -3,13 +3,13 @@ import { hideBin } from "yargs/helpers";
3
3
  import chalk from "chalk";
4
4
 
5
5
  export interface ICliOptions {
6
- channel?: string;
6
+ channel?: string | undefined;
7
7
  skipBuild: boolean;
8
8
  dryRun: boolean;
9
- environment?: "development" | "preview" | "production";
9
+ environment?: "development" | "preview" | "production" | undefined;
10
10
  exportDir: string;
11
11
  prod: boolean;
12
- help?: boolean;
12
+ help?: boolean | undefined;
13
13
  }
14
14
 
15
15
  /**
@@ -17,10 +17,9 @@ export interface ICliOptions {
17
17
  */
18
18
  function mapEnvironmentToChannel(
19
19
  environment?: string,
20
- prod?: boolean
20
+ isShorthandProd?: boolean
21
21
  ): string | undefined {
22
- if (prod) return "production";
23
- if (environment === "production") return "production";
22
+ if (environment === "production" || isShorthandProd) return "production";
24
23
  if (environment === "preview") return "staging";
25
24
  if (environment === "development") return "dev";
26
25
  return undefined;
@@ -92,8 +91,7 @@ export function parseArguments(argv: string[] = process.argv): ICliOptions {
92
91
  );
93
92
  }
94
93
 
95
- // Validation: ensure we have a channel
96
- if (!channel && !args.help) {
94
+ if (!channel && !args["help"]) {
97
95
  console.error(chalk.red("Error: Channel is required"));
98
96
  console.log("Use one of the following:");
99
97
  console.log(" easc --channel production");
@@ -113,6 +111,6 @@ export function parseArguments(argv: string[] = process.argv): ICliOptions {
113
111
  | undefined,
114
112
  exportDir: args.exportDir as string,
115
113
  prod: args.prod as boolean,
116
- help: args.help as boolean | undefined,
114
+ help: args["help"] as boolean | undefined,
117
115
  };
118
116
  }
@@ -1,14 +1,14 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { IAppJson } from "./runtime.ts";
4
- import { Platform, PlatformType } from "../enums/platform.ts";
3
+ import type { IAppJson } from "./runtime.ts";
4
+ import type { PlatformType } from "../enums/platform.ts";
5
5
 
6
6
  export interface IMetadata {
7
7
  fileMetadata?: {
8
- [Platform.iOS]?: {
8
+ ios?: {
9
9
  assets: Array<{ path: string }>;
10
10
  };
11
- [Platform.Android]?: {
11
+ android?: {
12
12
  assets: Array<{ path: string }>;
13
13
  };
14
14
  };
@@ -73,7 +73,12 @@ export function findBundleFile(
73
73
  throw new Error(`No bundle found for ${platform}`);
74
74
  }
75
75
 
76
- return path.join(bundlePath, bundleFiles[0]);
76
+ const [firstBundle] = bundleFiles;
77
+ if (!firstBundle) {
78
+ throw new Error(`No bundle found for ${platform}`);
79
+ }
80
+
81
+ return path.join(bundlePath, firstBundle);
77
82
  }
78
83
 
79
84
  /**
@@ -91,9 +96,9 @@ export function getAssetFiles(
91
96
  }
92
97
 
93
98
  const platformMetadata =
94
- platform === Platform.iOS
95
- ? metadata.fileMetadata?.[Platform.iOS]
96
- : metadata.fileMetadata?.[Platform.Android];
99
+ platform === "ios"
100
+ ? metadata.fileMetadata?.ios
101
+ : metadata.fileMetadata?.android;
97
102
  const platformAssets = platformMetadata?.assets || [];
98
103
 
99
104
  if (platformAssets.length === 0) {
@@ -1,5 +1,6 @@
1
1
  import chalk from "chalk";
2
- import ora, { Ora } from "ora";
2
+ import ora from "ora";
3
+ import type { Ora } from "ora";
3
4
 
4
5
  export class Logger {
5
6
  private spinner: Ora | null = null;
@@ -2,7 +2,7 @@
2
2
  * Utilities for handling Expo runtime versions
3
3
  */
4
4
 
5
- import { PlatformType } from "../enums/platform";
5
+ import type { PlatformType } from "../enums/platform.ts";
6
6
 
7
7
  export interface IAppJson {
8
8
  expo: {
@@ -15,16 +15,17 @@ export interface IAppJson {
15
15
  /**
16
16
  * Resolve the runtime version from app.json
17
17
  * Supports both string values and policy objects
18
+ *
19
+ * When using `appVersion` the version is infered from
20
+ * the `version` property in `app.json`
18
21
  */
19
22
  export function resolveRuntimeVersion(appJson: IAppJson): string {
20
23
  const runtimeVersionConfig = appJson.expo.runtimeVersion;
21
24
 
22
- // If it's a string, use it directly
23
25
  if (typeof runtimeVersionConfig === "string") {
24
26
  return runtimeVersionConfig;
25
27
  }
26
28
 
27
- // If it's an object with policy: appVersion
28
29
  if (
29
30
  typeof runtimeVersionConfig === "object" &&
30
31
  runtimeVersionConfig?.policy === "appVersion"
@@ -50,5 +51,7 @@ export function resolveRuntimeVersion(appJson: IAppJson): string {
50
51
  */
51
52
  export function getPlatforms(appJson: IAppJson): PlatformType[] {
52
53
  const platforms = appJson.expo.platforms || ["ios", "android"];
53
- return platforms.filter(p => p === "ios" || p === "android") as PlatformType[];
54
- }
54
+ return platforms.filter(
55
+ (p) => p === "ios" || p === "android"
56
+ ) as PlatformType[];
57
+ }
@@ -1,9 +1,8 @@
1
1
  import chalk from "chalk";
2
2
  import { z } from "zod";
3
3
 
4
- // Zod schemas
5
4
  const envSchema = z.object({
6
- OTA_SERVER: z.string().url("OTA_SERVER must be a valid URL"),
5
+ OTA_SERVER: z.url("OTA_SERVER must be a valid URL"),
7
6
  OTA_API_KEY: z.string().min(1, "OTA_API_KEY is required"),
8
7
  });
9
8
 
@@ -16,13 +15,12 @@ const channelSchema = z
16
15
  );
17
16
 
18
17
  const configSchema = z.object({
19
- otaServer: z.string().url(),
20
- apiKey: z.string().min(1),
21
18
  channel: channelSchema,
19
+ otaServer: z.url(),
20
+ apiKey: z.string().min(1),
22
21
  });
23
22
 
24
- // Type exports
25
- export type Config = z.infer<typeof configSchema>;
23
+ export type IConfig = z.infer<typeof configSchema>;
26
24
 
27
25
  export interface IValidationResult {
28
26
  valid: boolean;
@@ -40,7 +38,9 @@ function formatZodError(error: z.ZodError, context?: string): string[] {
40
38
  if (context === "environment") {
41
39
  if (path === "OTA_SERVER") {
42
40
  return (
43
- `${chalk.red("OTA_SERVER")} environment variable is required or invalid\n` +
41
+ `${chalk.red(
42
+ "OTA_SERVER"
43
+ )} environment variable is required or invalid\n` +
44
44
  ` Set it in your .env file or export it:\n` +
45
45
  ` export OTA_SERVER="https://your-ota-server.com"`
46
46
  );
@@ -72,8 +72,8 @@ function formatZodError(error: z.ZodError, context?: string): string[] {
72
72
  */
73
73
  export function validateEnvironment(): IValidationResult {
74
74
  const result = envSchema.safeParse({
75
- OTA_SERVER: process.env.OTA_SERVER,
76
- OTA_API_KEY: process.env.OTA_API_KEY,
75
+ OTA_SERVER: process.env["OTA_SERVER"],
76
+ OTA_API_KEY: process.env["OTA_API_KEY"],
77
77
  });
78
78
 
79
79
  if (!result.success) {
@@ -89,15 +89,17 @@ export function validateEnvironment(): IValidationResult {
89
89
  /**
90
90
  * Validate a channel name using zod
91
91
  */
92
- export function validateChannel(channel: string | undefined): IValidationResult {
92
+ export function validateChannel(
93
+ channel: string | undefined
94
+ ): IValidationResult {
93
95
  if (!channel) {
94
96
  return {
95
97
  valid: false,
96
98
  errors: [
97
99
  `${chalk.red("--channel")} flag is required\n` +
98
- ` Specify which channel to deploy to:\n` +
99
- ` easc --channel production\n` +
100
- ` easc --channel staging`,
100
+ ` Specify which channel to deploy to:\n` +
101
+ ` easc --channel production\n` +
102
+ ` easc --channel staging`,
101
103
  ],
102
104
  };
103
105
  }
@@ -130,11 +132,11 @@ export function validateConfig(channel: string | undefined): IValidationResult {
130
132
  /**
131
133
  * Get configuration from environment and arguments
132
134
  */
133
- export function getConfig(channel: string): Config {
135
+ export function getConfig(channel: string): IConfig {
134
136
  return {
135
- otaServer: process.env.OTA_SERVER!,
136
- apiKey: process.env.OTA_API_KEY!,
137
137
  channel,
138
+ apiKey: process.env["OTA_API_KEY"]!,
139
+ otaServer: process.env["OTA_SERVER"]!,
138
140
  };
139
141
  }
140
142
 
@@ -148,4 +150,4 @@ export function validateServerUrl(url: string): boolean {
148
150
  } catch {
149
151
  return false;
150
152
  }
151
- }
153
+ }
@@ -1,19 +1,19 @@
1
1
  import fs from "fs";
2
- import { IAppJson } from "./runtime.ts";
3
- import { IMetadata } from "./files.ts";
4
- import { Config } from "./schema.ts";
5
- import { PlatformType } from "../enums/platform.ts";
2
+ import type { IAppJson } from "./runtime.ts";
3
+ import type { IMetadata } from "./files.ts";
4
+ import type { IConfig } from "./schema.ts";
5
+ import type { PlatformType } from "../enums/platform.ts";
6
6
 
7
7
  export interface IUploadOptions {
8
- platform: PlatformType;
8
+ config: IConfig;
9
9
  channel: string;
10
- runtimeVersion: string;
11
- commitHash?: string;
12
10
  bundlePath: string;
11
+ commitHash?: string | undefined;
12
+ metadata: IMetadata;
13
13
  assetPaths: string[];
14
+ platform: PlatformType;
15
+ runtimeVersion: string;
14
16
  expoConfig: IAppJson["expo"];
15
- metadata: IMetadata;
16
- config: Config;
17
17
  }
18
18
 
19
19
  /**
@@ -21,23 +21,23 @@ export interface IUploadOptions {
21
21
  */
22
22
  export async function uploadBundle(options: IUploadOptions): Promise<void> {
23
23
  const {
24
- platform,
24
+ config,
25
25
  channel,
26
- runtimeVersion,
26
+ platform,
27
+ metadata,
27
28
  commitHash,
28
29
  bundlePath,
29
30
  assetPaths,
30
31
  expoConfig,
31
- metadata,
32
- config,
32
+ runtimeVersion,
33
33
  } = options;
34
34
 
35
35
  const form = new FormData();
36
36
  form.append("channel", channel);
37
- form.append("runtimeVersion", runtimeVersion);
38
37
  form.append("platform", platform);
39
- form.append("expoConfig", JSON.stringify(expoConfig));
38
+ form.append("runtimeVersion", runtimeVersion);
40
39
  form.append("metadata", JSON.stringify(metadata));
40
+ form.append("expoConfig", JSON.stringify(expoConfig));
41
41
 
42
42
  if (commitHash) {
43
43
  form.append("commitHash", commitHash);
@@ -46,14 +46,20 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
46
46
  // Add bundle
47
47
  const bundleBuffer = fs.readFileSync(bundlePath);
48
48
  const bundleBlob = new Blob([bundleBuffer]);
49
- const bundleFileName = bundlePath.split("/").pop()!;
49
+ const bundleFileName = bundlePath.split("/").pop();
50
+ if (!bundleFileName) {
51
+ throw new Error(`Invalid bundle path: ${bundlePath}`);
52
+ }
50
53
  form.append("bundle", bundleBlob, bundleFileName);
51
54
 
52
55
  // Add assets
53
56
  assetPaths.forEach((assetPath, index) => {
54
57
  const assetBuffer = fs.readFileSync(assetPath);
55
58
  const assetBlob = new Blob([assetBuffer]);
56
- const assetFileName = assetPath.split("/").pop()!;
59
+ const assetFileName = assetPath.split("/").pop();
60
+ if (!assetFileName) {
61
+ throw new Error(`Invalid asset path: ${assetPath}`);
62
+ }
57
63
  form.append(`asset-${index}`, assetBlob, assetFileName);
58
64
  });
59
65
 
@@ -83,20 +89,20 @@ export async function uploadBundle(options: IUploadOptions): Promise<void> {
83
89
  * Create a dry run summary
84
90
  */
85
91
  export function createDryRunSummary(options: {
86
- platform: PlatformType;
92
+ channel: string;
87
93
  bundlePath: string;
94
+ commitHash?: string | undefined;
88
95
  assetPaths: string[];
89
- channel: string;
96
+ platform: PlatformType;
90
97
  runtimeVersion: string;
91
- commitHash?: string;
92
98
  }): string {
93
99
  const {
100
+ channel,
94
101
  platform,
95
102
  bundlePath,
96
103
  assetPaths,
97
- channel,
98
- runtimeVersion,
99
104
  commitHash,
105
+ runtimeVersion,
100
106
  } = options;
101
107
 
102
108
  const bundleSize = fs.statSync(bundlePath).size;