Create React Functional Component (including javascript and css) with just one command "create"
This file contains 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
crc() { | |
if [ -z "$1" ]; then | |
echo "Usage: crc <Component>" | |
return 1 | |
fi | |
file=`echo ${1} | awk '{ print toupper(substr($0, 1, 1)) substr($0, 2) }'` | |
folder=`echo ${1} | awk '{ print tolower(substr($0, 1, 1)) substr($0, 2) }'` | |
if [[ -d ${1} || -d ${folder} || -d ${file} ]]; then | |
echo "Already Exists!" | |
return 1 | |
fi | |
mkdir $folder | |
echo "import React from \"react\"; | |
import \"./${file}.css\"; | |
const ${file} = () => { | |
return ( | |
<div> | |
${file} | |
</div> | |
) | |
} | |
export default ${file};" > ${folder}/${file}.js | |
touch ${folder}/${file}.css | |
echo "export { default as $1 } from \"./${folder}/${file}\"" >> index.js | |
if [[ -d ${folder} ]]; then | |
echo "React functional component ${file} successfully created!" | |
fi | |
} | |
create() { | |
if [ -z $1 ]; then | |
echo "Usage: create <Component1> <Component2> ..." | |
return 1 | |
fi | |
args=( "$@" ) | |
for (( i=1;i<=$#;i++ )) | |
do | |
if [[ "$SHELL" =~ "bash" ]]; then | |
crc ${!i} | |
elif [[ "$SHELL" =~ "zsh" ]]; then | |
crc ${args[i]} | |
else | |
echo "${SHELL} is not supported!" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place that code(which are function definitions) in your main config file like
bash.bashrc
or.bashrc
or.zshrc
. Currently, it only supports bash and zsh. Then use commandcreate <Component1> <Component2>...
to create multiple components by single command.Ex:
create Header Footer Input
This will create 3 folders and 6 files.Or you can also use
crc
command to create single component:crc Header