Created
June 26, 2020 09:07
-
-
Save jhamberg/625ad981d79bf58002db430c6225b652 to your computer and use it in GitHub Desktop.
Script for preparing and debloating React projects
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
#!/usr/bin/env bash | |
# Small convenience script for preparing a React project | |
# (C) 2019 - Jonatan Hamberg | |
copy_if_present() { | |
if [ -e "$1" ] && [ -e "$2" ]; then | |
cp "$1" "$2" | |
fi | |
} | |
# Check arguments | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 [PROJECT]" | |
exit 1 | |
fi | |
# Verify target exists | |
if [ ! -e "$1/package.json" ]; then | |
echo "Error: $1 is not a valid project!" | |
exit 1 | |
fi | |
# Copy custom template files | |
copy_if_present ".eslintrc.js" "$1/" | |
copy_if_present "App.js" "$1/src/" | |
copy_if_present "index.js" "$1/src/" | |
# Change work directory | |
pushd "$1" > /dev/null | |
# Remove git repository | |
if [ -e ".git" ]; then | |
rm -rf .git | |
fi | |
# Remove unnecessary files | |
rm README.md | |
rm src/App.css | |
rm src/App.test.js | |
rm src/logo.svg | |
rm src/serviceWorker.js | |
# Install plugins | |
npm i -D eslint-plugin-react | |
npm i -D eslint-plugin-jest | |
npm i -D babel-eslint | |
npm i -D jest-dom | |
npm i -D react-testing-library | |
# Install linter | |
if [ -e ".eslintrc.js" ]; then | |
npm i -D eslint | |
else | |
npx eslint --init | |
fi | |
# Restore work directory | |
popd > /dev/null | |
echo "Success!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment