Projects STRLCPY dum Commits 32f47f3e
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    .gitignore
     1 +.idea
    1 2  /target
    2 3  node_modules
     4 +npm-debug.log
     5 +yarn-error.log
     6 +.pnpm-debug.log
     7 + 
  • ■ ■ ■ ■ ■ ■
    Cargo.lock
    skipped 20 lines
    21 21  ]
    22 22   
    23 23  [[package]]
     24 +name = "anyhow"
     25 +version = "1.0.51"
     26 +source = "registry+https://github.com/rust-lang/crates.io-index"
     27 +checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
     28 + 
     29 +[[package]]
    24 30  name = "atty"
    25 31  version = "0.2.14"
    26 32  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 70 lines
    97 103  version = "0.1.19"
    98 104  dependencies = [
    99 105   "ansi_term",
     106 + "anyhow",
    100 107   "ctrlc",
    101 108   "dialoguer",
    102 109   "env_logger",
    skipped 315 lines
  • ■ ■ ■ ■ ■ ■
    Cargo.toml
    skipped 16 lines
    17 17  log = "0.4.14"
    18 18  env_logger = "0.9.0"
    19 19  path-absolutize = "3.0.11"
     20 +anyhow = "1.0.51"
     21 + 
  • ■ ■ ■ ■ ■
    src/install.rs
     1 +use std::path::Path;
     2 +use std::str::FromStr;
     3 + 
     4 +use anyhow::{anyhow, Error};
     5 + 
    1 6  use crate::prompt;
    2  -use std::path::Path;
     7 + 
     8 +pub enum PackageManager {
     9 + Yarn,
     10 + Npm,
     11 + Pnpm,
     12 +}
     13 + 
     14 +impl ToString for PackageManager {
     15 + fn to_string(&self) -> String {
     16 + match self {
     17 + PackageManager::Yarn => "yarn".to_string(),
     18 + PackageManager::Npm => "npm".to_string(),
     19 + PackageManager::Pnpm => "pnpm".to_string(),
     20 + }
     21 + }
     22 +}
     23 + 
     24 +impl FromStr for PackageManager {
     25 + type Err = Error;
     26 + 
     27 + fn from_str(name: &str) -> Result<Self, Self::Err> {
     28 + match name {
     29 + "yarn" => Ok(PackageManager::Yarn),
     30 + "npm" => Ok(PackageManager::Npm),
     31 + "pnpm" => Ok(PackageManager::Pnpm),
     32 + _ => Err(anyhow!("Parse package manager error")),
     33 + }
     34 + }
     35 +}
     36 + 
    3 37   
    4 38  // A function to guess package manager by looking for lock file in current directory only
    5 39  // If yarn.lock is found, it's likely to be a yarn project
    6 40  // If package-lock.json is found, it's likely to be a npm project
    7 41  // If pnpm-lock.yaml is found, it's likely to be a pnpm project
    8 42  // If none of the above is found, return None
    9  -pub fn guess_package_manager(dir: &Path) -> Option<String> {
     43 +pub fn guess_package_manager(dir: &Path) -> Option<PackageManager> {
    10 44   let lock_file = dir.join("yarn.lock");
    11 45   if lock_file.exists() {
    12  - return Some("yarn".to_string());
     46 + return Some(PackageManager::Yarn);
    13 47   }
    14 48   
    15 49   let lock_file = dir.join("package-lock.json");
    16 50   if lock_file.exists() {
    17  - return Some("npm".to_string());
     51 + return Some(PackageManager::Npm);
    18 52   }
    19 53   
    20 54   let lock_file = dir.join("pnpm-lock.yaml");
    21 55   if lock_file.exists() {
    22  - return Some("pnpm".to_string());
     56 + return Some(PackageManager::Pnpm);
    23 57   }
    24 58   
     59 + 
    25 60   let items = vec!["pnpm", "npm", "yarn"];
    26  - prompt::select("Which package manager do you want to use?", items)
     61 + match prompt::select("Which package manager do you want to use?", items) {
     62 + Some(pm) => PackageManager::from_str(&pm).ok(),
     63 + None => None
     64 + }
    27 65  }
    28 66   
  • ■ ■ ■ ■ ■ ■
    src/run.rs
    skipped 27 lines
    28 28   
    29 29  // A function to find the closest file
    30 30  // Starting from current directory
    31  -// Recusively until it finds the file or reach root directory
     31 +// Recursively until it finds the file or reach root directory
    32 32  fn find_closest_files(_current_dir: &Path, name: &str, stop_on_first: bool) -> Vec<PathBuf> {
    33 33   let mut closest_file: Vec<PathBuf> = Vec::new();
    34 34   let mut current_dir = Path::new(_current_dir);
    skipped 76 lines
    111 111   }
    112 112   
    113 113   run_command(
    114  - &[&pm.unwrap(), &app_args.command, &app_args.forwarded],
     114 + &[&pm.unwrap().to_string(), &app_args.command, &app_args.forwarded],
    115 115   &RunOptions {
    116 116   current_dir: app_args.change_dir.clone(),
    117 117   envs: HashMap::new(),
    skipped 130 lines
Please wait...
Page is in error, reload to recover