Skip to content

Commit 6c4af74

Browse files
abueideclaude
andauthored
feat(rn): route plugin.json scripts through segkit and add metro subcommand (#61)
Replace direct shell script calls in the React Native plugin's convenience scripts with segkit delegation. Adds `segkit metro` subcommand for metro.sh delegation. Fixes delegate.rs to use REACT_NATIVE_SCRIPTS_DIR instead of non-existent RN_SCRIPTS_DIR. Scripts updated: start:metro, stop:metro, start:android, start:ios, rn:metro:port, rn:metro:clean. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 049be1c commit 6c4af74

4 files changed

Lines changed: 37 additions & 17 deletions

File tree

plugins/react-native/plugin.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@
5151
"bash {{ .Virtenv }}/scripts/user/setup.sh"
5252
],
5353
"start:metro": [
54-
"metro.sh start ${1:-default}"
54+
"segkit metro start ${1:-default}"
5555
],
5656
"stop:metro": [
57-
"metro.sh stop ${1:-default}"
57+
"segkit metro stop ${1:-default}"
5858
],
5959
"start:android": [
60-
"android.sh run \"${1:-}\""
60+
"segkit android run \"${1:-}\""
6161
],
6262
"start:ios": [
63-
"ios.sh run \"${1:-}\""
63+
"segkit ios run \"${1:-}\""
6464
],
6565
"rn:metro:port": [
66-
"rn.sh metro port ${1:-default}"
66+
"segkit rn metro port ${1:-default}"
6767
],
6868
"rn:metro:clean": [
69-
"rn.sh metro clean ${1:-default}"
69+
"segkit rn metro clean ${1:-default}"
7070
],
7171
"doctor": [
7272
"bash {{ .Virtenv }}/scripts/user/doctor.sh"

segkit/src/delegate.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,27 @@ fn resolve_script(name: &str) -> Result<String> {
1515
"invalid script name: {name}"
1616
);
1717

18-
let platform = if name.starts_with("android") {
19-
"ANDROID"
18+
let env_keys: &[&str] = if name.starts_with("android") {
19+
&["ANDROID_SCRIPTS_DIR"]
2020
} else if name.starts_with("ios") {
21-
"IOS"
21+
&["IOS_SCRIPTS_DIR"]
2222
} else {
23-
"RN"
23+
&["REACT_NATIVE_SCRIPTS_DIR"]
2424
};
2525

26-
let env_key = format!("{}_SCRIPTS_DIR", platform);
27-
if let Ok(scripts_dir) = std::env::var(&env_key) {
28-
let path = format!("{}/user/{}", scripts_dir, name);
29-
if std::path::Path::new(&path).exists() {
30-
return Ok(path);
26+
for env_key in env_keys {
27+
if let Ok(scripts_dir) = std::env::var(env_key) {
28+
let path = format!("{}/user/{}", scripts_dir, name);
29+
if std::path::Path::new(&path).exists() {
30+
return Ok(path);
31+
}
3132
}
3233
}
3334

35+
let primary_key = env_keys[0];
3436
which::which(name)
3537
.map(|p| p.to_string_lossy().into_owned())
36-
.with_context(|| format!("{name} not found in PATH or ${env_key}"))
38+
.with_context(|| format!("{name} not found in PATH or ${primary_key}"))
3739
}
3840

3941
fn append_timing(script: &str, args: &[String], duration_ms: u128, exit_code: i32) {

segkit/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ enum Commands {
2929
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
3030
args: Vec<String>,
3131
},
32+
/// Metro bundler commands (delegates to metro.sh)
33+
Metro {
34+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
35+
args: Vec<String>,
36+
},
3237
/// Check and install required dependencies (devbox)
3338
Setup,
3439
}
@@ -40,6 +45,7 @@ fn main() -> ExitCode {
4045
Some(Commands::Android { args }) => delegate::run("android.sh", &args),
4146
Some(Commands::Ios { args }) => delegate::run("ios.sh", &args),
4247
Some(Commands::Rn { args }) => delegate::run("rn.sh", &args),
48+
Some(Commands::Metro { args }) => delegate::run("metro.sh", &args),
4349
Some(Commands::Setup) => setup::run(),
4450
None => {
4551
println!("segkit {}", env!("CARGO_PKG_VERSION"));

segkit/tests/cli.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn help_flag() {
2323
.stdout(predicate::str::contains("android"))
2424
.stdout(predicate::str::contains("ios"))
2525
.stdout(predicate::str::contains("rn"))
26+
.stdout(predicate::str::contains("metro"))
2627
.stdout(predicate::str::contains("setup"));
2728
}
2829

@@ -61,13 +62,24 @@ fn ios_subcommand_without_script_fails_gracefully() {
6162
fn rn_subcommand_without_script_fails_gracefully() {
6263
segkit()
6364
.args(["rn", "doctor"])
64-
.env_remove("RN_SCRIPTS_DIR")
65+
.env_remove("REACT_NATIVE_SCRIPTS_DIR")
6566
.env("PATH", "")
6667
.assert()
6768
.failure()
6869
.stderr(predicate::str::contains("rn.sh not found"));
6970
}
7071

72+
#[test]
73+
fn metro_subcommand_without_script_fails_gracefully() {
74+
segkit()
75+
.args(["metro", "start", "ios"])
76+
.env_remove("REACT_NATIVE_SCRIPTS_DIR")
77+
.env("PATH", "")
78+
.assert()
79+
.failure()
80+
.stderr(predicate::str::contains("metro.sh not found"));
81+
}
82+
7183
#[test]
7284
fn setup_detects_devbox() {
7385
segkit()

0 commit comments

Comments
 (0)