Projects STRLCPY dum Commits 08fd4504
🤬
  • feat: replace `npm run` `yarn` in npm scripts with `dum`

  • Loading...
  • EGOIST committed 2 years ago
    08fd4504
    1 parent 8f6335e6
  • ■ ■ ■ ■
    package.json
    1 1  {
    2 2   "scripts": {
    3 3   "foo": "node stuff/example-script",
    4  - "test": "echo \"hello test\"",
     4 + "test": "echo \"hello test\" && npm run foo -- arg",
    5 5   "build-mac": "cargo build --release --target x86_64-apple-darwin && cargo build --release --target aarch64-apple-darwin",
    6 6   "build-win": "cargo build --release --target x86_64-pc-windows-msvc",
    7 7   "build-lin": "cargo build --release --target x86_64-unknown-linux-gnu cargo build --release --target armv7-unknown-linux-gnueabihf"
    skipped 3 lines
  • ■ ■ ■ ■ ■ ■
    src/args.rs
    skipped 31 lines
    32 32   let arg = args_iter.next();
    33 33   match arg {
    34 34   Some(v) => {
     35 + if v == "--" {
     36 + args.forwarded.push_str(" ");
     37 + args.forwarded
     38 + .push_str(args_iter.as_slice().join(" ").as_str());
     39 + break;
     40 + }
    35 41   if v.starts_with("-") {
    36 42   if args.script_name.is_empty()
    37 43   && (args.command.is_empty() || args.command == "run")
    skipped 130 lines
  • ■ ■ ■ ■ ■ ■
    src/run.rs
    skipped 84 lines
    85 85   None
    86 86  }
    87 87   
     88 +// Replace npm run / yarn / pnpm run with `dum`
     89 +fn replace_run_commands(script: &str) -> String {
     90 + let mut dum = "dum";
     91 + let mut dum_run = "dum run";
     92 + if cfg!(debug_assertions) {
     93 + dum = "target/debug/dum";
     94 + dum_run = "target/debug/dum run";
     95 + }
     96 + script
     97 + .replace("npm run", dum_run)
     98 + .replace("yarn run", dum_run)
     99 + .replace("pnpm run", dum_run)
     100 + .replace("npx", dum)
     101 + .replace("pnpx", dum)
     102 + .replace("yarn", dum)
     103 +}
     104 + 
    88 105  pub fn run(app_args: &args::AppArgs) {
    89 106   if args::COMMANDS_TO_FORWARD.contains(&app_args.command.as_str()) {
    90 107   debug!("Running command {}", app_args.command);
    skipped 100 lines
    191 208   Some(script.unwrap_or_default())
    192 209   });
    193 210   if npm_script.is_some() {
    194  - let script = npm_script.unwrap();
     211 + let script = replace_run_commands(&npm_script.unwrap());
    195 212   println!(
    196 213   "{} {}",
    197 214   Purple.dimmed().paint("$"),
    skipped 40 lines
Please wait...
Page is in error, reload to recover