JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q36808F
  • License MIT

Turn javascript code into shellscript

Package Exports

  • js-to-sh
  • js-to-sh/globals
  • js-to-sh/loader

Readme

Transpiler Js to Sh

license-info stars-infoa

Last-Comitt Comitts Year reposize-info

๐Ÿคจ | 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"