forked from ngrok/ngrok-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.envrc
More file actions
162 lines (141 loc) · 6.49 KB
/
.envrc
File metadata and controls
162 lines (141 loc) · 6.49 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# ============================================================================
# ngrok-docs Development Environment Setup (.envrc)
# ============================================================================
# This file automatically sets up the development environment when you enter
# the project directory. It ensures Node.js, pnpm, and dependencies are ready.
#
# Prerequisites: direnv must be installed and allowed (`direnv allow`)
# ============================================================================
echo "Starting environment loading…"
START_TIME_MS=$(perl -MTime::HiRes=time -e 'printf "%.0f\n", time * 1000')
# ============================================================================
# DIRENV CONFIGURATION
# ============================================================================
# Disable direnv timeout warnings that can appear during long setup operations
# References:
# - https://github.com/direnv/direnv/issues/419#issuecomment-442005962
# - https://direnv.net/man/direnv.toml.1.html#codewarntimeoutcode
export DIRENV_WARN_TIMEOUT=876000h # 100 years in hours (effectively disabled)
# ============================================================================
# TELEMETRY AND PRIVACY SETTINGS
# ============================================================================
# Disable telemetry collection for various tools to improve privacy and performance
export DO_NOT_TRACK=1 # Universal opt-out signal
export TURBO_TELEMETRY_DISABLED=1 # Turborepo telemetry
export VERCEL_TELEMETRY_DISABLED=1 # Vercel CLI telemetry
# ============================================================================
# NIX SUPPORT
# ============================================================================
# If using NixOS or Nix package manager, use the flake-based environment
if has nix; then
echo "Using Nix flake environment…"
use flake
else
# ============================================================================
# NODE VERSION MANAGER (FNM) SETUP
# ============================================================================
# Fast Node Manager (fnm) handles Node.js version switching based on .nvmrc
# Detect operating system for cross-platform fnm path resolution
OS="$(uname -s)"
case "${OS}" in
MINGW* | Win*) OS="Windows" ;;
esac
# Set FNM_PATH based on OS conventions and user preferences
if [ -d "$HOME/.fnm" ]; then
export FNM_PATH="$HOME/.fnm" # Legacy location
elif [ -n "$XDG_DATA_HOME" ]; then
export FNM_PATH="$XDG_DATA_HOME/fnm" # XDG Base Directory spec
elif [ "$OS" = "Darwin" ]; then
export FNM_PATH="$HOME/Library/Application Support/fnm" # macOS standard
else
export FNM_PATH="$HOME/.local/share/fnm" # Linux/Unix standard
fi
# Auto-install fnm if not present
if ! command -v fnm &> /dev/null || [ -d "$FNM_PATH" ]; then
echo "fnm is not installed. Installing fnm…"
curl -fsSL https://fnm.vercel.app/install | bash -s -- --skip-shell
else
echo "fnm is already installed."
fi
# Add fnm to PATH and initialize
export PATH="$FNM_PATH:$PATH"
eval "`fnm env`"
# Install Node.js version specified in .nvmrc file
# This ensures everyone uses the same Node.js version
fnm install
# =============================================================================
# PACKAGE MANAGER SETUP
# =============================================================================
# Update npm and corepack to latest versions
# corepack is Node.js's official package manager manager
yes | npm update --global corepack npm
# Enable pnpm support in corepack
# pnpm is our chosen package manager for this project
yes | corepack enable pnpm
# Install the specific pnpm version defined in package.json#packageManager
# This ensures everyone uses the exact same package manager version
yes | corepack install
fi
# =============================================================================
# DEPENDENCY INSTALLATION
# =============================================================================
# Install all project dependencies
pnpm install
# ============================================================================
# ENVIRONMENT READY CONFIRMATION
# ============================================================================
# Display setup completion status and timing information
pnpm_version=$(pnpm --version)
echo -e "\nEnvironment is ready.\nUsing pnpm version: $pnpm_version\n"
END_TIME_MS=$(perl -MTime::HiRes=time -e 'printf "%.0f\n", time * 1000')
ELAPSED_TIME=$(bc <<< "scale=3; ($END_TIME_MS - $START_TIME_MS) / 1000")
echo -e "direnv environment setup took $ELAPSED_TIME s.\n"
# =============================================================================
# WHAT HAPPENS NEXT
# =============================================================================
# After this completes, you can:
# - `pnpm start` - Start the documentation development server
# - `pnpm build` - Build the documentation site
# - `pnpm test` - Run all tests
# - `pnpm typecheck` - Check TypeScript types
# - `pnpm fmt` - Format and lint code
# - See README.md for more commands and workflows
# =============================================================================
# ============================================================================
# FIRST-TIME SETUP GUIDANCE
# ============================================================================
# Show helpful next steps only on the first run
FIRST_RUN_MARKER=".direnv-initialized"
if [ ! -f "$FIRST_RUN_MARKER" ]; then
echo "============================================================================"
echo "🎉 Welcome to ngrok-docs! Here's what you can do next:"
echo "============================================================================"
echo ""
echo "📖 Start the documentation site:"
echo " pnpm start"
echo ""
echo "🔨 Build the documentation:"
echo " pnpm build"
echo ""
echo "🧪 Run tests:"
echo " pnpm test"
echo ""
echo "📋 Check types:"
echo " pnpm typecheck"
echo ""
echo "✨ Format & lint:"
echo " pnpm fmt"
echo ""
echo "🔍 Validate code blocks:"
echo " pnpm validate-codeblocks"
echo ""
echo "🧹 Clear cache (if needed):"
echo " pnpm clear-cache"
echo ""
echo "📚 Full documentation: https://ngrok.com/docs"
echo "📄 See README.md for more details"
echo ""
echo "============================================================================"
# Create marker file to indicate setup has been completed
touch "$FIRST_RUN_MARKER"
fi