Skip to content

Commit

Permalink
fix: 🐛 fixed cli packaging issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arctic-hen7 committed Sep 3, 2021
1 parent 2378c9d commit dd43e81
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
11 changes: 11 additions & 0 deletions bonnie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ dev.subcommands.serve.cmd = [
dev.subcommands.serve.args = [ "server" ]
dev.subcommands.cli = [
"cd packages/perseus-cli",
# We need to copy in the directory where we actually work on the subcrate
"cd ../perseus-cli",
"rm -rf ./.perseus",
"cp -r ../../examples/cli/.perseus/ .perseus/",
"mv .perseus/Cargo.toml .perseus/Cargo.toml.old",
"mv .perseus/server/Cargo.toml .perseus/server/Cargo.toml.old",
"cargo run -- %%"
]
build = "cargo build"
Expand All @@ -33,6 +39,11 @@ publish = [
"cargo publish",
"cd ../perseus-actix-web",
"cargo publish",
# The CLI needs the `.perseus/` directory copied in for packaging (and we need to rename `Cargo.toml` to `Cargo.toml.old`)
"cd ../perseus-cli",
"rm -rf ./.perseus",
"cp -r ../../examples/cli/.perseus/ .perseus/",
"mv .perseus/Cargo.toml .perseus/Cargo.toml.old",
"mv .perseus/server/Cargo.toml .perseus/server/Cargo.toml.old",
"cargo publish"
]
2 changes: 2 additions & 0 deletions packages/perseus-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# We copy in the subcrate under development in the `cli` example for packaging only
.perseus/
5 changes: 5 additions & 0 deletions packages/perseus-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ homepage = "https://arctic-hen7.github.io/perseus"
readme = "../../README.md"
keywords = ["wasm", "cli", "webdev", "ssg", "ssr"]
categories = ["wasm", "development-tools", "asynchronous", "gui", "command-line-utilities"]
include = [
"src/",
"Cargo.toml",
".perseus/"
]

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

Expand Down
18 changes: 12 additions & 6 deletions packages/perseus-cli/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use std::io::Write;
use std::path::PathBuf;
use std::process::Command;

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

/// Prepares the user's project by copying in the `.perseus/` subcrates. We use these subcrates to do all the building/serving, we just
/// have to execute the right commands in the CLI. We can essentially treat the subcrates themselves as a blackbox of just a folder.
Expand Down Expand Up @@ -42,19 +43,24 @@ pub fn prepare(dir: PathBuf) -> Result<()> {
}
// Use the current version of this crate (and thus all Perseus crates) to replace the relative imports
// That way everything works in dev and in prod on another system!
// We have to store `Cargo.toml` as `Cargo.toml.old` for packaging
let mut root_manifest_pkg = target.clone();
root_manifest_pkg.extend(["Cargo.toml.old"]);
let mut root_manifest = target.clone();
root_manifest.extend(["Cargo.toml"]);
let mut server_manifest_pkg = target.clone();
server_manifest_pkg.extend(["server", "Cargo.toml.old"]);
let mut server_manifest = target.clone();
server_manifest.extend(["server", "Cargo.toml"]);
let root_manifest_contents = fs::read_to_string(&root_manifest).map_err(|err| {
let root_manifest_contents = fs::read_to_string(&root_manifest_pkg).map_err(|err| {
ErrorKind::ManifestUpdateFailed(
root_manifest.to_str().map(|s| s.to_string()),
root_manifest_pkg.to_str().map(|s| s.to_string()),
err.to_string(),
)
})?;
let server_manifest_contents = fs::read_to_string(&server_manifest).map_err(|err| {
let server_manifest_contents = fs::read_to_string(&server_manifest_pkg).map_err(|err| {
ErrorKind::ManifestUpdateFailed(
server_manifest.to_str().map(|s| s.to_string()),
server_manifest_pkg.to_str().map(|s| s.to_string()),
err.to_string(),
)
})?;
Expand Down

0 comments on commit dd43e81

Please sign in to comment.