-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage-dev.sh
More file actions
executable file
·209 lines (183 loc) · 6.09 KB
/
package-dev.sh
File metadata and controls
executable file
·209 lines (183 loc) · 6.09 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
# package-dev.sh
# Build a development VSIX that can be installed alongside the marketplace version
set -e
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Constants
DEV_EXTENSION_ID="Mobb.mobb-ai-tracer-dev"
# Defaults
ENV="local"
API_URL=""
WEB_URL=""
# Help message
show_help() {
echo "Usage: ./package-dev.sh [OPTIONS]"
echo ""
echo "Build a development VSIX with configurable environment settings."
echo "The dev extension uses a different ID so it can run alongside the marketplace version."
echo ""
echo "Options:"
echo " --env ENV Environment preset: local (default), sandbox, prod"
echo " --api-url URL Override API URL"
echo " --web-url URL Override Web App URL"
echo " -h, --help Show this help message"
echo ""
echo "Environment presets:"
echo " local: http://localhost:8080/v1/graphql, http://localhost:5173"
echo " sandbox: https://api-st-stenant.mobb.dev/v1/graphql, https://st-stenant.mobb.dev"
echo " prod: https://api.mobb.ai/v1/graphql, https://app.mobb.ai"
echo ""
echo "Examples:"
echo " ./package-dev.sh # Build with local env (default)"
echo " ./package-dev.sh --env sandbox # Build with sandbox env"
echo " ./package-dev.sh --env prod # Build with prod env"
echo " ./package-dev.sh --api-url http://custom:8080/v1/graphql"
}
# Set URLs based on environment (consolidated)
set_env_urls() {
local env=$1
case $env in
local)
API_URL="http://localhost:8080/v1/graphql"
WEB_URL="http://localhost:5173"
;;
sandbox)
API_URL="https://api-st-stenant.mobb.dev/v1/graphql"
WEB_URL="https://st-stenant.mobb.dev"
;;
prod)
API_URL="https://api.mobb.ai/v1/graphql"
WEB_URL="https://app.mobb.ai"
;;
esac
}
# Install extension to an editor
install_to_editor() {
local cli_cmd=$1
local display_name=$2
if command -v "$cli_cmd" &> /dev/null; then
echo " Uninstalling old dev extension from $display_name..."
"$cli_cmd" --uninstall-extension "$DEV_EXTENSION_ID" 2>/dev/null || true
echo " Installing new dev extension to $display_name..."
"$cli_cmd" --install-extension "$VSIX_FILE"
echo -e " ${GREEN}Installed to $display_name${NC}"
else
echo -e " ${YELLOW}$display_name CLI ($cli_cmd) not found, skipping${NC}"
fi
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--env) ENV="$2"; shift 2 ;;
--api-url) API_URL="$2"; shift 2 ;;
--web-url) WEB_URL="$2"; shift 2 ;;
-h|--help) show_help; exit 0 ;;
*) echo -e "${RED}Unknown option: $1${NC}"; show_help; exit 1 ;;
esac
done
# Validate environment
if [[ "$ENV" != "local" && "$ENV" != "sandbox" && "$ENV" != "prod" ]]; then
echo -e "${RED}Invalid environment: $ENV${NC}"
echo "Valid options: local, sandbox, prod"
exit 1
fi
# Set URLs if not overridden via CLI
if [[ -z "$API_URL" && -z "$WEB_URL" ]]; then
set_env_urls "$ENV"
elif [[ -z "$API_URL" ]]; then
# Only API_URL missing, get default for this env
case $ENV in
local) API_URL="http://localhost:8080/v1/graphql" ;;
sandbox) API_URL="https://api-st-stenant.mobb.dev/v1/graphql" ;;
prod) API_URL="https://api.mobb.ai/v1/graphql" ;;
esac
elif [[ -z "$WEB_URL" ]]; then
# Only WEB_URL missing, get default for this env
case $ENV in
local) WEB_URL="http://localhost:5173" ;;
sandbox) WEB_URL="https://st-stenant.mobb.dev" ;;
prod) WEB_URL="https://app.mobb.ai" ;;
esac
fi
echo -e "${GREEN}Building dev extension for environment: ${YELLOW}$ENV${NC}"
echo -e " API URL: $API_URL"
echo -e " Web URL: $WEB_URL"
echo ""
# Backup original package.json
echo "Backing up package.json..."
cp package.json package.json.bak
# Backup existing .env if present
if [[ -f .env ]]; then
echo "Backing up existing .env file..."
cp .env .env.bak
fi
# Function to restore files on exit (success or failure)
cleanup() {
if [[ -f package.json.bak ]]; then
mv package.json.bak package.json
echo "Restored original package.json"
fi
if [[ -f .env.bak ]]; then
mv .env.bak .env
echo "Restored original .env file"
elif [[ -f .env ]]; then
rm .env
echo "Removed dev .env file"
fi
}
trap cleanup EXIT INT TERM
# Verify dev icon exists (committed to repo)
if [[ ! -f icon-dev.png ]]; then
echo -e "${YELLOW}icon-dev.png not found, using original icon${NC}"
cp icon.png icon-dev.png
fi
# Create .env file with dev values
# Uses DEV_* prefixed names to avoid conflicts with production extension
echo "Creating .env file for dev build..."
cat > .env << ENVEOF
MOBB_DEV_EXTENSION=true
DEV_API_URL=$API_URL
DEV_WEB_APP_URL=$WEB_URL
API_URL=$API_URL
WEB_APP_URL=$WEB_URL
HASURA_ACCESS_KEY=dummy
LOCAL_GRAPHQL_ENDPOINT=http://localhost:8080/v1/graphql
DD_RUM_TOKEN=$(grep '^DD_RUM_TOKEN=' .env.bak 2>/dev/null | cut -d= -f2-)
ENVEOF
# Modify package.json for dev build
echo "Modifying package.json for dev build..."
node scripts/modify-package-for-dev.js "$API_URL" "$WEB_URL" "$ENV"
# Clean previous dev builds
echo ""
echo "Cleaning previous builds..."
rm -rf mobb-ai-tracer-dev-*.vsix
rm -rf out
echo ""
echo "Building..."
npm run build
echo ""
echo "Packaging VSIX..."
# --no-dependencies: esbuild bundles everything into out/extension.js,
# so node_modules is not needed in the VSIX.
npx vsce package --allow-package-env-file --no-dependencies
# Get the generated VSIX filename
VSIX_FILE=$(ls mobb-ai-tracer-dev-*.vsix 2>/dev/null | head -1)
if [[ -z "$VSIX_FILE" ]]; then
echo -e "${RED}Failed to create VSIX file${NC}"
exit 1
fi
echo ""
echo -e "${GREEN}Dev VSIX created: ${YELLOW}$VSIX_FILE${NC}"
# Install to editors
echo ""
echo "Installing to editors..."
install_to_editor "code" "VS Code"
install_to_editor "cursor" "Cursor"
echo ""
echo -e "${GREEN}Done!${NC}"
echo -e "${YELLOW}Please restart your editor to activate the dev extension.${NC}"