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 committed Dec 10, 2024
1 parent 78bca49 commit 4be8ac5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
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 @@ -90,7 +90,7 @@ impl WebApp {
};

let ScaffoldedTemplate {
file_tree,
mut file_tree,
next_instructions,
} = scaffold_web_app(
&name,
Expand All @@ -101,7 +101,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 4be8ac5

Please sign in to comment.