Last active
October 17, 2021 20:24
-
-
Save Charlie-robin/77e7886c1c730ae606cbf73bb52b944e to your computer and use it in GitHub Desktop.
This creates React boilerplate, it will create .jsx & .scss files in the src inside the given folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This creates React boilerplate | |
# This script takes two arguments folder & files | |
# It will create .jsx & .scss files in the src inside the given folder | |
# Have the file in the root project directory & run | |
# ./create.sh folderName fileName | |
echo "Create $2 jsx & scss files in the $1 folder? Y/N" | |
read answer | |
lowerAnswer=$(echo "$answer" | tr '[:upper:]' '[:lower:]') | |
if [ $lowerAnswer = "n" ] || [ $lowerAnswer = "no" ] | |
then | |
echo "Exiting script" | |
exit | |
fi | |
if [ ! -d "./src/$1" ] | |
then | |
echo "creating $1 folder" | |
mkdir ./src/$1 | |
fi | |
if [ ! -d "./src/$1/$2" ] | |
then | |
echo "creating $2 folder" | |
mkdir ./src/$1/$2 | |
fi | |
touch ./src/$1/$2/$2.jsx ./src/$1/$2/$2.scss | |
lower=$(echo "$2" | sed 's/[[:upper:]]/-&/g;s/^-//' | tr '[:upper:]' '[:lower:]') | |
cat << EOF > ./src/$1/$2/$2.jsx | |
import React from 'react'; | |
import "./$2.scss"; | |
const ${2} = () => { | |
return <div className="$lower">$2 works</div>; | |
}; | |
export default $2; | |
EOF | |
cat << EOF > ./src/$1/$2/$2.scss | |
.$lower { | |
} | |
EOF | |
echo "Script Completed :)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment