jsrun-cli
v0.1.1
Published
A lightweight CLI tool for running JavaScript, TypeScript, and .jsr scripts with automatic dependency management.
Downloads
121
Maintainers
Readme
JSRUN
The ultimate CLI tool for effortlessly running JavaScript, TypeScript, and .jsr
scripts.
⚡ Focus on coding, let JSRUN handle the rest! ⚡
✨ Features
- Automatic Module Management: Automatically installs missing dependencies.
- Version Control: Specify version numbers directly in your imports.
- Caching for Speed: Locally cached modules reduce installation time.
- Colorful Logging: Clear, colorful logs powered by
chalk
. - Error Handling: Comprehensive error messages for easy troubleshooting.
- Extendable: Customizable and ready for expansion.
🔧 Installation
Prerequisites
- Node.js: Ensure you're using Node.js version 14 or higher. Get Node.js here.
Install via npm
npm install -g jsrun-cli
🚀 Usage
Run a Script
Run any script supported by JSRUN:
jsrun myscript.jsr
Supported extensions: .jsr
, .js
, .mjs
, .ts
.
Import Modules with Versions
import express from "[email protected]";
import chalk from "[email protected]";
console.log(chalk.green("Starting server..."));
const app = express();
app.get("/", (req, res) => res.send("Hello World!"));
app.listen(3000, () => console.log(chalk.blue("Server running on port 3000")));
Run the script:
jsrun server.jsr
Pass Arguments to Your Script
jsrun myscript.jsr --port=4000 --env=production
Inside your script:
const args = process.argv.slice(2);
const port =
args.find((arg) => arg.startsWith("--port="))?.split("=")[1] || 3000;
const env =
args.find((arg) => arg.startsWith("--env="))?.split("=")[1] || "development";
console.log(`Running on port ${port} in ${env} mode.`);
🧹 Clean Installed Packages
jsrun --clean
🎯 Key Features Explained
- Performance Caching: Caches modules locally in
~/.jsrun/node_modules
to speed up subsequent runs. - Colorful Logging: Uses
chalk
for colored feedback (Green for success, Yellow for warnings, Red for errors, and Blue for status). - Error Handling: Gives detailed error messages, simplifying debugging and fixing issues.
📝 Why JSRUN?
JSRUN was created to make running JavaScript and TypeScript scripts with modules a breeze, without the hassle of managing node_modules
. Instead of manually installing packages every time, JSRUN handles everything for you. It installs the necessary dependencies automatically, allowing you to create and run executable scripts from anywhere with minimal setup.
No more worrying about how to manage node_modules
just focus on writing and running your scripts, and let JSRUN take care of the rest!
📂 Examples
Explore the /examples
directory for use cases and .jsr
script examples.
🛠️ Troubleshooting
Common Issues
- Module Not Found: Ensure module names and versions are correct.
- Permission Denied: Use elevated privileges or adjust the ownership of the
~/.jsrun
folder. - Syntax Errors: Verify that your JavaScript/TypeScript syntax is correct. Use the appropriate Node.js version.
- Network Problems: Check your network connection or try manually installing the module.
❓ FAQ
Why
.jsr
?.jsr
highlights scripts specifically made forjsrun
.Can I use
.js
files?
Yes,.js
files are supported, but.jsr
is recommended for clarity.Where are modules installed?
In the cache directory~/.jsrun/node_modules
.How do I update
jsrun
?
Runnpm update -g jsrun-cli
.
🤝 Contributing
- Fork the repo
- Create a new branch
- Make your changes
- Push your branch
- Submit a Pull Request
📜 License
jsrun
is licensed under the MIT License.
✉️ Contact
Have questions or feedback? Check out our GitHub page.
📚 Documentation en Français
Pour la documentation en français, consultez ce lien.