Created
August 23, 2016 00:24
-
-
Save bguiz/75591d36d4ffc3e021f686c072ed7157 to your computer and use it in GitHub Desktop.
Installs a dependency from a git repo using info specified in pakage.json, then builds it
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
#!/bin/bash | |
# Installs a dependency from a git repo using info specified in pakage.json, then builds it | |
: <<"MultilineCommentDelimiter" | |
Place this file in ./devops/git-dependency/install-and-build.sh | |
Update package.json to add "config" and a a build step to "scripts" | |
{ | |
"config": { | |
"foo": { | |
"name": "foo", | |
"user": "bguiz", | |
"commit": "v1.2.3" | |
}, | |
}, | |
"scripts": { | |
"postinstall": "npm run build-foo", | |
"build-foo": "bash ./devops/git-dependency/install-and-build.sh foo" | |
} | |
} | |
MultilineCommentDelimiter | |
set -o xtrace | |
# Read info from package.json (npm populates contents in env vars) | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd ../.. && pwd )" | |
DEP_NAME="${1}" | |
REPO_USER_VARNAME="npm_package_config_${DEP_NAME}_user" | |
REPO_USER="${!REPO_USER_VARNAME}" | |
REPO_NAME_VARNAME="npm_package_config_${DEP_NAME}_name" | |
REPO_NAME="${!REPO_NAME_VARNAME}" | |
REPO_COMMIT_VARNAME="npm_package_config_${DEP_NAME}_commit" | |
REPO_COMMIT="${!REPO_COMMIT_VARNAME}" | |
# Clone or update from git repository, and switch to specified commit | |
mkdir -p ${DIR}/tmp | |
cd ${DIR}/tmp | |
if cd ./${REPO_NAME}; then | |
echo 'git fetch' | |
git fetch origin :remotes/origin/ | |
else | |
echo 'git clone' | |
git clone --depth 1 --branch ${REPO_COMMIT} git@github.com:${REPO_USER}/${REPO_NAME}.git ${REPO_NAME} | |
cd ./${REPO_NAME} | |
fi | |
git checkout ${REPO_COMMIT} | |
git status | |
git describe | |
# Now build and symlink | |
npm install --cache-min 864000 | |
npm run build | |
ls ${PWD}/build | |
cd ${DIR} | |
rm ${DIR}/static/${REPO_NAME} | |
ln -sf ${DIR}/tmp/${REPO_NAME}/build ${DIR}/static/${REPO_NAME} | |
ls -la ${DIR}/static | |
ls -la ${DIR}/static/${REPO_NAME}/* | |
cat ${DIR}/static/${REPO_NAME}/index.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment