Skip to content

Instantly share code, notes, and snippets.

@matt-bailey
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-bailey/22122af72c7be33e3bf6 to your computer and use it in GitHub Desktop.
Save matt-bailey/22122af72c7be33e3bf6 to your computer and use it in GitHub Desktop.
First run set-up shell script for a front-end workflow
#!/bin/bash
# Assumes the following project structure:
#
# myproject/site/.git
# myproject/site/.githooks
# myproject/site/.githooks/pre-commit
# myproject/site/.githooks/post-merge
# myproject/site/.shell
# myproject/site/.shell/frontend-setup.sh (this file)
# myproject/site/public_html
# myproject/site/theme
# Check for dependency presence before attempting to run setup
for dependency in npm ruby sass compass grunt bower
do
if ! which $dependency > /dev/null; then
echo -e "\xe2\x9c\x98 Dependency not found: $dependency"
echo "--- Please install $dependency and try running the setup script again"
exit;
fi
done
# Check if we're in the same directory as `.shell`
directory=".shell"
if [ ! -d "$directory" ]
then
echo "--- Please run this shell file from the project root (site)"
exit
else
echo "--- Running initial setup..."
fi
# Check if pre-commit symlink exists and if not, create it
file=".git/hooks/pre-commit"
if [ -h "$file" ]
then
echo -e "\xe2\x9c\x93 pre-commit git hook symlink already exists"
echo "--- Moving on..."
else
echo "--- Creating pre-commit git hook symlink..."
(cd .git/hooks; ln -s ../../.githooks/pre-commit pre-commit)
echo -e "\xe2\x9c\x93 Pre-commit git hook symlink created"
echo "--- Setting execute permissions on pre-commit git hook..."
(cd .githooks; chmod +x pre-commit)
echo -e "\xe2\x9c\x93 Execute permissions on pre-commit git hook set"
fi
# Check if post-merge symlink exists and if not, create it
file=".git/hooks/post-merge"
if [ -h "$file" ]
then
echo -e "\xe2\x9c\x93 post-merge git hook symlink already exists"
echo "--- Moving on..."
else
echo "--- Creating post-merge git hook symlink..."
(cd .git/hooks; ln -s ../../.githooks/post-merge post-merge)
echo -e "\xe2\x9c\x93 Post-merge git hook symlink created"
echo "--- Setting execute permissions on post-merge git hook..."
(cd .githooks; chmod +x post-merge)
echo -e "\xe2\x9c\x93 Execute permissions on post-merge git hook set"
fi
# `npm install` and `npm prune` if the `package.json` file gets changed
echo "--- Installing Node packages..."
(cd theme; npm install && npm prune)
echo -e "\xe2\x9c\x93 Node packages installed"
# `bower install` and `bower prune` if the `bower.json` file gets changed
echo "--- Installing Bower components..."
(cd theme; bower install --allow-root && bower prune --allow-root)
echo -e "\xe2\x9c\x93 Bower components installed"
# Run the build process `grunt`
echo "--- Running the build process..."
(cd theme; grunt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment