Skip to content

Commit d79f029

Browse files
committed
feat: ✨ made cli preserve relative paths in development
This makes updating and testing the CLI *much* easier.
1 parent 9b578f5 commit d79f029

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

bonnie.toml

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version="0.3.2"
44
dev.subcommands.cli.cmd = [
55
"cd packages/perseus-cli",
66
# We need to copy in the directory where we actually work on the subcrate
7-
"cd ../perseus-cli",
87
"rm -rf ./.perseus",
98
"cp -r ../../examples/cli/.perseus/ .perseus/",
109
"mv .perseus/Cargo.toml .perseus/Cargo.toml.old",
@@ -13,11 +12,17 @@ dev.subcommands.cli.cmd = [
1312
]
1413
dev.subcommands.cli.desc = "runs the cli in its own directory (which should test `examples/basic`)"
1514
dev.subcommands.example.cmd = [
16-
"cd examples/%example",
17-
"find . -not -path \"./.perseus/*\" -not -path \"./target/*\" | entr -s \"perseus serve\""
15+
"cd packages/perseus-cli",
16+
# We need to copy in the directory where we actually work on the subcrate
17+
"rm -rf ./.perseus",
18+
"cp -r ../../examples/cli/.perseus/ .perseus/",
19+
"mv .perseus/Cargo.toml .perseus/Cargo.toml.old",
20+
"mv .perseus/server/Cargo.toml .perseus/server/Cargo.toml.old",
21+
# Now point this live version of the CLI at the given example
22+
"TEST_EXAMPLE=../../examples/%example cargo run -- %%"
1823
]
1924
dev.subcommands.example.args = [ "example" ]
20-
dev.subcommands.example.desc = "serves the given example, watching for file changes (uses cli)"
25+
dev.subcommands.example.desc = "serves the given example using a live version of the cli"
2126

2227
build = "cargo build"
2328
test = "cargo watch -x \"test\""

packages/perseus-cli/src/bin/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::path::PathBuf;
88
fn main() {
99
// In development, we'll test in the `basic` example
1010
if cfg!(debug_assertions) {
11-
env::set_current_dir("../../examples/basic").unwrap();
11+
let example_to_test = env::var("TEST_EXAMPLE").unwrap_or_else(|_| "../../examples/basic".to_string());
12+
env::set_current_dir(example_to_test).unwrap();
1213
}
1314
let exit_code = real_main();
1415
std::process::exit(exit_code)

packages/perseus-cli/src/prepare.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,27 @@ pub fn prepare(dir: PathBuf) -> Result<()> {
7575
"no '[package]' section in manifest".to_string()
7676
)),
7777
};
78-
// Replace the relative path references to Perseus packages
79-
// Also update the name of the user's crate (Cargo needs more than just a path and an alias)
78+
// Update the name of the user's crate (Cargo needs more than just a path and an alias)
8079
// Also add an empty `[workspace]` key so we exclude from any of the user's workspace settings
8180
let updated_root_manifest = root_manifest_contents
82-
.replace(
83-
"{ path = \"../../../packages/perseus\" }",
84-
&format!("\"{}\"", PERSEUS_VERSION),
85-
)
8681
.replace("perseus-example-cli", &user_crate_name)
8782
+ "\n[workspace]";
8883
let updated_server_manifest = server_manifest_contents
89-
.replace(
90-
"{ path = \"../../../../packages/perseus-actix-web\" }",
91-
&format!("\"{}\"", PERSEUS_VERSION),
92-
)
9384
.replace("perseus-example-cli", &user_crate_name)
9485
+ "\n[workspace]";
86+
87+
// If we're not in development, also update relative path references
88+
#[cfg(not(debug_assertions))]
89+
let updated_root_manifest = updated_root_manifest.replace(
90+
"{ path = \"../../../packages/perseus\" }",
91+
&format!("\"{}\"", PERSEUS_VERSION),
92+
);
93+
#[cfg(not(debug_assertions))]
94+
let updated_server_manifest = updated_server_manifest.replace(
95+
"{ path = \"../../../../packages/perseus-actix-web\" }",
96+
&format!("\"{}\"", PERSEUS_VERSION),
97+
);
98+
9599
// Write the updated manifests back
96100
if let Err(err) = fs::write(&root_manifest, updated_root_manifest) {
97101
bail!(ErrorKind::ManifestUpdateFailed(

0 commit comments

Comments
 (0)