Created
April 19, 2023 16:02
-
-
Save wevertoum/eca99c9a1a2412a8ad1fc8d9b9eed89b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
function createComponent() { | |
COMPONENT_NAME="$1" | |
FILE_TYPE="$2" | |
if [ -z "$COMPONENT_NAME" ]; then | |
echo "Component name missing. Please provide a name." | |
exit 1 | |
fi | |
if [ ! -d "src/components" ]; then | |
echo "The directory src/components does not exist. Please create it first." | |
exit 1 | |
fi | |
mkdir "src/components/$COMPONENT_NAME" | |
touch "src/components/$COMPONENT_NAME/$COMPONENT_NAME.tsx" | |
touch "src/components/$COMPONENT_NAME/$COMPONENT_NAME.$FILE_TYPE" | |
touch "src/components/$COMPONENT_NAME/index.tsx" | |
if [ "$FILE_TYPE" == "less" ]; then | |
echo "import React from 'react'; | |
require('./$COMPONENT_NAME.less'); | |
interface Props {} | |
const $COMPONENT_NAME: React.FC<Props> = () => { | |
return <>$COMPONENT_NAME is ready</>; | |
}; | |
export default $COMPONENT_NAME;" >"src/components/$COMPONENT_NAME/$COMPONENT_NAME.tsx" | |
echo "export { default } from './$COMPONENT_NAME';" >"src/components/$COMPONENT_NAME/index.tsx" | |
elif [ "$FILE_TYPE" == "scss" ]; then | |
echo "import React from 'react'; | |
import './$COMPONENT_NAME.scss'; | |
interface Props {} | |
const $COMPONENT_NAME: React.FC<Props> = () => { | |
return <>$COMPONENT_NAME is ready</>; | |
}; | |
export default $COMPONENT_NAME;" >"src/components/$COMPONENT_NAME/$COMPONENT_NAME.tsx" | |
echo "export { default } from './$COMPONENT_NAME';" >"src/components/$COMPONENT_NAME/index.tsx" | |
else | |
echo "Invalid file type. Please use 'less' or 'scss'." | |
exit 1 | |
fi | |
echo "Component $COMPONENT_NAME created!" | |
} | |
createComponent "$1" "$2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to create React/Next js component in src/components/ in root directory, type
or