Skip to content

Commit dd43e81

Browse files
committed
fix: 🐛 fixed cli packaging issues
Had to copy subcrates in every time we run and store `Cargo.toml` as `Cargo.toml.old` so Cargo doesn't complain when we package.
1 parent 2378c9d commit dd43e81

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

bonnie.toml

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ dev.subcommands.serve.cmd = [
1212
dev.subcommands.serve.args = [ "server" ]
1313
dev.subcommands.cli = [
1414
"cd packages/perseus-cli",
15+
# We need to copy in the directory where we actually work on the subcrate
16+
"cd ../perseus-cli",
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",
1521
"cargo run -- %%"
1622
]
1723
build = "cargo build"
@@ -33,6 +39,11 @@ publish = [
3339
"cargo publish",
3440
"cd ../perseus-actix-web",
3541
"cargo publish",
42+
# The CLI needs the `.perseus/` directory copied in for packaging (and we need to rename `Cargo.toml` to `Cargo.toml.old`)
3643
"cd ../perseus-cli",
44+
"rm -rf ./.perseus",
45+
"cp -r ../../examples/cli/.perseus/ .perseus/",
46+
"mv .perseus/Cargo.toml .perseus/Cargo.toml.old",
47+
"mv .perseus/server/Cargo.toml .perseus/server/Cargo.toml.old",
3748
"cargo publish"
3849
]

packages/perseus-cli/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# We copy in the subcrate under development in the `cli` example for packaging only
2+
.perseus/

packages/perseus-cli/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ homepage = "https://arctic-hen7.github.io/perseus"
1010
readme = "../../README.md"
1111
keywords = ["wasm", "cli", "webdev", "ssg", "ssr"]
1212
categories = ["wasm", "development-tools", "asynchronous", "gui", "command-line-utilities"]
13+
include = [
14+
"src/",
15+
"Cargo.toml",
16+
".perseus/"
17+
]
1318

1419
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1520

packages/perseus-cli/src/prepare.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use std::io::Write;
1010
use std::path::PathBuf;
1111
use std::process::Command;
1212

13-
/// This literally includes the entire subcrate in the program, allowing more efficient development.
14-
const SUBCRATES: Dir = include_dir!("../../examples/cli/.perseus");
13+
// This literally includes the entire subcrate in the program, allowing more efficient development.
14+
// This MUST be copied in from `../../examples/cli/.perseus/` every time the CLI is tested (use the Bonnie script).
15+
const SUBCRATES: Dir = include_dir!("./.perseus");
1516

1617
/// Prepares the user's project by copying in the `.perseus/` subcrates. We use these subcrates to do all the building/serving, we just
1718
/// have to execute the right commands in the CLI. We can essentially treat the subcrates themselves as a blackbox of just a folder.
@@ -42,19 +43,24 @@ pub fn prepare(dir: PathBuf) -> Result<()> {
4243
}
4344
// Use the current version of this crate (and thus all Perseus crates) to replace the relative imports
4445
// That way everything works in dev and in prod on another system!
46+
// We have to store `Cargo.toml` as `Cargo.toml.old` for packaging
47+
let mut root_manifest_pkg = target.clone();
48+
root_manifest_pkg.extend(["Cargo.toml.old"]);
4549
let mut root_manifest = target.clone();
4650
root_manifest.extend(["Cargo.toml"]);
51+
let mut server_manifest_pkg = target.clone();
52+
server_manifest_pkg.extend(["server", "Cargo.toml.old"]);
4753
let mut server_manifest = target.clone();
4854
server_manifest.extend(["server", "Cargo.toml"]);
49-
let root_manifest_contents = fs::read_to_string(&root_manifest).map_err(|err| {
55+
let root_manifest_contents = fs::read_to_string(&root_manifest_pkg).map_err(|err| {
5056
ErrorKind::ManifestUpdateFailed(
51-
root_manifest.to_str().map(|s| s.to_string()),
57+
root_manifest_pkg.to_str().map(|s| s.to_string()),
5258
err.to_string(),
5359
)
5460
})?;
55-
let server_manifest_contents = fs::read_to_string(&server_manifest).map_err(|err| {
61+
let server_manifest_contents = fs::read_to_string(&server_manifest_pkg).map_err(|err| {
5662
ErrorKind::ManifestUpdateFailed(
57-
server_manifest.to_str().map(|s| s.to_string()),
63+
server_manifest_pkg.to_str().map(|s| s.to_string()),
5864
err.to_string(),
5965
)
6066
})?;

0 commit comments

Comments
 (0)