Skip to content

Commit

Permalink
Include the template in the binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker committed Dec 10, 2023
1 parent 247b670 commit 9212953
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
20 changes: 20 additions & 0 deletions libs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions libs/pavex_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ owo-colors = "3"
anyhow = "1"
guppy = "0.17"
supports-color = { version = "2" }

#cargo-generate = "0.18.4"
# Temporary fork until https://github.com/cargo-generate/cargo-generate/pull/1070 is merged and released
cargo-generate = { git = "https://github.com/LukeMathWalker/cargo-generate", branch = "main" }

include_dir = "0.7.3"
cargo-generate = "0.18.4"
path-absolutize = "3.1.1"

[dev-dependencies]
Expand Down
22 changes: 15 additions & 7 deletions libs/pavex_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ fn use_color_on_stderr(color_profile: Color) -> bool {
}
}

static TEMPLATE_DIR: include_dir::Dir =
include_dir::include_dir!("$CARGO_MANIFEST_DIR/../../template");

fn scaffold_project(path: PathBuf) -> Result<ExitCode, Box<dyn std::error::Error>> {
let name = path
.file_name()
Expand All @@ -200,15 +203,20 @@ fn scaffold_project(path: PathBuf) -> Result<ExitCode, Box<dyn std::error::Error
})?
.to_string();

let target_directory =
std::env::temp_dir().join(format!("pavex-template-{}", env!("VERGEN_GIT_SHA")));
TEMPLATE_DIR
.extract(&target_directory)
.context("Failed to save Pavex's template to a temporary directory")?;

let generate_args = GenerateArgs {
template_path: TemplatePath {
git: Some("https://github.com/LukeMathWalker/pavex".into()),
subfolder: Some("template".into()),
// We make sure to use the exact same version (i.e. commit SHA) for both
// the `pavex` CLI itself and the template that we use to scaffold the new project.
// This is to ensure that the generated project is always compatible with the
// version of the CLI that was used to generate it.
revision: Some(env!("VERGEN_GIT_SHA").into()),
path: Some(
target_directory
.to_str()
.context("Failed to convert the template path to a UTF8 string")?
.into(),
),
..Default::default()
},
destination: path
Expand Down

0 comments on commit 9212953

Please sign in to comment.