-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92ea5e0
commit dae04ae
Showing
4 changed files
with
101 additions
and
38 deletions.
There are no files selected for viewing
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
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,63 +3,118 @@ | |
# Exit with nonzero exit code if anything fails | ||
set -e | ||
|
||
# ------------------------------------------------------------------------------ | ||
# CONFIGURE SCRIPT | ||
# ------------------------------------------------------------------------------ | ||
|
||
#set our source and traget branches | ||
# Set our source branch (where we'll build from) and our target branch (where we | ||
# want to send the build page to) | ||
SOURCE_BRANCH="master" | ||
TARGET_BRANCH="gh-pages" | ||
REPO=`git config remote.origin.url` | ||
|
||
#pull requests and commits to other branches shouldn't try to deploy | ||
# Prep git credentials | ||
GIT_USER_NAME="Travis CI" | ||
GIT_USER_EMAIL="[email protected]" | ||
GIT_COMMIT_MESSAGE="[Travis] Rebuild documentation for Github Pages" | ||
|
||
# Check if we should run a deploy, or if we should skip it. Only commits to master | ||
# should trigger a build. Pull requests and commits to features branches should not. | ||
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then | ||
echo "Skipping deploy; just doing a build." | ||
exit 0 | ||
fi | ||
|
||
#create a temp directory that will store the bower.json file | ||
# ------------------------------------------------------------------------------ | ||
# PREPARE FILESYSTEM | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Create a temp directory that will store the bower.json file | ||
mkdir tmp_bower | ||
|
||
#clone this repo, and go into that folder. | ||
# Clone this repo, and go into that folder | ||
git clone ${REPO} ghp_tmp | ||
cd ghp_tmp | ||
|
||
#find out our repo name from the bower file | ||
# Find out our repo name from the bower file | ||
REPO_NAME=$(grep "name" bower.json | sed 's/"name": "//' | sed 's/",//') | ||
echo "repo name is ${REPO_NAME}" | ||
|
||
#set up our variables and configs | ||
git config user.name "Travis CI" | ||
git config user.email "[email protected]" | ||
|
||
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:} | ||
|
||
#copy the bower.json file out of the directory to a temp one | ||
# Copy the bower.json file out of the directory to a temp one | ||
cp bower.json ../tmp_bower/bower.json | ||
#and checkout gh-pages - create it if it doesn't exist. | ||
# ... and checkout gh-pages - create it if it doesn't exist. | ||
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH | ||
# ... and copy the bower.json file from our temp directory into the current one, overriding it, and passing a yes in there's a prompt | ||
yes | cp ../tmp_bower/bower.json bower.json | ||
|
||
#pull to ensure this is the latest one. | ||
git pull origin gh-pages | ||
# Overwrite whatever is in root .bowerrc to force installation of bower packages at the root | ||
rm -f .bowerrc | ||
echo "{ \"directory\": \".\" }" > .bowerrc | ||
|
||
#copy the bower.json file from our temp directory into the current one, overriding it, and passing a yes in there's a prompt | ||
yes | cp ../tmp_bower/bower.json bower.json | ||
# Overwrite whatever is in root `index.html` to create the redirect | ||
# Note: We are not overwriting the component's documentation `index.html` file | ||
# here, we are making sure that http://url/px-something/ redirects to | ||
# http://url/px-something/px-something/, where the demo page is installed | ||
rm -f index.html | ||
meta_temp='<META http-equiv=refresh content="0;URL=COMPONENT_NAME/">' | ||
echo ${meta_temp/'COMPONENT_NAME'/$REPO_NAME} > index.html | ||
|
||
#install your new tag through bower, it will fail without forcing it. | ||
# Install your new tag through bower (use --force because it will fail without forcing it) | ||
bower install ${REPO_NAME} --force | ||
# @DARK_THEME: Force install px-dark-theme (to generate dark-theme demos) | ||
bower install px-dark-theme --force | ||
|
||
# ------------------------------------------------------------------------------ | ||
# BUILD PROJECT | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Go into the component folder we've just installed from bower | ||
cd ${REPO_NAME} | ||
|
||
# @DARK_THEME: Copy `index.html` to new file, where we will add dark theme | ||
yes | cp index.html index-dark.html | ||
|
||
#optimize for production | ||
cd ${REPO_NAME} #go into the component folder | ||
npm install vulcanize -g | ||
vulcanize index.html -o index.vulcanized.html --inline-scripts --inline-css | ||
yes | cp index.vulcanized.html index.html | ||
rm index.vulcanized.html | ||
cd ../ #remember to exit out of the component before you do any git stuff | ||
# @DARK_THEME: Import dark-theme on the `index-dark.html` page | ||
perl -pi -w -e 's/px-theme\/px-theme-styles.html/px-dark-theme\/px-dark-theme-styles.html/g;' index-dark.html | ||
|
||
#do the git stuff | ||
# ------------------------------------------------------------------------------ | ||
# SW-PRECACHE | ||
# ------------------------------------------------------------------------------ | ||
|
||
# npm install sw-precache | ||
# sw-precache --root='.' --static-file-globs='**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}' | ||
|
||
# ------------------------------------------------------------------------------ | ||
# GIT PUSH TO REMOTES | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Remember to exit out of the component before we do any git stuff | ||
cd ../ | ||
|
||
# Do the git stuff | ||
git add . | ||
git commit -m "rebuild github pages" | ||
git commit -m "${GIT_COMMIT_MESSAGE}" | ||
|
||
# Set git credentials (defined in settings above) | ||
git config user.name ${GIT_USER_NAME} | ||
git config user.email ${GIT_USER_EMAIL} | ||
|
||
# We get the URL in this format: "https://github.com/PredixDev/px-something" | ||
# First, we need to replace https-style remote URL with a SSH-style remote | ||
# URL we can push to below | ||
SSH_GIT=${REPO/https:\/\/github.com\//git@github.com:} | ||
|
||
# Now, the URL is in this format: "[email protected]:PredixDev/px-something" | ||
# Next, replace `PredixDev` Github organization with `predix-ui` so configure | ||
# the correct remote to push to. | ||
# The resulting URL will be: "[email protected]:predix-ui/px-something" | ||
SSH_GIT_PREDIXUI=${SSH_GIT/:PredixDev\//:predix-ui\/} | ||
|
||
# Prepare ssh key, which we'll use to authenticate for SSH-push deploy | ||
eval `ssh-agent -s` | ||
#and cahnge permissions | ||
# ... and change permissions for deploy key | ||
chmod 0400 $TRAVIS_BUILD_DIR/deploy_key | ||
|
||
# Push to predix-ui/repo `gh-pages` branch (force to override out-of-date refs) | ||
ssh-add $TRAVIS_BUILD_DIR/deploy_key | ||
#Now that we're all set up, we can push. | ||
git push $SSH_REPO $TARGET_BRANCH | ||
git push $SSH_GIT_PREDIXUI $TARGET_BRANCH --force |