Skip to content

Commit

Permalink
choose_npm_package
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed May 14, 2024
1 parent a6611c7 commit b840f6a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/npm_scaffolding_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ fn default_select_npm_package(
.interact()?)
}

pub fn choose_npm_package(file_tree: &FileTree, prompt: &String) -> Result<String, NpmScaffoldingUtilsError> {
let package_jsons = find_files_by_name(&file_tree, PathBuf::from("package.json").as_path());

let package_jsons: Vec<(PathBuf, String)> = package_jsons.into_iter().collect();
let packages_names = package_jsons
.iter()
.map(|package_json| get_npm_package_name(package_json))
.collect::<Result<Vec<String>, NpmScaffoldingUtilsError>>()?;

let index = Select::with_theme(&ColorfulTheme::default())
.with_prompt(prompt)
.default(0)
.items(&packages_names[..])
.interact()?;

Ok(packages_names[index].clone())
}

pub fn add_npm_dependency(
mut file_tree: FileTree,
dependency: String,
Expand Down

0 comments on commit b840f6a

Please sign in to comment.