-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
Β·343 lines (314 loc) Β· 12.4 KB
/
Copy pathdev.sh
File metadata and controls
executable file
Β·343 lines (314 loc) Β· 12.4 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/bash
# UI Library Development Menu
# Interactive script to run common development tasks
#
# Usage: ./dev.sh
#
# Features:
# - 24+ commands organized into 7 categories
# - Color-coded output for better UX
# - Pre-release checklist automation
# - CI workflow simulator
# - Project status dashboard
#
# Documentation:
# - See README.md section "Developer Menu"
# - See TESTING.md for testing-specific workflows
set -e
# Colors for better UX
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Clear screen and show header
clear
echo -e "${CYAN}${BOLD}"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β UI Library Development Menu v1.0.0 β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo -e "${NC}"
# Main menu function
show_menu() {
echo ""
echo -e "${BOLD}π¦ BUILD & DEVELOPMENT${NC}"
echo " 1) Build library (ESM + CJS)"
echo " 2) Build TypeScript types"
echo " 3) Clean build (remove dist/)"
echo ""
echo -e "${BOLD}π§ͺ TESTING (Playwright)${NC}"
echo " 4) Run tests (component + E2E if present)"
echo " 5) Run component tests only (70 tests)"
echo " 6) Run tests in UI mode (interactive)"
echo " 7) Run tests in headed mode (visible browser)"
echo " 8) Debug tests (Playwright Inspector)"
echo " 9) Generate coverage report"
echo ""
echo -e "${BOLD}π¨ STORYBOOK${NC}"
echo " 10) Start Storybook dev server"
echo " 11) Build Storybook (static)"
echo ""
echo -e "${BOLD}π CODE QUALITY${NC}"
echo " 12) Lint code (ESLint)"
echo " 13) Lint and auto-fix"
echo ""
echo -e "${BOLD}π SECURITY & MAINTENANCE${NC}"
echo " 14) Check production dependencies (npm audit)"
echo " 15) Check all dependencies (dev + prod)"
echo " 16) Fix vulnerabilities (safe)"
echo " 17) Check outdated packages"
echo ""
echo -e "${BOLD}π¦ PACKAGE MANAGEMENT${NC}"
echo " 18) Install dependencies (npm install)"
echo " 19) Clean install (remove node_modules + reinstall)"
echo " 20) Create tarball for local testing"
echo ""
echo -e "${BOLD}π PROJECT INFO${NC}"
echo " 21) Show project status"
echo " 22) View test report (last run)"
echo ""
echo -e "${BOLD}π QUICK ACTIONS${NC}"
echo " 23) Full CI workflow (lint + test + build)"
echo " 24) Pre-release checklist"
echo ""
echo -e "${RED} 0) Exit${NC}"
echo ""
echo -e "${YELLOW}ββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
}
# Function to run command with nice output
run_command() {
local cmd=$1
local desc=$2
echo ""
echo -e "${CYAN}βΆ Running: ${BOLD}$desc${NC}"
echo -e "${YELLOW}ββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
if eval "$cmd"; then
echo ""
echo -e "${GREEN}β
Success: $desc${NC}"
else
echo ""
echo -e "${RED}β Failed: $desc${NC}"
return 1
fi
}
# Function to show project status
show_status() {
echo ""
echo -e "${CYAN}${BOLD}π Project Status${NC}"
echo -e "${YELLOW}ββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
# Check if node_modules exists
if [ -d "node_modules" ]; then
echo -e "${GREEN}β${NC} Dependencies installed"
else
echo -e "${RED}β${NC} Dependencies not installed (run npm install)"
fi
# Check if dist exists
if [ -d "dist" ]; then
echo -e "${GREEN}β${NC} Library built (dist/ exists)"
else
echo -e "${YELLOW}β ${NC} Library not built (run npm run build)"
fi
# Check Node version
echo -e "${BLUE}βΉ${NC} Node version: $(node --version)"
echo -e "${BLUE}βΉ${NC} npm version: $(npm --version)"
# Show package info
echo -e "${BLUE}βΉ${NC} Package: $(node -p "require('./package.json').name") v$(node -p "require('./package.json').version")"
# Count test files
local test_count=$(find tests/component -name "*.spec.tsx" 2>/dev/null | wc -l | tr -d ' ')
echo -e "${BLUE}βΉ${NC} Component tests: $test_count files"
# Show last test results if available
if [ -d "test-results" ]; then
echo -e "${GREEN}β${NC} Test results available (run option 22 to view)"
fi
echo ""
}
# Function for pre-release checklist
pre_release_checklist() {
echo ""
echo -e "${MAGENTA}${BOLD}π Pre-Release Checklist${NC}"
echo -e "${YELLOW}ββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
echo -e "${CYAN}Running pre-release checks...${NC}"
echo ""
local all_passed=true
# 1. Lint
echo -e "${BLUE}[1/5]${NC} Linting code..."
if npm run lint > /dev/null 2>&1; then
echo -e "${GREEN} β Lint passed${NC}"
else
echo -e "${RED} β Lint failed${NC}"
all_passed=false
fi
# 2. Tests
echo -e "${BLUE}[2/5]${NC} Running tests..."
if npm run test:component > /dev/null 2>&1; then
echo -e "${GREEN} β All tests passed${NC}"
else
echo -e "${RED} β Tests failed${NC}"
all_passed=false
fi
# 3. Build
echo -e "${BLUE}[3/5]${NC} Building library..."
if npm run build > /dev/null 2>&1; then
echo -e "${GREEN} β Build successful${NC}"
else
echo -e "${RED} β Build failed${NC}"
all_passed=false
fi
# 4. Security audit
echo -e "${BLUE}[4/5]${NC} Checking production dependencies..."
if npm audit --production > /dev/null 2>&1; then
echo -e "${GREEN} β No vulnerabilities found${NC}"
else
echo -e "${YELLOW} β Vulnerabilities detected (review with npm audit)${NC}"
fi
# 5. Check for uncommitted changes
echo -e "${BLUE}[5/5]${NC} Checking git status..."
if [ -z "$(git status --porcelain 2>/dev/null)" ]; then
echo -e "${GREEN} β No uncommitted changes${NC}"
else
echo -e "${YELLOW} β You have uncommitted changes${NC}"
fi
echo ""
if [ "$all_passed" = true ]; then
echo -e "${GREEN}${BOLD}β
All checks passed! Ready to release.${NC}"
else
echo -e "${RED}${BOLD}β Some checks failed. Please fix issues before release.${NC}"
fi
echo ""
}
# Main loop
while true; do
show_menu
read -p "$(echo -e ${CYAN}Enter your choice [0-24]:${NC} )" choice
case $choice in
1)
run_command "npm run build" "Build library"
;;
2)
run_command "npm run build:types" "Build TypeScript types"
;;
3)
run_command "rm -rf dist && echo 'Cleaned dist/' && npm run build" "Clean and rebuild"
;;
4)
run_command "npm run test:component && if [ -d 'tests/e2e' ] && find tests/e2e -type f \( -name '*.spec.ts' -o -name '*.spec.tsx' -o -name '*.test.ts' -o -name '*.test.tsx' \) | grep -q .; then npm test; else echo 'No E2E tests found, skipping.'; fi" "Run tests (component + E2E if present)"
;;
5)
run_command "npm run test:component" "Run component tests (70 tests)"
;;
6)
echo -e "${CYAN}Starting Playwright UI mode...${NC}"
npm run test:ui
;;
7)
# Prefer component tests in headed mode; fallback to E2E if present
if find tests/component -name "*.spec.tsx" 2>/dev/null | grep -q .; then
run_command "npx playwright test --config=playwright-ct.config.ts --headed" "Run component tests in headed mode"
elif [ -d "tests/e2e" ] && find tests/e2e -type f \( -name "*.spec.ts" -o -name "*.spec.tsx" -o -name "*.test.ts" -o -name "*.test.tsx" \) 2>/dev/null | grep -q .; then
run_command "npx playwright test --headed" "Run E2E tests in headed mode"
else
echo -e "${YELLOW}No tests found (component or E2E).${NC}"
fi
;;
8)
# Prefer component tests in debug (Inspector) mode; fallback to E2E if present
if find tests/component -name "*.spec.tsx" 2>/dev/null | grep -q .; then
run_command "npx playwright test --config=playwright-ct.config.ts --debug" "Debug component tests (Playwright Inspector)"
elif [ -d "tests/e2e" ] && find tests/e2e -type f \( -name "*.spec.ts" -o -name "*.spec.tsx" -o -name "*.test.ts" -o -name "*.test.tsx" \) 2>/dev/null | grep -q .; then
run_command "npx playwright test --debug" "Debug E2E tests (Playwright Inspector)"
else
echo -e "${YELLOW}No tests found (component or E2E).${NC}"
fi
;;
9)
run_command "npm run coverage" "Generate coverage report"
;;
10)
echo -e "${CYAN}Starting Storybook dev server on http://localhost:6006${NC}"
npm run storybook
;;
11)
run_command "npm run build-storybook" "Build Storybook"
;;
12)
run_command "npm run lint" "Lint code"
;;
13)
run_command "npm run lint:fix" "Lint and auto-fix"
;;
14)
run_command "npm run audit" "Check production dependencies"
;;
15)
echo -e "${CYAN}Checking all dependencies (including dev)...${NC}"
if npm run audit:dev; then
echo -e "${GREEN}β
No blocking vulnerabilities in dev or prod dependencies${NC}"
else
echo -e "${YELLOW}β Audit reported vulnerabilities (dev and/or prod). Review details above.${NC}"
# Do not fail the menu on non-zero exit from audit
fi
;;
16)
run_command "npm run audit:fix" "Fix vulnerabilities (safe)"
;;
17)
echo -e "${CYAN}Checking for outdated packages...${NC}"
if npm run outdated; then
echo -e "${GREEN}β
All dependencies up to date${NC}"
else
echo -e "${YELLOW}β Outdated packages are listed above. This is informational, not an error.${NC}"
fi
;;
18)
run_command "npm install" "Install dependencies"
;;
19)
run_command "rm -rf node_modules package-lock.json && npm install" "Clean install"
;;
20)
run_command "npm pack" "Create tarball"
echo -e "${GREEN}Tarball created! Install in another project with:${NC}"
echo -e "${CYAN} npm install ../ui-library/ui-library-*.tgz${NC}"
;;
21)
show_status
;;
22)
if [ -d "playwright-report" ]; then
echo -e "${CYAN}Opening test report...${NC}"
npx playwright show-report
else
echo -e "${RED}No test report found. Run tests first (option 5).${NC}"
fi
;;
23)
echo -e "${MAGENTA}${BOLD}Running full CI workflow...${NC}"
run_command "npm run lint && npm run test:component && npm run build" "CI workflow"
;;
24)
pre_release_checklist
;;
0)
echo ""
echo -e "${GREEN}Thanks for using UI Library Dev Menu! π${NC}"
echo ""
exit 0
;;
*)
echo -e "${RED}Invalid option. Please try again.${NC}"
sleep 1
clear
;;
esac
# Wait for user to continue
if [ "$choice" != "0" ] && [ "$choice" != "6" ] && [ "$choice" != "8" ] && [ "$choice" != "10" ] && [ "$choice" != "22" ]; then
echo ""
read -p "$(echo -e ${YELLOW}Press Enter to continue...${NC})"
clear
fi
done