Skip to content

Commit

Permalink
fix: Skip writing scaffold config for nixified custom templates (#415)
Browse files Browse the repository at this point in the history
* Add skip_config_check global flag to scaffolding

* Prefer not writing the scaffold config for nixified custom templates

* Fix rustfmt warning
  • Loading branch information
c12i authored Nov 14, 2024
1 parent 6d984d2 commit b2278b1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ itertools = "0.13.0"
colored = "2.1.0"
dprint-plugin-typescript = "0.91.1"
markup_fmt = "0.10.0"
git2 = { version = "0.19.0", default-features = false, features = ["https", "ssh_key_from_memory", "vendored-libgit2", "vendored-openssl"] }
git2 = { version = "0.19.0", default-features = false, features = [
"https",
"ssh_key_from_memory",
"vendored-libgit2",
"vendored-openssl",
] }
4 changes: 2 additions & 2 deletions src/cli/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ impl Example {
};

let ScaffoldedTemplate {
file_tree,
mut file_tree,
next_instructions,
} = scaffold_example(file_tree, package_manager, &template_file_tree, &example)?;

let file_tree = ScaffoldConfig::write_to_package_json(file_tree, template_type)?;
ScaffoldConfig::write_to_package_json(&mut file_tree, template_type)?;

build_file_tree(file_tree, &app_dir)?;

Expand Down
6 changes: 4 additions & 2 deletions src/cli/web_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl WebApp {
};

let ScaffoldedTemplate {
file_tree,
mut file_tree,
next_instructions,
} = scaffold_web_app(
&name,
Expand All @@ -99,7 +99,9 @@ impl WebApp {
self.holo_enabled,
)?;

let file_tree = ScaffoldConfig::write_to_package_json(file_tree, template_type)?;
if !template_type.is_nixified_custom_template() {
ScaffoldConfig::write_to_package_json(&mut file_tree, template_type)?;
}

build_file_tree(file_tree, &app_folder)?;

Expand Down
8 changes: 4 additions & 4 deletions src/scaffold/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ impl ScaffoldConfig {
}

pub fn write_to_package_json(
mut web_app_file_tree: FileTree,
web_app_file_tree: &mut FileTree,
template_type: &TemplateType,
) -> ScaffoldResult<FileTree> {
) -> ScaffoldResult<()> {
let config = ScaffoldConfig {
template: template_type.clone(),
};
let package_json_path = PathBuf::from("package.json");

map_file(&mut web_app_file_tree, &package_json_path, |c| {
map_file(web_app_file_tree, &package_json_path, |c| {
let original_content = c.clone();
let json = serde_json::from_str::<Value>(&c)?;
let json = match json {
Expand All @@ -59,6 +59,6 @@ impl ScaffoldConfig {
Ok(json)
})?;

Ok(web_app_file_tree)
Ok(())
}
}
8 changes: 8 additions & 0 deletions src/scaffold/web_app/template_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ impl TemplateType {
.interact()?;
Ok(frameworks[selection].clone())
}

/// Checks whether the custom template'path is a path to a nix store
pub fn is_nixified_custom_template(&self) -> bool {
if let TemplateType::Custom(path) = self {
return path.starts_with("/nix/store/");
}
false
}
}

impl From<PathBuf> for TemplateType {
Expand Down

0 comments on commit b2278b1

Please sign in to comment.