technomancy / leiningen

Moved to Codeberg; this is a convenience mirror
https://codeberg.org/leiningen/leiningen
Other
7.29k stars 1.61k forks source link

How to run directly without any associated alias? #1844

Closed binarykitchen closed 2 years ago

binarykitchen commented 9 years ago

Hello again

I have this configuration here:

  :aliases
  {
    "run"         ["do" ["shell" "gulp"] "run"]
    "jar"         ["do" ["shell" "gulp"] "jar"]
    "uberjar"     ["do" ["shell" "gulp"] "uberjar"]
    "redline-rpm" ["do" ["shell" "gulp"] "redline-rpm"]
    "release"     ["do" ["shell" "gulp"] "release"]

    "dev"   ["pdo" "run" ["shell" "gulp-dev" "watch"]]
    "test"  ["shell" "gulp" "test"]

    "deps"  ["do" "deps" ["npm" "prune"]]
  }

  :shell
  {:commands
    {
      "gulp"     {:default-command "node_modules/.bin/gulp"}
      "gulp-dev" {:default-command "node_modules/.bin/gulp" :env {"DEV" "true"}}
    }
  }

You see that I am running gulp first for some commands. But the problem is within the dev alias, where I call run together with gulp-dev whereas the run will trigger the run alias which will run gulp.

How can I call run inside the dev alias without the associated alias?

hypirion commented 9 years ago

I think the easiest is to just name the run alias something else :)

But considering you're doing a lot of repeated work for each task, maybe you should have a look at :prep-tasks and profile merging (with-profile). The profiles documentation has some notes on how you could potentially do it.

binarykitchen commented 9 years ago

Naming the run alias to something else won't solve it because I want to run Gulp tasks before the infamous lein run. But when running in development mode, i.E. with lein dev I want to run different Gulp tasks before lein run. That's the problem.

I cannot use :prep-tasks to solve this because they are always executed, no matter what lein command you are picking. Would be nice to have prep-tasks selective per command.

(profiles, nice but that would add more complexity we want to avoid)

hypirion commented 9 years ago

I'll see if there's any way to do this with pure lein, but it's not on my top priority right now. I'll keep it open though, as it's probably enough interest to find a general solution to something like this.

jvandyke commented 9 years ago

@binarykitchen You probably figured this out already, but to anyone else who comes across this the answer is in the do syntax. You must separate the tasks to want to run in an alias with a comma. Like so from command line:

$ lein do shell gulp, jar

But of course, Clojure arrays don't care about commas, so the comma must be added inside the quotes. In an example where you want to run lein shell gulp then lein jar you'd write:

:aliases {
  jar ["do" "shell" "gulp," "jar"]
}

The do task documentation is very sparse, but here's what I could find: https://github.com/technomancy/leiningen#basic-usage

binarykitchen commented 9 years ago

thx, this is good, works for me (yes, have figured that out)

darwin commented 8 years ago

Today I wanted to do a similar thing. My problem is the checkouts feature. I have to run lein jar, lein install, lein uberjar (and similar) without checkouts directory if present (checkout projects are causing troubles in my own project.clj because their lein plugins get automatically included in my project). I wish I could disable it on per-profile basis, but unfortunately Iein does not have such an option. So I wanted to define aliases which would wrap lein invocation with a simple bash script, which would move checkout out and then move it back. But I hit this same issue of 'How to invoke original task without aliases being applied?'

Fortunately turns out there exists a solution using :profiles and lein-shell plugin for the price of nested lein invocation (which I'm willing to pay):

:profiles {:nuke-aliases {:aliases ^:replace {}}}
:plugins [[lein-shell "0.4.2"]]
:aliases { jar ["shell" "scripts/lein-without-checkouts.sh" "jar"] }

where scripts/lein-without-checkouts.sh does something like this:

lein with-profile "+nuke-aliases" "$@"

The actual script is here: https://github.com/binaryage/dirac/blob/master/scripts/lein-without-checkouts.sh

technomancy commented 2 years ago

It sounds like we have a solution for this.