xpiler
v1.0.7
Published
A lightweight Node.js to executable compiler
Readme
🚀 Xpiler - A Native Node.js Compiler using Go
Xpiler is a native Node.js compiler designed to package JavaScript/Node.js applications into standalone executables. It achieves this by leveraging Go for efficient bundling and execution, similar to how go build works in Go projects.
🟢 Features
- Compile JavaScript/Node.js codebases into standalone executables.
- Cross-platform support for Windows, Linux, and macOS.
- Native compilation using Go, no third-party dependencies.
- Command-line interface (CLI) with versatile options.
🟢 Installation
Clone the repository and build the Go binaries:
# Clone the repo
git clone https://github.com/yourusername/xpiler.git
cd xpiler
# Build Go binaries
chmod +x scripts/build.sh
./scripts/build.sh
# Link the CLI globally (optional)
sudo ln -s "$(pwd)/xpiler.sh" /usr/local/bin/xpiler🟢 Usage
✅ Compile a JavaScript/Node.js Project
xpiler --entry path/to/index.js --output myExecutable✅ CLI Options
| Command | Description |
|------------------------|---------------------------------------------------------|
| --entry, -e | Specify the entry JavaScript file |
| --output, -o | Specify the output executable name |
| --help, -h | Display help information |
| --version, -v | Show the current version |
| --platform, -p | Specify target platform (e.g., linux, windows, macos) |
✅ Examples
- Compile a Node.js script on your current platform:
xpiler --entry src/index.js --output myApp- Show version information:
xpiler --version- Display help menu:
xpiler --help- Cross-compile to another platform (if supported):
xpiler --entry src/index.js --output myApp --platform linux🟢 Project Structure
xpiler/
├── bin/ # Compiled Go binaries
│ ├── xpiler-windows.exe # Windows
│ ├── xpiler-linux # Linux
│ ├── xpiler-macos # macOS
├── src/
│ ├── compiler.js # Main compiler logic
│ ├── go-compiler.go # Go code for bundling and compiling
├── scripts/
│ ├── build.sh # Script to build Go binaries
├── xpiler.sh # CLI script
└── package.json # Package metadata🟢 How Xpiler Works
Entry Point (compiler.js)
- Parses command-line arguments.
- Detects the operating system and selects the appropriate Go binary.
- Calls the Go binary, passing the entry JavaScript file and output executable name.
Go Compiler (go-compiler.go)
- Reads the entry JavaScript file.
- Creates a temporary file in the OS’s temp directory.
- Executes the script using Node.js and bundles it into an executable.
Binary Compilation (build.sh)
- Builds the Go compiler for each target platform (Windows, Linux, macOS).
- Outputs binaries in the
bindirectory.
🟢 Troubleshooting
Permission Issues (Linux/macOS) If you encounter permission errors, ensure the script is executable:
chmod +x xpiler.shMissing Node.js Ensure Node.js is installed and accessible in your PATH.
Unsupported OS If your OS isn’t detected correctly, modify
xpiler.shto handle it manually.
🟢 Limitations
- Requires Node.js to execute the compiled script.
- Cross-compilation may need additional setup (e.g., Go environment variables).
- Not designed for extremely large projects with multiple dependencies.
🟢 Future Enhancements
- Add support for ES6 modules and advanced JavaScript features.
- Implement code obfuscation and minification.
- Support multiple entry points for complex projects.
- Explore embedding a Node.js runtime for fully standalone binaries.
🟢 Contributing
Feel free to submit pull requests or report issues. Contributions are welcome!
🟢 License
Licensed under the MIT License.
