forked from documenso/documenso
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvercel.sh
More file actions
executable file
·105 lines (80 loc) · 2.65 KB
/
Copy pathvercel.sh
File metadata and controls
executable file
·105 lines (80 loc) · 2.65 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# Exit on error.
set -eo pipefail
# Get the directory of this script, regardless of where it is called from.
SCRIPT_DIR="$(readlink -f "$(dirname "$0")")"
function log() {
echo "[VercelBuild]: $1"
}
function build_webapp() {
log "Building webapp for $VERCEL_ENV"
remap_webapp_env
remap_database_integration
npm run prisma:generate --workspace=@documenso/prisma
npm run prisma:migrate-deploy --workspace=@documenso/prisma
if [[ "$VERCEL_ENV" != "production" ]]; then
log "Seeding database for $VERCEL_ENV"
npm run prisma:seed --workspace=@documenso/prisma
fi
npm run build -- --filter @documenso/web
}
function remap_webapp_env() {
if [[ "$VERCEL_ENV" != "production" ]]; then
log "Remapping webapp environment variables for $VERCEL_ENV"
export NEXTAUTH_URL="https://$VERCEL_URL"
export NEXT_PUBLIC_WEBAPP_URL="https://$VERCEL_URL"
fi
}
function build_marketing() {
log "Building marketing for $VERCEL_ENV"
remap_marketing_env
remap_database_integration
npm run prisma:generate --workspace=@documenso/prisma
npm run build -- --filter @documenso/marketing
}
function remap_marketing_env() {
if [[ "$VERCEL_ENV" != "production" ]]; then
log "Remapping marketing environment variables for $VERCEL_ENV"
export NEXT_PUBLIC_MARKETING_URL="https://$VERCEL_URL"
fi
}
function remap_database_integration() {
log "Remapping Supabase integration for $VERCEL_ENV"
if [[ ! -z "$POSTGRES_URL" ]]; then
export NEXT_PRIVATE_DATABASE_URL="$POSTGRES_URL"
export NEXT_PRIVATE_DIRECT_DATABASE_URL="$POSTGRES_URL"
fi
if [[ ! -z "$DATABASE_URL" ]]; then
export NEXT_PRIVATE_DATABASE_URL="$DATABASE_URL"
export NEXT_PRIVATE_DIRECT_DATABASE_URL="$DATABASE_URL"
fi
if [[ ! -z "$DATABASE_URL_UNPOOLED" ]]; then
log "Remapping for Neon integration"
export NEXT_PRIVATE_DATABASE_URL="$DATABASE_URL&pgbouncer=true"
export NEXT_PRIVATE_DIRECT_DATABASE_URL="$DATABASE_URL_UNPOOLED"
fi
if [[ ! -z "$POSTGRES_URL_NON_POOLING" ]]; then
export NEXT_PRIVATE_DATABASE_URL="$POSTGRES_URL?pgbouncer=true"
export NEXT_PRIVATE_DIRECT_DATABASE_URL="$POSTGRES_URL_NON_POOLING"
fi
}
# Navigate to the root of the project.
cd "$SCRIPT_DIR/.."
# Check if the script is running on Vercel.
if [[ -z "$VERCEL" ]]; then
log "ERROR - This script must be run as part of the Vercel build process."
exit 1
fi
case "$DEPLOYMENT_TARGET" in
"webapp")
build_webapp
;;
"marketing")
build_marketing
;;
*)
log "ERROR - Missing or invalid DEPLOYMENT_TARGET environment variable."
log "ERROR - DEPLOYMENT_TARGET must be either 'webapp' or 'marketing'."
exit 1
;;
esac