shelljs-transpiler
raw JSON → 0.2.6 verified Fri May 01 auth: no javascript
Translate Bash scripts to ShellJS (shelljs) code. Current stable version is 0.2.6, with a pre-1.0 release cadence. It supports both a web interface and a CLI tool `sh2js`. Unlike manual porting, it automates conversion of common Bash constructs to ShellJS API calls. Notable limitations: not all Bash syntax is handled until v1.0; translations may rely on unimplemented ShellJS features. The tool is experimental and community-driven, with limited maintenance.
Common errors
error SyntaxError: Unexpected token ↓
cause Input Bash script contains unsupported syntax.
fix
Simplify the script or report the issue.
error TypeError: transpile is not a function ↓
cause Incorrect import: using CJS require instead of ESM import.
fix
Use
import { transpile } from 'shelljs-transpiler'. error sh2js: command not found ↓
cause ShellJS-transpiler not installed globally or not in PATH.
fix
Install globally:
npm install -g shelljs-transpiler or use npx sh2js. error Error: Plugin not found ↓
cause Specified plugin name is misspelled or not installed.
fix
Check plugin name and ensure it is installed as a npm package.
Warnings
breaking Some Bash syntax may not be handled until v1.0. ↓
fix File an issue on GitHub with your failing script.
gotcha Translated scripts may depend on ShellJS features not yet implemented. ↓
fix Check the output and manually adjust to use existing ShellJS API.
deprecated The CLI tool `sh2js` is experimental and may change. ↓
fix Use npx to run the latest version or install globally.
gotcha Plugin system via `--plugins` is experimental and may not work as expected. ↓
fix Avoid using plugins until stable.
breaking Requires Node.js >= 8 for ES6 features. ↓
fix Upgrade Node.js or use a transpiler like Babel.
Install
npm install shelljs-transpiler yarn add shelljs-transpiler pnpm add shelljs-transpiler Imports
- sh2js wrong
npm run sh2js script.sh output.jscorrectnpx sh2js script.sh output.js - transpile wrong
const { transpile } = require('shelljs-transpiler')correctimport { transpile } from 'shelljs-transpiler' - default export wrong
const shelljsTranspiler = require('shelljs-transpiler')correctimport shelljsTranspiler from 'shelljs-transpiler' - ShellJS
import { ShellJS } from 'shelljs-transpiler'
Quickstart
import { transpile } from 'shelljs-transpiler';
const bashScript = 'echo hello; ls -la';
const shelljsCode = transpile(bashScript);
console.log(shelljsCode);
// Output: 'console.log("hello");\nshell.ls("-la");'