Projects STRLCPY dum Commits 2b5e8020
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    CHANGELOG.md
    1  -## Unreleased
     1 +## v0.1.5
    2 2   
    3 3  - Alias script `t` to `test`, so `dum t` and `dum test` are equivalent.
     4 +- Add `install` command to automatically run `npm i`, `yarn` or `pnpm i` depending on the project.
    4 5   
  • ■ ■ ■ ■ ■ ■
    Cargo.lock
    skipped 2 lines
    3 3  version = 3
    4 4   
    5 5  [[package]]
     6 +name = "bitflags"
     7 +version = "1.3.2"
     8 +source = "registry+https://github.com/rust-lang/crates.io-index"
     9 +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
     10 + 
     11 +[[package]]
     12 +name = "cfg-if"
     13 +version = "1.0.0"
     14 +source = "registry+https://github.com/rust-lang/crates.io-index"
     15 +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
     16 + 
     17 +[[package]]
     18 +name = "console"
     19 +version = "0.15.0"
     20 +source = "registry+https://github.com/rust-lang/crates.io-index"
     21 +checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31"
     22 +dependencies = [
     23 + "encode_unicode",
     24 + "libc",
     25 + "once_cell",
     26 + "regex",
     27 + "terminal_size",
     28 + "unicode-width",
     29 + "winapi",
     30 +]
     31 + 
     32 +[[package]]
     33 +name = "dialoguer"
     34 +version = "0.9.0"
     35 +source = "registry+https://github.com/rust-lang/crates.io-index"
     36 +checksum = "61579ada4ec0c6031cfac3f86fdba0d195a7ebeb5e36693bd53cb5999a25beeb"
     37 +dependencies = [
     38 + "console",
     39 + "lazy_static",
     40 + "tempfile",
     41 + "zeroize",
     42 +]
     43 + 
     44 +[[package]]
    6 45  name = "dum"
    7  -version = "0.1.4"
     46 +version = "0.1.5"
    8 47  dependencies = [
     48 + "dialoguer",
    9 49   "pico-args",
    10 50   "serde_json",
    11 51  ]
    12 52   
    13 53  [[package]]
     54 +name = "encode_unicode"
     55 +version = "0.3.6"
     56 +source = "registry+https://github.com/rust-lang/crates.io-index"
     57 +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
     58 + 
     59 +[[package]]
     60 +name = "getrandom"
     61 +version = "0.2.3"
     62 +source = "registry+https://github.com/rust-lang/crates.io-index"
     63 +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
     64 +dependencies = [
     65 + "cfg-if",
     66 + "libc",
     67 + "wasi",
     68 +]
     69 + 
     70 +[[package]]
    14 71  name = "itoa"
    15 72  version = "0.4.8"
    16 73  source = "registry+https://github.com/rust-lang/crates.io-index"
    17 74  checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
    18 75   
    19 76  [[package]]
     77 +name = "lazy_static"
     78 +version = "1.4.0"
     79 +source = "registry+https://github.com/rust-lang/crates.io-index"
     80 +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
     81 + 
     82 +[[package]]
     83 +name = "libc"
     84 +version = "0.2.107"
     85 +source = "registry+https://github.com/rust-lang/crates.io-index"
     86 +checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219"
     87 + 
     88 +[[package]]
     89 +name = "once_cell"
     90 +version = "1.8.0"
     91 +source = "registry+https://github.com/rust-lang/crates.io-index"
     92 +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
     93 + 
     94 +[[package]]
    20 95  name = "pico-args"
    21 96  version = "0.4.2"
    22 97  source = "registry+https://github.com/rust-lang/crates.io-index"
    23 98  checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
    24 99   
    25 100  [[package]]
     101 +name = "ppv-lite86"
     102 +version = "0.2.15"
     103 +source = "registry+https://github.com/rust-lang/crates.io-index"
     104 +checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba"
     105 + 
     106 +[[package]]
     107 +name = "rand"
     108 +version = "0.8.4"
     109 +source = "registry+https://github.com/rust-lang/crates.io-index"
     110 +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
     111 +dependencies = [
     112 + "libc",
     113 + "rand_chacha",
     114 + "rand_core",
     115 + "rand_hc",
     116 +]
     117 + 
     118 +[[package]]
     119 +name = "rand_chacha"
     120 +version = "0.3.1"
     121 +source = "registry+https://github.com/rust-lang/crates.io-index"
     122 +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
     123 +dependencies = [
     124 + "ppv-lite86",
     125 + "rand_core",
     126 +]
     127 + 
     128 +[[package]]
     129 +name = "rand_core"
     130 +version = "0.6.3"
     131 +source = "registry+https://github.com/rust-lang/crates.io-index"
     132 +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
     133 +dependencies = [
     134 + "getrandom",
     135 +]
     136 + 
     137 +[[package]]
     138 +name = "rand_hc"
     139 +version = "0.3.1"
     140 +source = "registry+https://github.com/rust-lang/crates.io-index"
     141 +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
     142 +dependencies = [
     143 + "rand_core",
     144 +]
     145 + 
     146 +[[package]]
     147 +name = "redox_syscall"
     148 +version = "0.2.10"
     149 +source = "registry+https://github.com/rust-lang/crates.io-index"
     150 +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
     151 +dependencies = [
     152 + "bitflags",
     153 +]
     154 + 
     155 +[[package]]
     156 +name = "regex"
     157 +version = "1.5.4"
     158 +source = "registry+https://github.com/rust-lang/crates.io-index"
     159 +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
     160 +dependencies = [
     161 + "regex-syntax",
     162 +]
     163 + 
     164 +[[package]]
     165 +name = "regex-syntax"
     166 +version = "0.6.25"
     167 +source = "registry+https://github.com/rust-lang/crates.io-index"
     168 +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
     169 + 
     170 +[[package]]
     171 +name = "remove_dir_all"
     172 +version = "0.5.3"
     173 +source = "registry+https://github.com/rust-lang/crates.io-index"
     174 +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
     175 +dependencies = [
     176 + "winapi",
     177 +]
     178 + 
     179 +[[package]]
    26 180  name = "ryu"
    27 181  version = "1.0.5"
    28 182  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 16 lines
    45 199   "serde",
    46 200  ]
    47 201   
     202 +[[package]]
     203 +name = "tempfile"
     204 +version = "3.2.0"
     205 +source = "registry+https://github.com/rust-lang/crates.io-index"
     206 +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
     207 +dependencies = [
     208 + "cfg-if",
     209 + "libc",
     210 + "rand",
     211 + "redox_syscall",
     212 + "remove_dir_all",
     213 + "winapi",
     214 +]
     215 + 
     216 +[[package]]
     217 +name = "terminal_size"
     218 +version = "0.1.17"
     219 +source = "registry+https://github.com/rust-lang/crates.io-index"
     220 +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
     221 +dependencies = [
     222 + "libc",
     223 + "winapi",
     224 +]
     225 + 
     226 +[[package]]
     227 +name = "unicode-width"
     228 +version = "0.1.9"
     229 +source = "registry+https://github.com/rust-lang/crates.io-index"
     230 +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
     231 + 
     232 +[[package]]
     233 +name = "wasi"
     234 +version = "0.10.2+wasi-snapshot-preview1"
     235 +source = "registry+https://github.com/rust-lang/crates.io-index"
     236 +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
     237 + 
     238 +[[package]]
     239 +name = "winapi"
     240 +version = "0.3.9"
     241 +source = "registry+https://github.com/rust-lang/crates.io-index"
     242 +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
     243 +dependencies = [
     244 + "winapi-i686-pc-windows-gnu",
     245 + "winapi-x86_64-pc-windows-gnu",
     246 +]
     247 + 
     248 +[[package]]
     249 +name = "winapi-i686-pc-windows-gnu"
     250 +version = "0.4.0"
     251 +source = "registry+https://github.com/rust-lang/crates.io-index"
     252 +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
     253 + 
     254 +[[package]]
     255 +name = "winapi-x86_64-pc-windows-gnu"
     256 +version = "0.4.0"
     257 +source = "registry+https://github.com/rust-lang/crates.io-index"
     258 +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
     259 + 
     260 +[[package]]
     261 +name = "zeroize"
     262 +version = "1.4.3"
     263 +source = "registry+https://github.com/rust-lang/crates.io-index"
     264 +checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619"
     265 + 
  • ■ ■ ■ ■ ■
    Cargo.toml
    1 1  [package]
    2 2  name = "dum"
    3  -version = "0.1.4"
     3 +version = "0.1.5"
    4 4  edition = "2021"
    5 5  license = "MIT"
    6 6  description = "An npm scripts runner"
    skipped 5 lines
    12 12  [dependencies]
    13 13  pico-args = "0.4.2"
    14 14  serde_json = "1.0"
     15 +dialoguer = "0.9.0"
    15 16   
  • ■ ■ ■ ■ ■ ■
    src/install.rs
    1  -enum PackageManager {
    2  - Npm,
    3  - Yarn,
    4  - Pnpm,
    5  -}
     1 +use dialoguer::console::Term;
     2 +use dialoguer::{theme::ColorfulTheme, Select};
     3 +use std::path::PathBuf;
    6 4   
    7 5  // A function to guess package manager by looking for lock file in current directory only
    8 6  // If yarn.lock is found, it's likely to be a yarn project
    9 7  // If package-lock.json is found, it's likely to be a npm project
    10 8  // If pnpm-lock.yaml is found, it's likely to be a pnpm project
    11 9  // If none of the above is found, return None
    12  -pub fn guess_package_manager(dir: &PathBuf) -> Option<PackageManager> {
     10 +pub fn guess_package_manager(dir: &PathBuf) -> Option<String> {
    13 11   let lock_file = dir.join("yarn.lock");
    14 12   if lock_file.exists() {
    15  - return Some(PackageManager::Yarn);
     13 + return Some("yarn".to_string());
    16 14   }
    17 15   
    18 16   let lock_file = dir.join("package-lock.json");
    19 17   if lock_file.exists() {
    20  - return Some(PackageManager::Npm);
     18 + return Some("npm".to_string());
    21 19   }
    22 20   
    23 21   let lock_file = dir.join("pnpm-lock.yaml");
    24 22   if lock_file.exists() {
    25  - return Some(PackageManager::Pnpm);
     23 + return Some("pnpm".to_string());
    26 24   }
    27 25   
    28  - None
     26 + let items = vec!["pnpm", "npm", "yarn"];
     27 + let selection = Select::with_theme(&ColorfulTheme::default())
     28 + .with_prompt("Which package manager do you want to use?")
     29 + .items(&items)
     30 + .default(0)
     31 + .interact_on_opt(&Term::stderr())
     32 + .ok()?;
     33 + 
     34 + if selection.is_none() {
     35 + return None;
     36 + }
     37 + 
     38 + Some(items[selection.unwrap()].to_string())
    29 39  }
    30 40   
  • ■ ■ ■ ■ ■ ■
    src/main.rs
     1 +mod install;
     2 + 
    1 3  use serde_json::Value;
    2 4  use std::collections::HashMap;
    3 5  use std::env;
    skipped 38 lines
    42 44   return;
    43 45   }
    44 46   
     47 + // Run npm install if the script_name is "install"
     48 + if args.script_name == "install" {
     49 + let pm = install::guess_package_manager(&execute_dir);
     50 + 
     51 + if pm.is_none() {
     52 + eprintln!("No package manager found.");
     53 + exit(1);
     54 + }
     55 + 
     56 + run_command(
     57 + &[&pm.unwrap(), "install"],
     58 + &RunOptions {
     59 + current_dir: execute_dir,
     60 + envs: HashMap::new(),
     61 + },
     62 + );
     63 + return;
     64 + }
     65 + 
    45 66   println!("> {}", args.script_name);
    46 67   
    47 68   let result = v
    skipped 50 lines
    98 119   // Alias t to test
    99 120   if script_name == "t" {
    100 121   script_name = "test".to_string();
     122 + }
     123 + 
     124 + // Alias i to install
     125 + if script_name == "i" {
     126 + script_name = "install".to_string();
    101 127   }
    102 128   
    103 129   let args = AppArgs {
    skipped 71 lines
    175 201   
    176 202   let status = Command::new(sh)
    177 203   .arg(sh_flag)
    178  - .args(args)
     204 + .arg(args.join(" "))
    179 205   .envs(&options.envs)
    180 206   .current_dir(&options.current_dir)
    181 207   .status()
    skipped 5 lines
  • ■ ■ ■ ■
    stuff/example-script.js
    1  -console.log("from example")
     1 +console.log("from example", process.argv.slice(2))
    2 2   
Please wait...
Page is in error, reload to recover