easc 0.0.14 → 0.0.16
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 +11 -0
- package/index.ts +2 -0
- package/package.json +1 -1
- package/src/commands/build-run.ts +170 -0
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
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
if (args.path) {
|
|
99
|
+
artifactPath = args.path;
|
|
100
|
+
if (!fs.existsSync(artifactPath)) {
|
|
101
|
+
logger.error(`Artifact not found: ${artifactPath}`);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
logger.info(`Using provided artifact: ${artifactPath}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!artifactPath) {
|
|
108
|
+
didBuild = true;
|
|
109
|
+
|
|
110
|
+
logger.info(`Running prebuild for ${platformName}...`);
|
|
111
|
+
|
|
112
|
+
runx(`expo prebuild --platform ${platform} --clean`, {
|
|
113
|
+
cwd: process.cwd(),
|
|
114
|
+
stdio: "inherit",
|
|
115
|
+
env: { ...process.env, CI: "1" },
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
logger.success("Prebuild completed");
|
|
119
|
+
logger.info(`Building ${platformName} locally...`);
|
|
120
|
+
|
|
121
|
+
const buildFlags = [
|
|
122
|
+
`--platform ${platform}`,
|
|
123
|
+
args.profile ? `--profile ${args.profile}` : "",
|
|
124
|
+
"--local",
|
|
125
|
+
"--non-interactive",
|
|
126
|
+
]
|
|
127
|
+
.filter(Boolean)
|
|
128
|
+
.join(" ");
|
|
129
|
+
|
|
130
|
+
runx(`eas build ${buildFlags}`, {
|
|
131
|
+
cwd: process.cwd(),
|
|
132
|
+
stdio: "inherit",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
logger.success(`${platformName} build completed`);
|
|
136
|
+
|
|
137
|
+
artifactPath = findLatestArtifact(artifactPattern);
|
|
138
|
+
|
|
139
|
+
if (!artifactPath) {
|
|
140
|
+
logger.error(`No build artifact found after build`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
logger.info(`Build artifact: ${artifactPath}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
logger.info(`Installing on ${platformName} simulator/emulator...`);
|
|
148
|
+
|
|
149
|
+
runx(`eas build:run --path "${artifactPath}" --platform ${platform}`, {
|
|
150
|
+
cwd: process.cwd(),
|
|
151
|
+
stdio: "inherit",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
logger.success(`${platformName} app installed and running`);
|
|
155
|
+
|
|
156
|
+
if (didBuild && artifactPath && fs.existsSync(artifactPath)) {
|
|
157
|
+
fs.unlinkSync(artifactPath);
|
|
158
|
+
logger.info(`Cleaned up: ${artifactPath}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
logger.section("");
|
|
163
|
+
logger.success("Done! App is running on simulator/emulator.");
|
|
164
|
+
} catch (error) {
|
|
165
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
166
|
+
console.error(chalk.red(`Build:run failed: ${message}`));
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
};
|