This repository was archived by the owner on Jun 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 652
/
Copy pathcompile
94 lines (78 loc) · 2.34 KB
/
compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# Fail immediately on non-zero exit code.
set -e
# Fail immediately on non-zero exit code within a pipeline.
set -o pipefail
# Fail on undeclared variables.
set -u
# Debug, echo every command
#set -x
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
function export_env_dir() {
local env_dir=$1
local whitelist_regex=${2:-''}
local blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH|IFS)$'}
if [ -d "$env_dir" ]; then
for e in $(ls $env_dir); do
echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" &&
export "$e=$(cat $env_dir/$e)"
:
done
fi
}
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
BP_DIR=`cd $(dirname $0); cd ..; pwd`
# Use architecture of multi-buildpack to compose behavior.
# https://github.com/heroku/heroku-buildpack-multi
cp $BP_DIR/.buildpacks $BUILD_DIR/.buildpacks
url=https://github.com/heroku/heroku-buildpack-multi.git
branch=""
dir=$(mktemp -t buildpackXXXXX)
rm -rf $dir
# Set env vars for the inner buildpacks in `.buildpacks`
# * Install `npm build` tooling.
export NPM_CONFIG_PRODUCTION=false
echo "=====> Downloading Buildpack: $url"
if [[ "$url" =~ \.tgz$ ]] || [[ "$url" =~ \.tgz\? ]]; then
mkdir -p "$dir"
curl -s "$url" | tar xvz -C "$dir" >/dev/null 2>&1
else
git clone $url $dir >/dev/null 2>&1
fi
cd $dir
if [ "$branch" != "" ]; then
git checkout $branch >/dev/null 2>&1
fi
chmod -f +x $dir/bin/{detect,compile,release}
framework=$($dir/bin/detect $1)
if [ $? == 0 ]; then
echo "=====> Detected Framework: $framework"
$dir/bin/compile $BUILD_DIR $CACHE_DIR $ENV_DIR
if [ $? != 0 ]; then
exit 1
fi
else
echo "create-react-app `.buildpacks` not defined. Exiting."
exit 1
fi
export_env_dir "$ENV_DIR" '^(REACT_APP_|NODE_)'
if [ 'true' == "${REACT_APP_STATEFUL_BUILD-false}" ]; then
echo '=====> Stateful build, now generating the JavaScript bundle'
echo ' NOTICE: `REACT_APP_*` config vars will be compiled into'
echo ' the slug. To update their values, push a new deployment.'
cd $BUILD_DIR
.heroku/node/bin/npm run build
else
echo '=====> Stateless build, the JavaScript bundle will be generated on start-up'
fi
mkdir -p $BUILD_DIR/.profile.d
cp $BP_DIR/.profile.d/create-react-app.sh $BUILD_DIR/.profile.d/