Skip to content

Instantly share code, notes, and snippets.

@benvanik
Created October 1, 2012 21:03
Show Gist options
  • Save benvanik/3814397 to your computer and use it in GitHub Desktop.
Save benvanik/3814397 to your computer and use it in GitHub Desktop.
anvil-build javascript project bootstrap
#!/bin/bash
# Copyright 2012 Google Inc. All Rights Reserved.
# anvil-build unix bootstrap script
# This script prepares a new anvil-build based project by performing a lot of
# the boring skeleton work of preparing a new repo. It is designed to be used
# on empty paths.
#
# usage: anvil-bootstrap.sh projectname namespace copyright
# example: anvil-bootstrap.sh my-project mp "Google, Inc"
#
# Requires:
# - All:
# - Git 1.7.5+
# - Python 2.6+
# - Python easy_install: http://pypi.python.org/pypi/setuptools
# TODO(benvanik): check git
# ==============================================================================
# Grab arguments
# ==============================================================================
echo "Preparing to generate project..."
PROJECT_NAME=$1
PROJECT_NAMESPACE=$2
AUTHOR_NAME=`git config --get user.name`
AUTHOR_EMAIL=`git config --get user.email`
COPYRIGHT=$3
echo ""
echo "Setting up an anvil-build project:"
echo " Project name: $PROJECT_NAME"
echo " Namespace: $PROJECT_NAMESPACE"
echo " Author name: $AUTHOR_NAME (from git user.name)"
echo " Author email: $AUTHOR_EMAIL (from git user.email)"
echo " Copyright: $COPYRIGHT"
echo " Path: ./$PROJECT_NAME/"
echo ""
read -p "Continue? (y/N) " -n 1
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
echo ""
# ==============================================================================
# Check for Python/node/etc
# ==============================================================================
echo "Checking for dependencies..."
echo "- Python 2.6+:"
if [ ! -e "$(which python)" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "! Python not found or not in PATH - at least version 2.6 is required !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 1
fi
PYTHON_CHECK=`python -c 'import sys; print(sys.version_info >= (2, 6) and "1" or "0")'`
PYTHON_VERSION=`python -c 'import sys; print(sys.version_info[:])'`
if [ "$PYTHON_CHECK" = "0" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "! Python is out of date - at least version 2.6 is required !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Your version: $PYTHON_VERSION"
exit 1
fi
echo " path: $(which python)"
echo " version: $PYTHON_VERSION"
echo "- Python easy_install:"
if [ ! -e "$(which easy_install)" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "! easy_install not found or not in PATH !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Grab the latest version from: http://pypi.python.org/pypi/setuptools"
exit 1
fi
echo " path: $(which easy_install)"
echo "- node.js 0.6.14+:"
if [ ! -e "$(which node)" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "! node.js not found or not in PATH - at least version 0.6.10 is required !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Grab the latest version from: http://nodejs.org/#download"
exit 1
fi
NODE_CHECK=`node -e "var v = process.version.split('v')[1].split('.'); console.log(v[0] > 0 || v[1] > 6 || v[2] >= 14)"`
NODE_VERSION=`node -e "console.log(process.version)"`
if [ "$NODE_CHECK" = "false" ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "! node.js is out of date - at least version 0.6.14 is required !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Your version: $NODE_VERSION"
echo "Grab the latest version from: http://nodejs.org/#download"
exit 1
fi
echo " path: $(which node)"
echo " version: $NODE_VERSION"
echo ""
# ==============================================================================
# Create git repo
# ==============================================================================
echo "Creating git repo..."
mkdir $PROJECT_NAME
cd $PROJECT_NAME
git init
echo ""
# ==============================================================================
# Fetch skeleton project
# ==============================================================================
echo "Fetching skeleton project..."
wget \
-nv \
-O anvil-js-skeleton-scratch.tgz \
https://github.com/benvanik/anvil-js-skeleton/tarball/master
tar zxf anvil-js-skeleton-scratch.tgz
rm anvil-js-skeleton-scratch.tgz
SCRATCH_PATH=`ls -1 | grep *-anvil-js-skeleton*`
cp -R $SCRATCH_PATH/* .
cp -R $SCRATCH_PATH/.git* .
rm -r $SCRATCH_PATH
echo ""
# ==============================================================================
# Move things into place
# ==============================================================================
echo "Rearranging..."
mv projrc ${PROJECT_NAMESPACE}rc
mv src/proj/proj.js src/proj/${PROJECT_NAMESPACE}.js
mv src/proj src/${PROJECT_NAMESPACE}
echo ""
# ==============================================================================
# Templating
# ==============================================================================
echo "Templating..."
perl -e "s/{<ANVIL_PROJECT_NAME>}/$PROJECT_NAME/g;" -pi $(find . -type f)
perl -e "s/{<ANVIL_PROJECT_NAMESPACE>}/$PROJECT_NAMESPACE/g;" -pi $(find . -type f)
perl -e "s/{<ANVIL_AUTHOR_NAME>}/$AUTHOR_NAME/g;" -pi $(find . -type f)
perl -e "\$em='$AUTHOR_EMAIL';s/{<ANVIL_AUTHOR_EMAIL>}/\$em/g;" -pi $(find . -type f)
perl -e "s/{<ANVIL_COPYRIGHT>}/$COPYRIGHT/g;" -pi $(find . -type f)
echo ""
# ==============================================================================
# Add to git index
# ==============================================================================
echo "Adding to git..."
git add -A .
echo ""
# ==============================================================================
# Setup submodules
# ==============================================================================
echo "Setting up submodules..."
git submodule init
# TODO(benvanik): pull from .gitmodules from the source
rm .gitmodules
rm -rf third_party/anvil-build
rm -rf third_party/closure-library
rm -rf third_party/closure-compiler
rm -rf third_party/closure-templates
rm -rf third_party/closure-stylesheets
rm -rf third_party/closure-linter
git submodule add \
https://github.com/benvanik/anvil-build.git \
third_party/anvil-build
git submodule add \
https://github.com/jarib/google-closure-library.git \
third_party/closure-library
git submodule add \
https://github.com/benvanik/google-closure-compiler-bin.git \
third_party/closure-compiler
git submodule add \
https://github.com/benvanik/google-closure-templates-bin.git \
third_party/closure-templates
git submodule add \
https://github.com/benvanik/google-closure-stylesheets-bin.git \
third_party/closure-stylesheets
git submodule add \
https://github.com/knutwalker/google-closure-linter.git \
third_party/closure-linter
echo ""
# ==============================================================================
# Commit first change
# ==============================================================================
echo "Committing..."
git commit -m "Initial skeleton from anvil-js-skeleton."
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment