easc 0.0.13 → 0.0.15

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
@@ -51,6 +51,17 @@ easc build --clear-cache # Clean prebuild
51
51
  easc build --output ./build.ipa # Custom output path
52
52
  ```
53
53
 
54
+ ### build:run
55
+
56
+ Build locally and run on simulator/emulator. Always runs `expo prebuild --clean` before building.
57
+
58
+ ```bash
59
+ easc build:run --platform ios # Build and run on iOS Simulator
60
+ easc build:run --platform android # Build and run on Android Emulator
61
+ easc build:run --platform ios --profile preview # Use specific build profile
62
+ easc build:run --platform ios --path ./build.tar.gz # Run existing artifact (skip build)
63
+ ```
64
+
54
65
  ## Publishing
55
66
 
56
67
  To publish this package to npm:
package/index.ts CHANGED
@@ -2,12 +2,14 @@
2
2
  import yargs from "yargs";
3
3
  import { hideBin } from "yargs/helpers";
4
4
  import { build } from "./src/commands/build";
5
+ import { buildRun } from "./src/commands/build-run";
5
6
  import { update } from "./src/commands/update";
6
7
 
7
8
  yargs(hideBin(process.argv))
8
9
  .scriptName("easc")
9
10
  .usage("$0 <command> [options]")
10
11
  .command(build)
12
+ .command(buildRun)
11
13
  .command(update)
12
14
  .demandCommand(1, "")
13
15
  .showHelpOnFail(true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easc",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
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",
@@ -0,0 +1,178 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import chalk from "chalk";
4
+ import type { CommandModule } from "yargs";
5
+ import { Logger } from "../utils/logger";
6
+ import { Platform, PlatformType } from "../enums/platform";
7
+ import { runx } from "../utils/runx";
8
+
9
+ interface IArgs {
10
+ path?: string;
11
+ profile?: string;
12
+ platform: PlatformType | "all";
13
+ }
14
+
15
+ /**
16
+ * Get the artifact pattern for a platform.
17
+ * These patterns match EAS Build local output:
18
+ * - iOS simulator builds: .tar.gz (contains .app)
19
+ * - Android builds: .apk
20
+ */
21
+ function getArtifactPattern(platform: PlatformType): string {
22
+ return platform === Platform.iOS ? "build-*.tar.gz" : "build-*.apk";
23
+ }
24
+
25
+ /**
26
+ * Find the latest build artifact matching a pattern
27
+ */
28
+ function findLatestArtifact(pattern: string): string | null {
29
+ const cwd = process.cwd();
30
+ const files = fs.readdirSync(cwd).filter((f) => {
31
+ const regex = new RegExp(pattern.replace("*", ".*"));
32
+ return regex.test(f);
33
+ });
34
+
35
+ if (files.length === 0) return null;
36
+
37
+ return (
38
+ files
39
+ .map((f) => ({ name: f, mtime: fs.statSync(path.join(cwd, f)).mtime }))
40
+ .sort((a, b) => b.mtime.getTime() - a.mtime.getTime())[0]?.name ?? null
41
+ );
42
+ }
43
+
44
+ export const buildRun: CommandModule = {
45
+ command: "build:run",
46
+ describe: "Build locally and run on simulator/emulator",
47
+ builder: (yargs) =>
48
+ yargs
49
+ .option("platform", {
50
+ alias: "p",
51
+ type: "string",
52
+ choices: [Platform.iOS, Platform.Android, "all"] as const,
53
+ description: "Target platform",
54
+ demandOption: true,
55
+ })
56
+ .option("profile", {
57
+ alias: "e",
58
+ type: "string",
59
+ description:
60
+ 'Name of the build profile from eas.json. Defaults to "production" if defined in eas.json.',
61
+ })
62
+ .option("path", {
63
+ type: "string",
64
+ description:
65
+ "Path to the simulator/emulator build archive or app (skips build)",
66
+ })
67
+ .example(
68
+ "$0 build:run -p ios -e preview",
69
+ "Build with preview profile and run on iOS Simulator",
70
+ )
71
+ .example(
72
+ "$0 build:run -p android",
73
+ "Build with default profile and run on Android Emulator",
74
+ )
75
+ .example(
76
+ "$0 build:run -p ios --path ./build.tar.gz",
77
+ "Run existing build artifact",
78
+ ),
79
+ async handler(argv) {
80
+ const args = argv as unknown as IArgs;
81
+ const logger = new Logger();
82
+
83
+ try {
84
+ const platforms: PlatformType[] =
85
+ args.platform === "all"
86
+ ? [Platform.iOS, Platform.Android]
87
+ : [args.platform];
88
+
89
+ for (const platform of platforms) {
90
+ const platformName = platform === Platform.iOS ? "iOS" : "Android";
91
+ const artifactPattern = getArtifactPattern(platform);
92
+
93
+ logger.section(`${platformName} Build & Run`);
94
+
95
+ let artifactPath: string | null = null;
96
+ let didBuild = false;
97
+
98
+ // Determine artifact path
99
+ if (args.path) {
100
+ // Use explicitly provided path
101
+ artifactPath = args.path;
102
+ if (!fs.existsSync(artifactPath)) {
103
+ logger.error(`Artifact not found: ${artifactPath}`);
104
+ process.exit(1);
105
+ }
106
+ logger.info(`Using provided artifact: ${artifactPath}`);
107
+ }
108
+
109
+ // Build if no artifact specified
110
+ if (!artifactPath) {
111
+ didBuild = true;
112
+
113
+ // Always run clean prebuild before building
114
+ logger.startSpinner(`Running prebuild for ${platformName}...`);
115
+ runx(`expo prebuild --platform ${platform} --clean`, {
116
+ cwd: process.cwd(),
117
+ stdio: "ignore",
118
+ env: { ...process.env, CI: "1" },
119
+ });
120
+ logger.succeedSpinner("Prebuild completed");
121
+
122
+ logger.startSpinner(`Building ${platformName} locally...`);
123
+
124
+ const buildFlags = [
125
+ `--platform ${platform}`,
126
+ args.profile ? `--profile ${args.profile}` : "",
127
+ "--local",
128
+ "--non-interactive",
129
+ ]
130
+ .filter(Boolean)
131
+ .join(" ");
132
+
133
+ runx(`eas build ${buildFlags}`, {
134
+ cwd: process.cwd(),
135
+ stdio: "inherit",
136
+ });
137
+
138
+ logger.succeedSpinner(`${platformName} build completed`);
139
+
140
+ // Find the newly created artifact
141
+ artifactPath = findLatestArtifact(artifactPattern);
142
+
143
+ if (!artifactPath) {
144
+ logger.error(`No build artifact found after build`);
145
+ process.exit(1);
146
+ }
147
+
148
+ logger.info(`Build artifact: ${artifactPath}`);
149
+ }
150
+
151
+ // Run the artifact on simulator/emulator
152
+ logger.startSpinner(
153
+ `Installing on ${platformName} simulator/emulator...`,
154
+ );
155
+
156
+ runx(`eas build:run --path "${artifactPath}" --platform ${platform}`, {
157
+ cwd: process.cwd(),
158
+ stdio: "inherit",
159
+ });
160
+
161
+ logger.succeedSpinner(`${platformName} app installed and running`);
162
+
163
+ // Clean up artifact only if we built it (not if user provided --path)
164
+ if (didBuild && artifactPath && fs.existsSync(artifactPath)) {
165
+ fs.unlinkSync(artifactPath);
166
+ logger.info(`Cleaned up: ${artifactPath}`);
167
+ }
168
+ }
169
+
170
+ logger.section("");
171
+ logger.success("Done! App is running on simulator/emulator.");
172
+ } catch (error) {
173
+ const message = error instanceof Error ? error.message : String(error);
174
+ console.error(chalk.red(`Build:run failed: ${message}`));
175
+ process.exit(1);
176
+ }
177
+ },
178
+ };