125 lines
3.1 KiB
Markdown
125 lines
3.1 KiB
Markdown
# Reloadd
|
|
|
|
A powerful development tool for automatically restarting your application and reloading your browser when files change.
|
|
|
|
## Features
|
|
|
|
- 🔄 **File Watching**: Monitor multiple directories for changes
|
|
- 🚀 **Auto-Restart**: Automatically restart your application when files change
|
|
- 🌐 **Browser Reload**: Automatically reload connected browsers
|
|
- 🔌 **WebSocket Integration**: Uses WebSockets for instant browser reloading
|
|
- 📊 **Sequential Commands**: Run multiple commands in sequence
|
|
- 🔧 **Configurable Ports**: Customize web server and WebSocket ports
|
|
- 🛠️ **Robust Error Handling**: Clear error messages and graceful recovery
|
|
|
|
## Installation
|
|
|
|
### From Source
|
|
|
|
```bash
|
|
# Clone the repository
|
|
git clone https://github.com/yourusername/reloadd.git
|
|
cd reloadd
|
|
|
|
# Build and install
|
|
cargo install --path .
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Basic Usage
|
|
|
|
```bash
|
|
reloadd --watch src --watch templates -- run --example server
|
|
```
|
|
|
|
### With Sequential Commands
|
|
|
|
```bash
|
|
reloadd --watch src --run "cargo build" --run "cargo test" --run "cargo run --example server"
|
|
```
|
|
|
|
Commands will run in the order specified. All commands except the last one will run to completion. The last command is treated as the long-running server process.
|
|
|
|
### With Custom Port
|
|
|
|
```bash
|
|
reloadd --watch src --port 3000 --run "cargo run --example server"
|
|
```
|
|
|
|
### In a Shell Script
|
|
|
|
Create a `develop.sh` script for your project:
|
|
|
|
```bash
|
|
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Start dev server with file watching and browser reload
|
|
reloadd \
|
|
--watch src \
|
|
--watch templates \
|
|
--port 8080 \
|
|
--run "cargo run --example server"
|
|
```
|
|
|
|
Make it executable and run it:
|
|
|
|
```bash
|
|
chmod +x develop.sh
|
|
./develop.sh
|
|
```
|
|
|
|
## Command Line Options
|
|
|
|
```
|
|
Usage: reloadd [OPTIONS] --watch <PATH>... [-- <COMMAND>...]
|
|
|
|
Arguments:
|
|
[COMMAND]... Command to run on change (legacy format)
|
|
|
|
Options:
|
|
-w, --watch <PATH>... Paths to watch (like src/, templates/, scripts/)
|
|
-p, --port <PORT> Port for the web server [default: 8080]
|
|
-r, --run <COMMAND>... Multiple commands to run
|
|
-h, --help Print help
|
|
-V, --version Print version
|
|
```
|
|
|
|
## LiveReload Integration
|
|
|
|
When you start the tool, it will output a script tag that you can add to your HTML files:
|
|
|
|
```html
|
|
<script>
|
|
const ws = new WebSocket("ws://localhost:35729");
|
|
ws.onmessage = (msg) => {
|
|
if (msg.data === "reload") location.reload();
|
|
};
|
|
</script>
|
|
```
|
|
|
|
Add this script to your HTML templates to enable automatic browser reloading.
|
|
|
|
## How It Works
|
|
|
|
1. Reloadd watches specified directories for file changes
|
|
2. When a change is detected, it runs your commands in sequence
|
|
3. Build commands (all except the last) run to completion before proceeding
|
|
4. The last command (typically a server) runs and stays active
|
|
5. After a brief delay, it sends a reload signal to connected browsers
|
|
6. Browsers with the LiveReload script will automatically refresh
|
|
|
|
## Error Handling
|
|
|
|
Reloadd includes robust error handling:
|
|
|
|
- Validates watch paths before starting
|
|
- Checks for port availability
|
|
- Provides clear error messages
|
|
- Gracefully exits with error codes when critical errors occur
|
|
|
|
## License
|
|
|
|
MIT
|