Giter Club home page Giter Club logo

Comments (4)

antonmedv avatar antonmedv commented on May 3, 2024 7

Node comes with helpful tool npx. Just use it.

npx zx scripts/my-script.mjs

from zx.

Artoria2e5 avatar Artoria2e5 commented on May 3, 2024

I am pretty sure you can do a quick user-env install in these steps:

  1. Use n-install to install n: https://github.com/mklement0/n-install.
  2. Run exec bash -l or whatever to restart your shell and update the PATH.
  3. Get n to install node and npm: n install latest
  4. Get npm to install zx: npm install -g zx

All that can be put into a install-zx.sh script, yes. But it into a line at the top is very questionable practice, since it downloads stuff without asking you. On top of that, you will need special magic to deal with the extra arguments in shebang as it varies by system. That said, if you still want to try...

#!/usr/bin/env -S sh -c 'if ! command -v zx &>/dev/null; curl install-zx.sh | sh; PATH+=":$HOME/n/bin"; fi; exec zx "$@"'

// Usual zx stuff

(Oh, did I mention that the long line might break things too? See https://www.in-ulm.de/~mascheck/various/shebang/#solutionsforlonglines. But then you get another dependency, and that's what we've been trying to avoid all the time...)

from zx.

biels avatar biels commented on May 3, 2024

But it into a line at the top is very questionable practice, since it downloads stuff without asking you.

Gradle is doing it though. Gradle downloads a copy of its binary (gradle daemon) if it can't find it and then runs using it. It downloads a copy on the local folder by default. This makes it portable to any system without any instructions. It even creates scripts for windows and linux by default (a .sh and a .bat).

I think you should be reading any scripts before executing them so really not anything unexpected is happening.

from zx.

Artoria2e5 avatar Artoria2e5 commented on May 3, 2024

The gradle wrapper requires not just gradlew.bat to run -- it also needs a gradle-wrapper.jar. On top of that, the behavior of gradle is not defined using the wrapper itself, but using a bunch of other config files. If settings.gradle somehow includes the whole of gradlew that would be an okay analogue.

Still, having an install script can help with easy deployment, and shipping that with a zx script is totally cool. It's just fitting it into the shebang isn't much of a good idea. (We could also not fit it in there but instead use the run-by-shell fallback of many sh shells. That doesn't make it any better IMO.)

from zx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.