Skip to content

Instantly share code, notes, and snippets.

@MrJackdaw
Last active May 29, 2018 16:32
Show Gist options
  • Save MrJackdaw/655fe49d219650bc9a1ca72490ec7fd0 to your computer and use it in GitHub Desktop.
Save MrJackdaw/655fe49d219650bc9a1ca72490ec7fd0 to your computer and use it in GitHub Desktop.
#!//bin/bash
# Helper script to install and initialize @jackcom libraries and subdirectories
# after create-react-app install. `chmod 700` and run from app's `package.json` layer.
#
# Note: Installs @jackcom/raphsducks and @jackcom/app-network-layer
function makeIndexFile {
if [ ! -e $1 ]
then
# create index.js file in specified directory
echo 'Making index.js in' $1
cd $1 && touch index.js
else
echo 'index.js exists in $1 directory: skipping'
fi
return 0
}
function makeSubdirectories {
for directory in $1
do
if [ ! -e $directory ]
then
mkdir $directory
else
echo 'Directory $directory exists: skipping'
fi
done
return 0
}
# 1. create directories [resources/services/state] inside src/
cd src/ && makeSubdirectories 'resources services state' &&
# 2. make default subdirectories for UI resources
cd resources/ && makeSubdirectories 'styles images' &&
# 3. make `index.js` files in JS modules
makeIndexFile '../services' &&
makeIndexFile '../state' &&
# 4. navigate back to package.json layer and install required libraries
clear && echo 'All JackCom subdirectories created. Installing @jackcom libraries...'
cd ../../ && npm install --save @jackcom/raphsducks @jackcom/app-network-layer &&
# clear and update
clear && echo 'JackCom libraries installed. Initializing React...'
# Run app
npm start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment