Comments (4)
Node comes with helpful tool npx
. Just use it.
npx zx scripts/my-script.mjs
from zx.
I am pretty sure you can do a quick user-env install in these steps:
- Use n-install to install
n
: https://github.com/mklement0/n-install. - Run
exec bash -l
or whatever to restart your shell and update the PATH. - Get
n
to installnode
andnpm
:n install latest
- Get
npm
to installzx
: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.
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.
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)
- Why zx instead of Python ? HOT 2
- Markdown script didn't work for CRLF file
- Is Node.js 12.17.0 supported for zx as a package ? HOT 7
- Single file executable?
- Docs: Typo in setup docs
- fetch's document link is wrong HOT 4
- bun compatibility: get rid of async_hooks.createHook call HOT 3
- cannot concatenate strings with ${} HOT 4
- Understanding `zx` roadmap and idea 🙏 HOT 6
- YAML.parseAllDocuments is no longer accessible HOT 10
- Provide better out of the box TypeScript support HOT 4
- Could not resolve "zx/globals.cjs" HOT 4
- Since 8.1.4 YAML.parseAllDocuments is not allowed from zx HOT 9
- Importing this package into CJS project triggers false-positive TypeScript error HOT 4
- [Windows] Escaping doesn't work properly (also impacts zx --install)
- Parsing hexadecimals string as number unintentionally HOT 1
- Misleading documentation HOT 9
- leaks signal listeners in Node.js HOT 5
- Bundled Output Missing core.cjs File When Using esbuild with zx Library HOT 1
- TypeError: dest.on is not a function when using `.pipe` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zx.