-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild
More file actions
executable file
·74 lines (61 loc) · 1.87 KB
/
build
File metadata and controls
executable file
·74 lines (61 loc) · 1.87 KB
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
#!/usr/bin/env bash
set -eo pipefail
echo "---> Node Buildpack"
# 1. GET ARGS
layers_dir=$1
plan_path=$3
# shellcheck source=/dev/null
. generate-project.sh "${layers_dir}"
# 2. Install build deps
# shellcheck source=/dev/null
. generate-layers.sh "${layers_dir}"
generate_deps_layer build-deps
generate_deps_layer run-deps
# 3. install node
generate_stack_layer node "${plan_path}" true
# shellcheck source=/dev/null
. init-stack
# 4. install node modules
node_modules_layer_dir="${layers_dir}/node_modules"
mkdir -p "${node_modules_layer_dir}"/profile.d
# Compares previous package.json checksum to the current package.json
local_package_checksum=$(sha256sum package.json | cut -d ' ' -f 1 || echo 'not found')
remote_package_checksum='not found'
if [[ -f "${node_modules_layer_dir}.toml" ]]; then
remote_package_checksum=$(yj <"${node_modules_layer_dir}.toml" -t | jq -r .metadata.version 2>/dev/null || echo 'not found')
fi
if [[ -f package.json && "${local_package_checksum}" == "${remote_package_checksum}" ]]; then
echo "---> Reusing package.json"
elif [[ -f package.json ]]; then
echo "---> Installing package.json with npm install."
cp package.json "${node_modules_layer_dir}"
cd "${node_modules_layer_dir}" && npm install && cd -
cat >"${node_modules_layer_dir}.toml" <<EOL
[types]
cache = true
build = true
launch = true
[metadata]
version = "${local_package_checksum}"
EOL
cat >"${node_modules_layer_dir}"/profile.d/copy_node_modules.sh <<EOL
# only execute at runtime
if [ -z "\$INIT_STACK" ]; then
cp -rf ${node_modules_layer_dir}/node_modules $(pwd)
fi
EOL
fi
json_get_key() {
local file="$1"
local key="$2"
if test -f "$file"; then
jq -c -M --raw-output "$key // \"\"" <"$file" || return 1
else
echo ""
fi
}
build_script=$(json_get_key "package.json" ".scripts.build")
if [[ $build_script ]]; then
npm run build
fi
generate-launch.sh "${layers_dir}"