Skip to content

Commit

Permalink
Merge pull request #257 from 0xPolygonMiden/greenhat/i165-proj-templa…
Browse files Browse the repository at this point in the history
…te-add-git-tag

chore: switch new project template to basic wallet example and use git tag for it in cargo-miden
  • Loading branch information
bitwalker authored Jul 30, 2024
2 parents 5e787bc + 0e82c14 commit 4150344
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
22 changes: 13 additions & 9 deletions tools/cargo-miden/src/new_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,27 @@ impl NewCommand {
},
None => TemplatePath {
git: Some("https://github.com/0xPolygonMiden/rust-templates".into()),
tag: Some("v0.2.0".into()),
auto_path: Some("account".into()),
..Default::default()
},
};

let destination = self
.path
.parent()
.map(|p| {
use path_absolutize::Absolutize;
p.absolutize().map(|p| p.to_path_buf())
})
.transpose()
.context("Failed to convert destination path to an absolute path")?;
let generate_args = GenerateArgs {
template_path,
destination: self
.path
.parent()
.map(|p| {
use path_absolutize::Absolutize;
p.absolutize().map(|p| p.to_path_buf())
})
.transpose()
.context("Failed to convert destination path to an absolute path")?,
destination,
name: Some(name),
// Force the `name` to not be kebab-cased
force: true,
force_git_init: true,
verbose: true,
define,
Expand Down
28 changes: 24 additions & 4 deletions tools/cargo-miden/tests/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use std::{env, fs};
use std::{env, fs, vec};

use cargo_component_core::terminal;
use cargo_miden::run;

// NOTE: This test sets the current working directory so don't run it in parallel with tests
// that depend on the current directory

fn new_project_args(project_name: &str, template_path: Option<&str>) -> Vec<String> {
let mut args = vec!["cargo", "miden", "new", project_name];
if let Some(template_path) = template_path {
args.extend(["--template-path", template_path]);
};
args.into_iter().map(|s| s.to_string()).collect()
}

#[test]
fn build_new_project_from_template() {
// Signal to `cargo-miden` that we're running in a test harness.
Expand All @@ -17,14 +25,26 @@ fn build_new_project_from_template() {
let restore_dir = env::current_dir().unwrap();
let temp_dir = env::temp_dir();
env::set_current_dir(&temp_dir).unwrap();
let project_name = "test-proj";
let project_name = "test_proj_underscore";
let expected_new_project_dir = &temp_dir.join(project_name);
dbg!(&expected_new_project_dir);
if expected_new_project_dir.exists() {
fs::remove_dir_all(expected_new_project_dir).unwrap();
}
let args = ["cargo", "miden", "new", project_name].into_iter().map(|s| s.to_string());

let args = new_project_args(project_name, None);
// let args = new_project_args(
// project_name,
// Some(
// &(format!(
// "{}/../../../rust-templates/account",
// std::env::var("CARGO_MANIFEST_DIR").unwrap()
// )),
// ),
// );

let terminal = terminal::Terminal::new(terminal::Verbosity::Verbose, terminal::Color::Auto);
let outputs = run(args, &terminal).expect("Failed to create new project");
let outputs = run(args.into_iter(), &terminal).expect("Failed to create new project");
let new_project_path = outputs.first().unwrap().canonicalize().unwrap();
dbg!(&new_project_path);
assert!(new_project_path.exists());
Expand Down

0 comments on commit 4150344

Please sign in to comment.