easc 0.0.17 → 0.0.20
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/index.ts +2 -3
- package/package.json +11 -11
- package/src/commands/build-run.ts +67 -67
- package/src/commands/build.ts +9 -3
- package/src/commands/update.ts +11 -40
- package/src/utils/cli.ts +187 -0
- package/src/utils/eas.ts +32 -0
package/index.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import yargs from "yargs";
|
|
3
2
|
import { hideBin } from "yargs/helpers";
|
|
3
|
+
import { cli } from "./src/utils/cli";
|
|
4
4
|
import { build } from "./src/commands/build";
|
|
5
5
|
import { buildRun } from "./src/commands/build-run";
|
|
6
6
|
import { update } from "./src/commands/update";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
cli(hideBin(process.argv))
|
|
9
9
|
.scriptName("easc")
|
|
10
10
|
.usage("$0 <command> [options]")
|
|
11
11
|
.command(build)
|
|
12
12
|
.command(buildRun)
|
|
13
13
|
.command(update)
|
|
14
14
|
.demandCommand(1, "")
|
|
15
|
-
.showHelpOnFail(true)
|
|
16
15
|
.help()
|
|
17
16
|
.alias("help", "h")
|
|
18
17
|
.alias("version", "V")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
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",
|
|
@@ -12,15 +12,8 @@
|
|
|
12
12
|
"index.ts",
|
|
13
13
|
"src"
|
|
14
14
|
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"test": "vitest",
|
|
17
|
-
"test:watch": "vitest --watch",
|
|
18
|
-
"test:ui": "vitest --ui",
|
|
19
|
-
"test:coverage": "vitest --coverage",
|
|
20
|
-
"typecheck": "tsgo --noEmit",
|
|
21
|
-
"prepublishOnly": "pnpm run test"
|
|
22
|
-
},
|
|
23
15
|
"dependencies": {
|
|
16
|
+
"@inquirer/prompts": "^7.8.6",
|
|
24
17
|
"chalk": "5.6.0",
|
|
25
18
|
"ora": "^9.0.0",
|
|
26
19
|
"tsx": "^4.20.6",
|
|
@@ -30,8 +23,8 @@
|
|
|
30
23
|
"devDependencies": {
|
|
31
24
|
"@types/node": "^24.8.0",
|
|
32
25
|
"@types/yargs": "^17.0.33",
|
|
33
|
-
"@vitest/ui": "^3.0.0",
|
|
34
26
|
"@typescript/native-preview": "^7.0.0-dev.20250601",
|
|
27
|
+
"@vitest/ui": "^3.0.0",
|
|
35
28
|
"vitest": "^3.2.4"
|
|
36
29
|
},
|
|
37
30
|
"engines": {
|
|
@@ -52,5 +45,12 @@
|
|
|
52
45
|
],
|
|
53
46
|
"publishConfig": {
|
|
54
47
|
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"test": "vitest",
|
|
51
|
+
"test:watch": "vitest --watch",
|
|
52
|
+
"test:ui": "vitest --ui",
|
|
53
|
+
"test:coverage": "vitest --coverage",
|
|
54
|
+
"typecheck": "tsgo --noEmit"
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
}
|
|
@@ -5,11 +5,13 @@ import type { CommandModule } from "yargs";
|
|
|
5
5
|
import { Logger } from "../utils/logger";
|
|
6
6
|
import { Platform, PlatformType } from "../enums/platform";
|
|
7
7
|
import { runx } from "../utils/runx";
|
|
8
|
+
import { getEasProfiles } from "../utils/eas";
|
|
8
9
|
|
|
9
10
|
interface IArgs {
|
|
10
11
|
path?: string;
|
|
11
|
-
profile
|
|
12
|
-
platform: PlatformType
|
|
12
|
+
profile: string;
|
|
13
|
+
platform: PlatformType;
|
|
14
|
+
nonInteractive: boolean;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -49,21 +51,25 @@ export const buildRun: CommandModule = {
|
|
|
49
51
|
.option("platform", {
|
|
50
52
|
alias: "p",
|
|
51
53
|
type: "string",
|
|
52
|
-
choices: [Platform.iOS, Platform.Android
|
|
54
|
+
choices: [Platform.iOS, Platform.Android] as const,
|
|
53
55
|
description: "Target platform",
|
|
54
|
-
demandOption: true,
|
|
55
56
|
})
|
|
56
57
|
.option("profile", {
|
|
57
58
|
alias: "e",
|
|
58
59
|
type: "string",
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
choices: getEasProfiles(),
|
|
61
|
+
description: "EAS build profile",
|
|
61
62
|
})
|
|
62
63
|
.option("path", {
|
|
63
64
|
type: "string",
|
|
64
65
|
description:
|
|
65
66
|
"Path to the simulator/emulator build archive or app (skips build)",
|
|
66
67
|
})
|
|
68
|
+
.option("non-interactive", {
|
|
69
|
+
type: "boolean",
|
|
70
|
+
description: "Never prompt for user input",
|
|
71
|
+
default: false,
|
|
72
|
+
})
|
|
67
73
|
.example(
|
|
68
74
|
"$0 build:run -p ios -e preview",
|
|
69
75
|
"Build with preview profile and run on iOS Simulator",
|
|
@@ -81,82 +87,76 @@ export const buildRun: CommandModule = {
|
|
|
81
87
|
const logger = new Logger();
|
|
82
88
|
|
|
83
89
|
try {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
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}...`);
|
|
90
|
+
const platform = args.platform;
|
|
91
|
+
const platformName = platform === Platform.iOS ? "iOS" : "Android";
|
|
92
|
+
const artifactPattern = getArtifactPattern(platform);
|
|
111
93
|
|
|
112
|
-
|
|
113
|
-
cwd: process.cwd(),
|
|
114
|
-
stdio: "inherit",
|
|
115
|
-
env: { ...process.env, CI: "1" },
|
|
116
|
-
});
|
|
94
|
+
logger.section(`${platformName} Build & Run`);
|
|
117
95
|
|
|
118
|
-
|
|
119
|
-
|
|
96
|
+
let artifactPath: string | null = null;
|
|
97
|
+
let didBuild = false;
|
|
120
98
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
runx(`eas build ${buildFlags}`, {
|
|
131
|
-
cwd: process.cwd(),
|
|
132
|
-
stdio: "inherit",
|
|
133
|
-
});
|
|
99
|
+
if (args.path) {
|
|
100
|
+
artifactPath = args.path;
|
|
101
|
+
if (!fs.existsSync(artifactPath)) {
|
|
102
|
+
logger.error(`Artifact not found: ${artifactPath}`);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
logger.info(`Using provided artifact: ${artifactPath}`);
|
|
106
|
+
}
|
|
134
107
|
|
|
135
|
-
|
|
108
|
+
if (!artifactPath) {
|
|
109
|
+
didBuild = true;
|
|
136
110
|
|
|
137
|
-
|
|
111
|
+
logger.info(`Running prebuild for ${platformName}...`);
|
|
138
112
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
113
|
+
runx(`expo prebuild --platform ${platform} --clean`, {
|
|
114
|
+
cwd: process.cwd(),
|
|
115
|
+
stdio: "inherit",
|
|
116
|
+
env: { ...process.env, CI: "1" },
|
|
117
|
+
});
|
|
143
118
|
|
|
144
|
-
|
|
145
|
-
}
|
|
119
|
+
logger.success("Prebuild completed");
|
|
120
|
+
logger.info(`Building ${platformName} locally...`);
|
|
146
121
|
|
|
147
|
-
|
|
122
|
+
const buildFlags = [
|
|
123
|
+
`--platform ${platform}`,
|
|
124
|
+
`--profile ${args.profile}`,
|
|
125
|
+
"--local",
|
|
126
|
+
"--non-interactive",
|
|
127
|
+
]
|
|
128
|
+
.filter(Boolean)
|
|
129
|
+
.join(" ");
|
|
148
130
|
|
|
149
|
-
runx(`eas build
|
|
131
|
+
runx(`eas build ${buildFlags}`, {
|
|
150
132
|
cwd: process.cwd(),
|
|
151
133
|
stdio: "inherit",
|
|
152
134
|
});
|
|
153
135
|
|
|
154
|
-
logger.success(`${platformName}
|
|
136
|
+
logger.success(`${platformName} build completed`);
|
|
137
|
+
|
|
138
|
+
artifactPath = findLatestArtifact(artifactPattern);
|
|
155
139
|
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
140
|
+
if (!artifactPath) {
|
|
141
|
+
logger.error(`No build artifact found after build`);
|
|
142
|
+
process.exit(1);
|
|
159
143
|
}
|
|
144
|
+
|
|
145
|
+
logger.info(`Build artifact: ${artifactPath}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
logger.info(`Installing on ${platformName} simulator/emulator...`);
|
|
149
|
+
|
|
150
|
+
runx(`eas build:run --path "${artifactPath}" --platform ${platform}`, {
|
|
151
|
+
cwd: process.cwd(),
|
|
152
|
+
stdio: "inherit",
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
logger.success(`${platformName} app installed and running`);
|
|
156
|
+
|
|
157
|
+
if (didBuild && artifactPath && fs.existsSync(artifactPath)) {
|
|
158
|
+
fs.unlinkSync(artifactPath);
|
|
159
|
+
logger.info(`Cleaned up: ${artifactPath}`);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
logger.section("");
|
package/src/commands/build.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { CommandModule } from "yargs";
|
|
|
5
5
|
import { Logger } from "../utils/logger";
|
|
6
6
|
import { Platform, PlatformType } from "../enums/platform";
|
|
7
7
|
import { runx } from "../utils/runx";
|
|
8
|
+
import { getEasProfiles } from "../utils/eas";
|
|
8
9
|
|
|
9
10
|
interface IArgs {
|
|
10
11
|
platform: PlatformType | "all";
|
|
@@ -12,6 +13,7 @@ interface IArgs {
|
|
|
12
13
|
autoSubmit: boolean;
|
|
13
14
|
clearCache: boolean;
|
|
14
15
|
output?: string;
|
|
16
|
+
nonInteractive: boolean;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
function findBuildArtifact(pattern: string): string | null {
|
|
@@ -40,13 +42,12 @@ export const build: CommandModule = {
|
|
|
40
42
|
type: "string",
|
|
41
43
|
choices: [Platform.iOS, Platform.Android, "all"] as const,
|
|
42
44
|
description: "Target platform",
|
|
43
|
-
default: "all",
|
|
44
45
|
})
|
|
45
46
|
.option("profile", {
|
|
46
47
|
alias: "e",
|
|
47
48
|
type: "string",
|
|
49
|
+
choices: getEasProfiles(),
|
|
48
50
|
description: "EAS build profile",
|
|
49
|
-
default: "production",
|
|
50
51
|
})
|
|
51
52
|
.option("auto-submit", {
|
|
52
53
|
alias: "s",
|
|
@@ -63,6 +64,11 @@ export const build: CommandModule = {
|
|
|
63
64
|
type: "string",
|
|
64
65
|
description: "Output path for the build artifact",
|
|
65
66
|
})
|
|
67
|
+
.option("non-interactive", {
|
|
68
|
+
type: "boolean",
|
|
69
|
+
description: "Never prompt for user input",
|
|
70
|
+
default: false,
|
|
71
|
+
})
|
|
66
72
|
.example("$0 build", "Build all platforms locally")
|
|
67
73
|
.example("$0 build -p ios -e development", "Build iOS with dev profile")
|
|
68
74
|
.example("$0 build -s", "Build and submit to stores"),
|
|
@@ -129,7 +135,7 @@ export const build: CommandModule = {
|
|
|
129
135
|
|
|
130
136
|
runx(
|
|
131
137
|
`eas submit --platform ${platform} --path "${artifactPath}" --non-interactive`,
|
|
132
|
-
{ cwd: process.cwd(), stdio: "inherit" }
|
|
138
|
+
{ cwd: process.cwd(), stdio: "inherit" },
|
|
133
139
|
);
|
|
134
140
|
|
|
135
141
|
logger.success(`${platformName} submitted`);
|
package/src/commands/update.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
-
import chalk from "chalk";
|
|
3
2
|
import type { CommandModule } from "yargs";
|
|
4
3
|
import { validateConfig, getConfig } from "../utils/schema";
|
|
5
4
|
import { resolveRuntimeVersion, getPlatforms } from "../utils/runtime";
|
|
@@ -17,22 +16,11 @@ import { PlatformType } from "../enums/platform";
|
|
|
17
16
|
import { runx } from "../utils/runx";
|
|
18
17
|
|
|
19
18
|
interface IArgs {
|
|
20
|
-
channel
|
|
19
|
+
channel: string;
|
|
21
20
|
skipBuild: boolean;
|
|
22
21
|
dryRun: boolean;
|
|
23
|
-
environment?: "development" | "preview" | "production";
|
|
24
22
|
exportDir: string;
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function mapEnvironmentToChannel(
|
|
29
|
-
environment?: string,
|
|
30
|
-
isShorthandProd?: boolean
|
|
31
|
-
): string | undefined {
|
|
32
|
-
if (environment === "production" || isShorthandProd) return "production";
|
|
33
|
-
if (environment === "preview") return "staging";
|
|
34
|
-
if (environment === "development") return "dev";
|
|
35
|
-
return undefined;
|
|
23
|
+
nonInteractive: boolean;
|
|
36
24
|
}
|
|
37
25
|
|
|
38
26
|
export const update: CommandModule = {
|
|
@@ -43,7 +31,8 @@ export const update: CommandModule = {
|
|
|
43
31
|
.option("channel", {
|
|
44
32
|
alias: "c",
|
|
45
33
|
type: "string",
|
|
46
|
-
|
|
34
|
+
choices: ["production", "staging", "dev"],
|
|
35
|
+
description: "Deployment channel",
|
|
47
36
|
})
|
|
48
37
|
.option("skip-build", {
|
|
49
38
|
type: "boolean",
|
|
@@ -55,41 +44,23 @@ export const update: CommandModule = {
|
|
|
55
44
|
description: "Outputs deployment info instead of uploading",
|
|
56
45
|
default: false,
|
|
57
46
|
})
|
|
58
|
-
.option("environment", {
|
|
59
|
-
type: "string",
|
|
60
|
-
choices: ["development", "preview", "production"] as const,
|
|
61
|
-
description: "Environment variable's environment",
|
|
62
|
-
})
|
|
63
47
|
.option("export-dir", {
|
|
64
48
|
type: "string",
|
|
65
49
|
description: "Directory where the Expo project was exported",
|
|
66
50
|
default: "dist",
|
|
67
51
|
})
|
|
68
|
-
.option("
|
|
52
|
+
.option("non-interactive", {
|
|
69
53
|
type: "boolean",
|
|
70
|
-
description: "
|
|
54
|
+
description: "Never prompt for user input",
|
|
71
55
|
default: false,
|
|
72
56
|
})
|
|
73
57
|
.example("$0 update --channel production", "Deploy to production")
|
|
74
|
-
.example("$0 update --prod", "Deploy to production (EAS-style)")
|
|
75
58
|
.example("$0 update -c staging --skip-build", "Deploy existing build"),
|
|
76
59
|
async handler(argv) {
|
|
77
60
|
const args = argv as unknown as IArgs;
|
|
78
61
|
const logger = new Logger();
|
|
79
62
|
|
|
80
|
-
|
|
81
|
-
if (!channel) {
|
|
82
|
-
channel = mapEnvironmentToChannel(args.environment, args.prod);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!channel) {
|
|
86
|
-
console.error(chalk.red("Error: Channel is required"));
|
|
87
|
-
console.log("Use one of the following:");
|
|
88
|
-
console.log(" easc update --channel production");
|
|
89
|
-
console.log(" easc update --prod");
|
|
90
|
-
console.log(" easc update --environment production");
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
63
|
+
const channel = args.channel;
|
|
93
64
|
|
|
94
65
|
const validation = validateConfig(channel);
|
|
95
66
|
if (!validation.valid) {
|
|
@@ -110,13 +81,13 @@ export const update: CommandModule = {
|
|
|
110
81
|
args.exportDir !== "dist"
|
|
111
82
|
? `expo export --output-dir ${args.exportDir}`
|
|
112
83
|
: `expo export`,
|
|
113
|
-
{ cwd: process.cwd(), stdio: "inherit" }
|
|
84
|
+
{ cwd: process.cwd(), stdio: "inherit" },
|
|
114
85
|
);
|
|
115
86
|
|
|
116
87
|
logger.success("Build completed");
|
|
117
88
|
} else {
|
|
118
89
|
logger.info(
|
|
119
|
-
`Skipping build (using existing export from ${args.exportDir})
|
|
90
|
+
`Skipping build (using existing export from ${args.exportDir})`,
|
|
120
91
|
);
|
|
121
92
|
}
|
|
122
93
|
|
|
@@ -128,7 +99,7 @@ export const update: CommandModule = {
|
|
|
128
99
|
const commitHash = getCommitHash();
|
|
129
100
|
const shortCommit = getShortCommitHash();
|
|
130
101
|
|
|
131
|
-
logger.section("
|
|
102
|
+
logger.section("Deployment Info");
|
|
132
103
|
logger.table([
|
|
133
104
|
["Server", config.otaServer],
|
|
134
105
|
["Runtime", runtimeVersion],
|
|
@@ -213,7 +184,7 @@ export const update: CommandModule = {
|
|
|
213
184
|
logger.success("Dry run completed successfully!");
|
|
214
185
|
logger.info("Run without --dry-run to perform actual upload");
|
|
215
186
|
} else {
|
|
216
|
-
logger.success("
|
|
187
|
+
logger.success("Updates published successfully!");
|
|
217
188
|
}
|
|
218
189
|
},
|
|
219
190
|
};
|
package/src/utils/cli.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import yargs, { type Argv, type CommandModule, type Options } from "yargs";
|
|
2
|
+
import { select } from "@inquirer/prompts";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
|
|
5
|
+
interface CommandInfo {
|
|
6
|
+
command: string;
|
|
7
|
+
describe: string;
|
|
8
|
+
options: Record<string, Options>;
|
|
9
|
+
handler: (argv: any) => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class InteractiveCLI {
|
|
13
|
+
private args: string[];
|
|
14
|
+
private commands: CommandInfo[] = [];
|
|
15
|
+
private yargsInstance: Argv;
|
|
16
|
+
|
|
17
|
+
constructor(args: string[]) {
|
|
18
|
+
this.args = args;
|
|
19
|
+
this.yargsInstance = yargs(args);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private showWelcome() {
|
|
23
|
+
console.clear();
|
|
24
|
+
console.log();
|
|
25
|
+
console.log(chalk.cyan(" ___ __ _ ___ ___ "));
|
|
26
|
+
console.log(chalk.cyan(" / _ \\/ _` / __|/ __|"));
|
|
27
|
+
console.log(chalk.blue("| __/ (_| \\__ \\ (__ "));
|
|
28
|
+
console.log(chalk.blue(" \\___|\\__,_|___/\\___|"));
|
|
29
|
+
console.log();
|
|
30
|
+
console.log(chalk.gray(" Expo App Services for Cloudflare"));
|
|
31
|
+
console.log(chalk.yellow("════════════════════════════════════"));
|
|
32
|
+
console.log();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private async promptForMissingArgs(
|
|
36
|
+
argv: any,
|
|
37
|
+
options: Record<string, Options>,
|
|
38
|
+
) {
|
|
39
|
+
if (argv.nonInteractive || argv["non-interactive"]) return;
|
|
40
|
+
|
|
41
|
+
for (const [key, opt] of Object.entries(options)) {
|
|
42
|
+
const camelKey = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
43
|
+
const value = argv[key] ?? argv[camelKey];
|
|
44
|
+
|
|
45
|
+
if (value !== undefined) continue;
|
|
46
|
+
if (opt.default !== undefined) continue;
|
|
47
|
+
if (!opt.choices || !Array.isArray(opt.choices)) continue;
|
|
48
|
+
|
|
49
|
+
argv[key] = await select({
|
|
50
|
+
message: `Select ${key.replace(/-/g, " ")}:`,
|
|
51
|
+
choices: opt.choices.map((c: string) => ({ name: c, value: c })),
|
|
52
|
+
});
|
|
53
|
+
argv[camelKey] = argv[key];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
scriptName(name: string): this {
|
|
58
|
+
this.yargsInstance.scriptName(name);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
usage(message: string): this {
|
|
63
|
+
this.yargsInstance.usage(message);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
command(cmd: CommandModule): this {
|
|
68
|
+
const commandStr = typeof cmd.command === "string"
|
|
69
|
+
? cmd.command
|
|
70
|
+
: cmd.command?.[0] ?? "";
|
|
71
|
+
const commandName = commandStr.split(" ")[0] || "";
|
|
72
|
+
|
|
73
|
+
let options: Record<string, Options> = {};
|
|
74
|
+
|
|
75
|
+
if (typeof cmd.builder === "function") {
|
|
76
|
+
const fakeYargs = {
|
|
77
|
+
option: (key: string, opt: Options) => {
|
|
78
|
+
options[key] = opt;
|
|
79
|
+
return fakeYargs;
|
|
80
|
+
},
|
|
81
|
+
example: () => fakeYargs,
|
|
82
|
+
positional: () => fakeYargs,
|
|
83
|
+
demandOption: () => fakeYargs,
|
|
84
|
+
choices: () => fakeYargs,
|
|
85
|
+
};
|
|
86
|
+
cmd.builder(fakeYargs as any);
|
|
87
|
+
} else if (cmd.builder) {
|
|
88
|
+
options = cmd.builder as Record<string, Options>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.commands.push({
|
|
92
|
+
command: commandName,
|
|
93
|
+
describe: (cmd.describe as string) ?? "",
|
|
94
|
+
options,
|
|
95
|
+
handler: cmd.handler as (argv: any) => void | Promise<void>,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const wrappedCmd: CommandModule = {
|
|
99
|
+
...cmd,
|
|
100
|
+
handler: async (argv: any) => {
|
|
101
|
+
await this.promptForMissingArgs(argv, options);
|
|
102
|
+
return cmd.handler(argv);
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
this.yargsInstance.command(wrappedCmd);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
demandCommand(_min: number, _message?: string): this {
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
help(): this {
|
|
115
|
+
this.yargsInstance.help();
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
alias(key: string, alias: string): this {
|
|
120
|
+
this.yargsInstance.alias(key, alias);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
strict(): this {
|
|
125
|
+
this.yargsInstance.strict();
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
showHelpOnFail(enabled: boolean): this {
|
|
130
|
+
this.yargsInstance.showHelpOnFail(enabled);
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async parse(): Promise<void> {
|
|
135
|
+
const needsCommandPrompt = this.args.length === 0 ||
|
|
136
|
+
(this.args.length === 1 && this.args[0]?.startsWith("-"));
|
|
137
|
+
|
|
138
|
+
if (!needsCommandPrompt) {
|
|
139
|
+
this.yargsInstance.demandCommand(1, "").parse();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.showWelcome();
|
|
144
|
+
|
|
145
|
+
const command = await select({
|
|
146
|
+
message: "Select a command:",
|
|
147
|
+
choices: [
|
|
148
|
+
...this.commands.map((cmd) => ({
|
|
149
|
+
name: `${cmd.command.padEnd(12)} ${cmd.describe}`,
|
|
150
|
+
value: cmd.command,
|
|
151
|
+
})),
|
|
152
|
+
{ name: "Exit", value: "exit" },
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if (command === "exit") {
|
|
157
|
+
console.log("Goodbye!");
|
|
158
|
+
process.exit(0);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this.args.unshift(command);
|
|
162
|
+
this.yargsInstance = yargs(this.args);
|
|
163
|
+
|
|
164
|
+
for (const cmd of this.commands) {
|
|
165
|
+
this.yargsInstance.command({
|
|
166
|
+
command: cmd.command,
|
|
167
|
+
describe: cmd.describe,
|
|
168
|
+
builder: (y) => {
|
|
169
|
+
for (const [key, opt] of Object.entries(cmd.options)) {
|
|
170
|
+
y.option(key, opt);
|
|
171
|
+
}
|
|
172
|
+
return y;
|
|
173
|
+
},
|
|
174
|
+
handler: async (argv: any) => {
|
|
175
|
+
await this.promptForMissingArgs(argv, cmd.options);
|
|
176
|
+
return cmd.handler(argv);
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.yargsInstance.demandCommand(1, "").parse();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function cli(args: string[]): InteractiveCLI {
|
|
186
|
+
return new InteractiveCLI(args);
|
|
187
|
+
}
|
package/src/utils/eas.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
interface EasConfig {
|
|
5
|
+
build?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getEasProfiles(): string[] {
|
|
9
|
+
const easJsonPath = path.join(process.cwd(), "eas.json");
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync(easJsonPath)) {
|
|
12
|
+
throw new Error("eas.json not found. Run 'eas build:configure' to create one.");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let easConfig: EasConfig;
|
|
16
|
+
try {
|
|
17
|
+
easConfig = JSON.parse(fs.readFileSync(easJsonPath, "utf-8"));
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new Error(`Failed to parse eas.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!easConfig.build || typeof easConfig.build !== "object") {
|
|
23
|
+
throw new Error("No build profiles found in eas.json");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const profiles = Object.keys(easConfig.build);
|
|
27
|
+
if (profiles.length === 0) {
|
|
28
|
+
throw new Error("No build profiles found in eas.json");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return profiles;
|
|
32
|
+
}
|