feat(xtask): add mobile app starter
Add app new --mobile as the public phone-first starter path. It reuses the Workout starter so created apps carry a real page/form/keyed partial/notice flow, typed host capability handling, app-owned recovery truth, and inspectable mobile release/verify commands without adding a mobile framework. req: ceremony/006 req: examples/006
This commit is contained in:
+76
-15
@@ -16,8 +16,8 @@ fn main() -> ExitCode {
|
||||
}
|
||||
Some("app") => {
|
||||
let subcommand = args.next();
|
||||
let operand = args.next();
|
||||
run_app(subcommand.as_deref(), operand.as_deref())
|
||||
let operands = args.collect::<Vec<_>>();
|
||||
run_app(subcommand.as_deref(), &operands)
|
||||
}
|
||||
Some("workout-mobile") => run_workout_mobile(args.next().as_deref()),
|
||||
Some("help") | Some("--help") | Some("-h") => {
|
||||
@@ -34,14 +34,14 @@ fn main() -> ExitCode {
|
||||
|
||||
fn print_help() {
|
||||
println!(
|
||||
"hemx-ci — resource-aware project checks\n\n cargo run -p hemx-xtask -- test\n cargo run -p hemx-xtask -- bench\n cargo run -p hemx-xtask -- app new PATH\n cargo run -p hemx-xtask -- workout new PATH\n cargo run -p hemx-xtask -- workout dev\n cargo run -p hemx-xtask -- workout test\n cargo run -p hemx-xtask -- workout build\n cargo run -p hemx-xtask -- workout mobile-release\n cargo run -p hemx-xtask -- workout mobile-verify\n cargo run -p hemx-xtask -- workout doctor\n\nEnvironment overrides:\n HEMX_CI_JOBS=N compile jobs, capped by detected resources\n HEMX_CI_TEST_THREADS=N Rust test threads, capped by detected resources\n HEMX_CI_SKIP_BROWSER=1 skip browser E2E\n HEMX_WORKOUT_ORIGIN=https://app.example.com\n HEMX_WORKOUT_MOBILE_OUT=target/hemx-mobile/workout"
|
||||
"hemx-ci — resource-aware project checks\n\n cargo run -p hemx-xtask -- test\n cargo run -p hemx-xtask -- bench\n cargo run -p hemx-xtask -- app new PATH\n cargo run -p hemx-xtask -- app new --mobile PATH\n cargo run -p hemx-xtask -- workout new PATH\n cargo run -p hemx-xtask -- workout dev\n cargo run -p hemx-xtask -- workout test\n cargo run -p hemx-xtask -- workout build\n cargo run -p hemx-xtask -- workout mobile-release\n cargo run -p hemx-xtask -- workout mobile-verify\n cargo run -p hemx-xtask -- workout doctor\n\nEnvironment overrides:\n HEMX_CI_JOBS=N compile jobs, capped by detected resources\n HEMX_CI_TEST_THREADS=N Rust test threads, capped by detected resources\n HEMX_CI_SKIP_BROWSER=1 skip browser E2E\n HEMX_WORKOUT_ORIGIN=https://app.example.com\n HEMX_WORKOUT_MOBILE_OUT=target/hemx-mobile/workout"
|
||||
);
|
||||
}
|
||||
|
||||
fn run_app(command: Option<&str>, operand: Option<&str>) -> ExitCode {
|
||||
// req: ceremony/005 req: canonical_authoring/003
|
||||
fn run_app(command: Option<&str>, operands: &[String]) -> ExitCode {
|
||||
// req: ceremony/005 req: ceremony/006 req: canonical_authoring/003
|
||||
match command.unwrap_or("help") {
|
||||
"new" | "create" => run_app_new(operand),
|
||||
"new" | "create" => run_app_new(operands),
|
||||
"help" | "--help" | "-h" => {
|
||||
print_help();
|
||||
ExitCode::SUCCESS
|
||||
@@ -54,11 +54,16 @@ fn run_app(command: Option<&str>, operand: Option<&str>) -> ExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
fn run_app_new(destination: Option<&str>) -> ExitCode {
|
||||
// req: ceremony/005 req: canonical_authoring/003
|
||||
let Some(destination) = destination else {
|
||||
eprintln!("usage: cargo run -p hemx-xtask -- app new PATH");
|
||||
return ExitCode::from(2);
|
||||
fn run_app_new(operands: &[String]) -> ExitCode {
|
||||
// req: ceremony/005 req: ceremony/006 req: canonical_authoring/003
|
||||
let (mobile, destination) = match operands {
|
||||
[destination] => (false, destination.as_str()),
|
||||
[flag, destination] if flag == "--mobile" => (true, destination.as_str()),
|
||||
[destination, flag] if flag == "--mobile" => (true, destination.as_str()),
|
||||
_ => {
|
||||
eprintln!("usage: cargo run -p hemx-xtask -- app new [--mobile] PATH");
|
||||
return ExitCode::from(2);
|
||||
}
|
||||
};
|
||||
let destination = PathBuf::from(destination);
|
||||
if destination.exists() {
|
||||
@@ -68,13 +73,28 @@ fn run_app_new(destination: Option<&str>) -> ExitCode {
|
||||
);
|
||||
return ExitCode::from(2);
|
||||
}
|
||||
match create_app_scaffold(&destination) {
|
||||
let result = if mobile {
|
||||
create_mobile_app_scaffold(&destination)
|
||||
} else {
|
||||
create_app_scaffold(&destination)
|
||||
};
|
||||
match result {
|
||||
Ok(()) => {
|
||||
println!("app-new\tpath={}", destination.display());
|
||||
println!(
|
||||
"{}\tpath={}",
|
||||
if mobile { "app-new-mobile" } else { "app-new" },
|
||||
destination.display()
|
||||
);
|
||||
println!(
|
||||
"next\tcargo test --manifest-path {}/Cargo.toml",
|
||||
destination.display()
|
||||
);
|
||||
if mobile {
|
||||
println!(
|
||||
"next\tHEMX_WORKOUT_ORIGIN=https://app.example.com {}/hemx-workout mobile-release",
|
||||
destination.display()
|
||||
);
|
||||
}
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -194,6 +214,16 @@ fn create_app_scaffold(destination: &Path) -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_mobile_app_scaffold(destination: &Path) -> std::io::Result<()> {
|
||||
// req: ceremony/006 req: examples/006
|
||||
create_workout_app(destination)?;
|
||||
fs::write(
|
||||
destination.join("MOBILE_STARTER.md"),
|
||||
"# Mobile hemx starter\n\nThis starter is the phone-first Workout path exposed through `app new --mobile`: it has a real page/form/keyed partial/notice flow, typed host haptics/share calls returning through Rust handlers, app-owned command/event/projection recovery truth, and the same `hemx-workout mobile-release` / `hemx-workout mobile-verify` release-kit commands.\n\nIt deliberately does not add a hemx mobile framework, client store, signing secret owner, or store submission bot. req: ceremony/006 req: examples/006\n",
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_workout_app(destination: &Path) -> std::io::Result<()> {
|
||||
let root = repo_root()?;
|
||||
copy_dir(&root.join("examples/workout"), destination)?;
|
||||
@@ -1145,8 +1175,8 @@ fn is_executable(path: impl AsRef<Path>) -> bool {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
android_twa_release_json, create_app_scaffold, create_workout_app,
|
||||
mobile_external_blockers, origin_host, verify_workout_mobile_release,
|
||||
android_twa_release_json, create_app_scaffold, create_mobile_app_scaffold,
|
||||
create_workout_app, mobile_external_blockers, origin_host, verify_workout_mobile_release,
|
||||
workout_mobile_manifest, write_workout_mobile_release, Budget, WorkoutMobileConfig,
|
||||
};
|
||||
use std::fs;
|
||||
@@ -1211,6 +1241,37 @@ mod tests {
|
||||
let _ = fs::remove_dir_all(&destination);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_new_mobile_creates_phone_first_release_starter() {
|
||||
// req: ceremony/006 req: examples/006
|
||||
let destination = PathBuf::from("target/test-hemx-app-new-mobile");
|
||||
let _ = fs::remove_dir_all(&destination);
|
||||
|
||||
create_mobile_app_scaffold(&destination).expect("create mobile app scaffold");
|
||||
let mobile_readme =
|
||||
fs::read_to_string(destination.join("MOBILE_STARTER.md")).expect("mobile docs");
|
||||
let command = fs::read_to_string(destination.join("hemx-workout")).expect("command");
|
||||
let lib_rs = fs::read_to_string(destination.join("src/lib.rs")).expect("lib rs");
|
||||
let template =
|
||||
fs::read_to_string(destination.join("templates/workout.heml")).expect("template");
|
||||
|
||||
assert!(mobile_readme.contains("phone-first Workout path"));
|
||||
assert!(mobile_readme.contains("typed host haptics/share calls"));
|
||||
assert!(mobile_readme.contains("command/event/projection recovery truth"));
|
||||
assert!(mobile_readme.contains("does not add a hemx mobile framework"));
|
||||
assert!(command.contains("mobile-release"));
|
||||
assert!(command.contains("mobile-verify"));
|
||||
assert!(command.contains("app-owned command/event/projection records"));
|
||||
assert!(command.contains("external_blockers"));
|
||||
assert!(lib_rs.contains("HostCall::Share"));
|
||||
assert!(lib_rs.contains("WorkoutCommand"));
|
||||
assert!(lib_rs.contains("WorkoutEvent"));
|
||||
assert!(template.contains("<form"));
|
||||
assert!(template.contains("data-hemx-slot"));
|
||||
assert!(destination.join("tests/e2e.rs").exists());
|
||||
let _ = fs::remove_dir_all(&destination);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn workout_new_creates_standalone_app_manifest() {
|
||||
// req: examples/001 req: examples/006
|
||||
|
||||
Reference in New Issue
Block a user