Package Exports
- js-to-sh
- js-to-sh/globals
- js-to-sh/loader
Readme
Transpiler Js to Sh
๐คจ | What's that?
This project uses ATS (abstract syntax tree) to format the javascript for shellscript syntax, but errors can happen, don't expect it to always work, for example, classes are converted to functions for their operation, but more complex things have not yet been implemented and may not work, if you want to help open a pull request!
๐คทโโ๏ธ | Why did you do that?
With a deficit in generating high-performance, easy-to-maintain shell scripts, I decided to create this project. Of course, it's still in development and, for the time being, it's just a big improvisation, but I hope I don't leave any bugs behind!
๐ฅ | Installation
Installing this package is as easy as using it. Just run:
npm i -g js-to-sh
# OR
npm i js-to-sh๐ | How to use
๐ | Terminal:
js-to-sh -f src/test.ts -o test.sh
# OR
npx tjss -f src/test.ts -o test.sh๐ | Help
Usage: tjss [options]
Options:
-D --debug Activates debug mode.
-d --dir Directory for fetching and transpiling .js files
-f --file File to be transpiled.
-o --output Output directory or file to save the transpiled files.๐จโ๐ป | Code:
โ ๏ธ | Warning: Currently only use this package in projects that support ESM natively, it won't work with commonjs (CJS)!
import 'js-to-sh/loader' // this should be in the main file of your project
import { Transpiler } from 'js-to-sh'
const AST = await new Transpiler({ path: 'src/test.ts' }).loader()
const code = Transpiler.parser(AST)
console.log(code)๐ก | Example
Input:
function some (num1, num2) {
return num1 + num2
}
function someString (str1, str2) {
return `${str1} ${str2}`
}
const result = some(1, 2)
console.log(string('teste', 'teste'))
console.log(result)Output:
#!/bin/bash
function some() {
local num1=$1
local num2=$2
echo "$(( "$num1" + "$num2" ))"
}
function someString() {
local str1=$1
local str2=$2
echo ""$str1" "$str2""
}
result=$(some 1 2)
echo "$(string teste teste)"
echo "$result"