Skip to content

Commit

Permalink
chore: Backport and release 0.3000.5 (holochain#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i authored Aug 19, 2024
1 parent f4d1a1c commit 8a6d1da
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "holochain_scaffolding_cli"
version = "0.3000.4"
version = "0.3000.5"
description = "CLI to easily generate and modify holochain apps"
license = "CAL-1.0"
homepage = "https://developer.holochain.org"
Expand Down
38 changes: 19 additions & 19 deletions flake.lock

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

10 changes: 9 additions & 1 deletion src/cli/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
zome::ZomeFileTree,
},
templates::ScaffoldedTemplate,
utils::{check_case, input_with_case},
utils::{check_case, input_with_case, run_cargo_fmt_if_available},
};

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -76,6 +76,14 @@ impl Collection {

build_file_tree(file_tree, ".")?;

if let Err(e) = run_cargo_fmt_if_available() {
println!(
"{}: {}",
"rustfmt exec failed: ".yellow(),
e.to_string().yellow()
);
}

println!("\nCollection {} scaffolded!", name.italic());

if let Some(i) = next_instructions {
Expand Down
10 changes: 9 additions & 1 deletion src/cli/entry_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
zome::ZomeFileTree,
},
templates::ScaffoldedTemplate,
utils::{check_case, input_with_case},
utils::{check_case, input_with_case, run_cargo_fmt_if_available},
};

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -87,6 +87,14 @@ impl EntryType {

build_file_tree(file_tree, ".")?;

if let Err(e) = run_cargo_fmt_if_available() {
println!(
"{}: {}",
"rustfmt exec failed: ".yellow(),
e.to_string().yellow()
);
}

println!("\nEntry type {} scaffolded!", name.italic());

if let Some(i) = next_instructions {
Expand Down
9 changes: 9 additions & 0 deletions src/cli/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::{
},
},
templates::{example::scaffold_example, ScaffoldedTemplate},
utils::run_cargo_fmt_if_available,
};

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -263,6 +264,14 @@ impl Example {

build_file_tree(file_tree, &app_dir)?;

if let Err(e) = run_cargo_fmt_if_available() {
println!(
"{}: {}",
"rustfmt exec failed: ".yellow(),
e.to_string().yellow()
);
}

// set up nix
if let Some(true) | None = self.setup_nix {
if let Err(err) = setup_nix_developer_environment(&app_dir) {
Expand Down
10 changes: 10 additions & 0 deletions src/cli/link_type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::str::FromStr;

use colored::Colorize;
use structopt::StructOpt;

use crate::{
Expand All @@ -9,6 +10,7 @@ use crate::{
zome::ZomeFileTree,
},
templates::ScaffoldedTemplate,
utils::run_cargo_fmt_if_available,
};

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -67,6 +69,14 @@ impl LinkType {

build_file_tree(file_tree, ".")?;

if let Err(e) = run_cargo_fmt_if_available() {
println!(
"{}: {}",
"rustfmt exec failed: ".yellow(),
e.to_string().yellow()
);
}

println!("\nLink type scaffolded!");
if let Some(i) = next_instructions {
println!("\n{}", i);
Expand Down
12 changes: 9 additions & 3 deletions src/cli/web_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use colored::Colorize;
use convert_case::Case;
use convert_case::{Case, Casing};
use structopt::StructOpt;
use tokio::fs;

Expand All @@ -23,7 +23,9 @@ use crate::{
zome::scaffold_zome_pair,
},
templates::ScaffoldedTemplate,
utils::{check_no_whitespace, input_no_whitespace, input_with_case, input_yes_or_no},
utils::{
check_no_whitespace, input_no_whitespace, input_with_case_and_initial_text, input_yes_or_no,
},
};

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -166,7 +168,11 @@ Here's how you can get started with developing your application:
path: &Path,
) -> ScaffoldResult<()> {
env::set_current_dir(PathBuf::from(&name))?;
let dna_name = input_with_case("Initial DNA name (snake_case):", Case::Snake)?;
let dna_name = input_with_case_and_initial_text(
"Initial DNA name (snake_case):",
Case::Snake,
&name.to_case(Case::Snake),
)?;

let file_tree = load_directory_into_memory(&path.join(name))?;
let app_file_tree = AppFileTree::get_or_choose(file_tree, Some(name))?;
Expand Down
10 changes: 9 additions & 1 deletion src/cli/zome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
},
},
templates::ScaffoldedTemplate,
utils::{check_case, input_with_case},
utils::{check_case, input_with_case, run_cargo_fmt_if_available},
};

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -131,6 +131,14 @@ impl Zome {
let f = file_tree.clone();
file_tree.build(&PathBuf::from("."))?;

if let Err(e) = run_cargo_fmt_if_available() {
println!(
"{}: {}",
"rustfmt exec failed: ".yellow(),
e.to_string().yellow()
);
}

// Execute cargo metadata to set up the cargo workspace in case this zome is the first crate
exec_metadata(&f)?;

Expand Down
10 changes: 10 additions & 0 deletions src/scaffold/web_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ pub fn scaffold_web_app(
.insert("flake.nix".into(), flake_nix(holo_enabled));
}

if package_manager == PackageManager::Pnpm {
app_file_tree
.dir_content_mut()
.ok_or(ScaffoldError::PathNotFound(PathBuf::new()))?
.insert(
"pnpm-workspace.yaml".into(),
file!("packages:\n - ui\n - tests"),
);
}

let scaffold_template_result = scaffold_web_app_template(
app_file_tree,
template_file_tree,
Expand Down
5 changes: 3 additions & 2 deletions src/scaffold/zome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
coordinator::scaffold_coordinator_zome_templates,
integrity::scaffold_integrity_zome_templates, ScaffoldedTemplate,
},
utils::input_with_case,
utils::input_with_case_and_initial_text,
versions,
};
use build_fs_tree::{dir, file};
Expand Down Expand Up @@ -512,9 +512,10 @@ pub fn scaffold_zome_pair(
let mut dna_file_tree = DnaFileTree::get_or_choose(app_file_tree, Some(dna_name))?;
let dna_manifest_path = dna_file_tree.dna_manifest_path.clone();

let zome_name = input_with_case(
let zome_name = input_with_case_and_initial_text(
"Enter coordinator zome name (snake_case):\n(The integrity zome will automatically be named '{name of coordinator zome}_integrity')\n",
Case::Snake,
dna_name
)?;

let integrity_zome_name = integrity_zome_name(&zome_name);
Expand Down
15 changes: 15 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::path::Path;
use std::process::Command;
use std::{ffi::OsString, path::PathBuf};

use anyhow::Context;
Expand Down Expand Up @@ -310,6 +311,20 @@ fn format_nested<'a>(
Ok(Cow::Borrowed(raw))
}

/// Runs `cargo fmt` if it's available in the current Rust toolchain otherwise will exit
/// gracefully
pub fn run_cargo_fmt_if_available() -> ScaffoldResult<()> {
let cargo_fmt_available = Command::new("cargo").arg("fmt").arg("--version").output();

match cargo_fmt_available {
Ok(output) if output.status.success() => {
Command::new("cargo").arg("fmt").status()?;
}
_ => {}
}
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

This file was deleted.

0 comments on commit 8a6d1da

Please sign in to comment.