Skip to content

Instantly share code, notes, and snippets.

@LuisCardenasSolis
Last active May 20, 2021 05:56
Show Gist options
  • Save LuisCardenasSolis/cf07e2c6eb2aabca463304a69c61fd2d to your computer and use it in GitHub Desktop.
Save LuisCardenasSolis/cf07e2c6eb2aabca463304a69c61fd2d to your computer and use it in GitHub Desktop.
Compile es6 to es5 by command line / Ofuscar codigo - compilado bash script

Install nodejs (npm,npx)

curl -sL https://rpm.nodesource.com/setup_12.x | bash - yum install nodejs -y

Install babel

npm install -g @babel/core @babel/cli @babel/preset-env

Validate

npm list -g --depth=0

/usr/lib
├── @babel/cli@7.10.1
├── @babel/core@7.10.1
├── @babel/preset-env@7.10.1
└── npm@6.14.4

Command run

npx babel index.js --presets /usr/lib/node_modules/@babel/preset-env -d build

Script custom

vim /usr/bin/buildES5

#!/bin/bash
npx babel ${1} --presets /usr/lib/node_modules/@babel/preset-env -d build

chmod u+x /usr/bin/buildES5

#!/bin/bash
FILE=$1
PATH_FILE=${PWD}/$FILE
FILE_COMPILATE=${FILE%.*}
if [ -z "$FILE" ];then
echo "ERROR: Falta el script a compilar"
exit 1
fi
#Dependencias
#yum install shc
#npm install -g bash-obfuscate
echo -n "Ofuscando Codigo: "
cat $PATH_FILE | tail -n +2 > ${PATH_FILE%.*}.bash
bash-obfuscate ${PATH_FILE%.*}.bash -o ${PATH_FILE%.*}.of
rm -f ${PATH_FILE%.*}.bash
sed -i '1i#!/bin/bash' ${PATH_FILE%.*}.of
echo "..done"
#Herramienta : shc
echo "Compilando : ${PATH_FILE}"
shc -v -rf ${PATH_FILE%.*}.of -o "../dist/${FILE_COMPILATE}"
#Clean
rm -f "${PATH_FILE%.*}.of.x.c"
rm -f ${PATH_FILE%.*}.of
echo "=============================="
file "../dist/${FILE_COMPILATE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment