From 97b7a472e2645cdeeaf547637dae5005cd849020 Mon Sep 17 00:00:00 2001 From: Collins Muriuki Date: Thu, 14 Nov 2024 14:06:29 +0300 Subject: [PATCH] fix: Skip writing scaffold config for nixified custom templates (#415) * Add skip_config_check global flag to scaffolding * Prefer not writing the scaffold config for nixified custom templates * Fix rustfmt warning --- src/cli/example.rs | 4 ++-- src/cli/web_app.rs | 6 ++++-- src/scaffold/config.rs | 8 ++++---- src/scaffold/web_app/template_type.rs | 8 ++++++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cli/example.rs b/src/cli/example.rs index c50aadcc7..f2916c0cf 100644 --- a/src/cli/example.rs +++ b/src/cli/example.rs @@ -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)?; diff --git a/src/cli/web_app.rs b/src/cli/web_app.rs index 2172d3a7b..ecc68a06d 100644 --- a/src/cli/web_app.rs +++ b/src/cli/web_app.rs @@ -88,7 +88,7 @@ impl WebApp { }; let ScaffoldedTemplate { - file_tree, + mut file_tree, next_instructions, } = scaffold_web_app( &name, @@ -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)?; diff --git a/src/scaffold/config.rs b/src/scaffold/config.rs index 5c5b3de26..9bbff39c6 100644 --- a/src/scaffold/config.rs +++ b/src/scaffold/config.rs @@ -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 { + ) -> 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::(&c)?; let json = match json { @@ -59,6 +59,6 @@ impl ScaffoldConfig { Ok(json) })?; - Ok(web_app_file_tree) + Ok(()) } } diff --git a/src/scaffold/web_app/template_type.rs b/src/scaffold/web_app/template_type.rs index 711152b32..cd5de8e39 100644 --- a/src/scaffold/web_app/template_type.rs +++ b/src/scaffold/web_app/template_type.rs @@ -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 for TemplateType {