@haposoft/cafekit 0.3.2 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,312 @@
1
+ #!/bin/bash
2
+
3
+ # Master Impact Analysis Script
4
+ # Chạy tất cả analysis techniques và tạo comprehensive report
5
+ #
6
+ # Usage:
7
+ # ./run-analysis.sh
8
+ # ./run-analysis.sh --files "file1.ts,file2.ts"
9
+ # ./run-analysis.sh --output report.md
10
+
11
+ set -e
12
+
13
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14
+ OUTPUT_FILE="${OUTPUT_FILE:-impact-analysis-report.md}"
15
+ SRC_DIR="${SRC_DIR:-src}"
16
+
17
+ # Colors
18
+ RED='\033[0;31m'
19
+ GREEN='\033[0;32m'
20
+ YELLOW='\033[1;33m'
21
+ BLUE='\033[0;34m'
22
+ NC='\033[0m' # No Color
23
+
24
+ # Parse arguments
25
+ FILES=""
26
+ while [[ $# -gt 0 ]]; do
27
+ case $1 in
28
+ --files)
29
+ FILES="$2"
30
+ shift 2
31
+ ;;
32
+ --output)
33
+ OUTPUT_FILE="$2"
34
+ shift 2
35
+ ;;
36
+ *)
37
+ echo "Unknown option: $1"
38
+ echo "Usage: $0 [--files \"file1.ts,file2.ts\"] [--output report.md]"
39
+ exit 1
40
+ ;;
41
+ esac
42
+ done
43
+
44
+ echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
45
+ echo -e "${BLUE}║ 🔍 Impact Analysis - Comprehensive Report ║${NC}"
46
+ echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
47
+ echo ""
48
+
49
+ # Get changed files
50
+ if [ -n "$FILES" ]; then
51
+ CHANGED_FILES=$(echo "$FILES" | tr ',' '\n')
52
+ echo -e "${GREEN}📝 Analyzing specified files:${NC}"
53
+ else
54
+ CHANGED_FILES=$(git diff HEAD --name-only 2>/dev/null || echo "")
55
+ if [ -z "$CHANGED_FILES" ]; then
56
+ echo -e "${RED}❌ No changed files found${NC}"
57
+ echo "Usage: $0 [--files \"file1.ts,file2.ts\"]"
58
+ exit 1
59
+ fi
60
+ echo -e "${GREEN}📝 Analyzing uncommitted changes:${NC}"
61
+ fi
62
+
63
+ echo "$CHANGED_FILES" | while read -r file; do
64
+ echo " - $file"
65
+ done
66
+ echo ""
67
+
68
+ # Initialize report
69
+ cat > "$OUTPUT_FILE" << 'EOF'
70
+ # Impact Analysis Report
71
+
72
+ **Generated**: $(date '+%Y-%m-%d %H:%M:%S')
73
+ **Branch**: $(git branch --show-current 2>/dev/null || echo "unknown")
74
+
75
+ ---
76
+
77
+ EOF
78
+
79
+ # Step 1: Change Detection
80
+ echo -e "${YELLOW}[1/6]${NC} 📊 Detecting changes..."
81
+ {
82
+ echo "## 📊 Change Detection"
83
+ echo ""
84
+ echo "### Files Changed"
85
+ echo ""
86
+ echo "$CHANGED_FILES" | while read -r file; do
87
+ echo "- \`$file\`"
88
+ done
89
+ echo ""
90
+
91
+ # Git stats
92
+ if git rev-parse --git-dir > /dev/null 2>&1; then
93
+ echo "### Change Statistics"
94
+ echo ""
95
+ echo '```'
96
+ git diff HEAD --stat 2>/dev/null || echo "No git stats available"
97
+ echo '```'
98
+ echo ""
99
+ fi
100
+ } >> "$OUTPUT_FILE"
101
+
102
+ # Step 2: Risk Assessment
103
+ echo -e "${YELLOW}[2/6]${NC} ⚠️ Calculating risk..."
104
+ {
105
+ echo "## ⚠️ Risk Assessment"
106
+ echo ""
107
+
108
+ if [ -f "$SCRIPT_DIR/calculate-risk.js" ]; then
109
+ if [ -n "$FILES" ]; then
110
+ node "$SCRIPT_DIR/calculate-risk.js" --files "$FILES" 2>/dev/null || echo "Risk calculation failed"
111
+ else
112
+ node "$SCRIPT_DIR/calculate-risk.js" 2>/dev/null || echo "Risk calculation failed"
113
+ fi
114
+ else
115
+ echo "⚠️ Risk calculation script not found"
116
+ fi
117
+ echo ""
118
+ } >> "$OUTPUT_FILE"
119
+
120
+ # Step 3: Dependency Analysis
121
+ echo -e "${YELLOW}[3/6]${NC} 🔗 Finding dependencies..."
122
+ {
123
+ echo "## 🔗 Dependency Analysis"
124
+ echo ""
125
+
126
+ if [ -f "$SCRIPT_DIR/find-dependencies.sh" ]; then
127
+ echo "$CHANGED_FILES" | while read -r file; do
128
+ if [ -f "$file" ]; then
129
+ echo "### Dependencies for \`$file\`"
130
+ echo ""
131
+ echo '```'
132
+ bash "$SCRIPT_DIR/find-dependencies.sh" "$file" 2>/dev/null || echo "Dependency analysis failed for $file"
133
+ echo '```'
134
+ echo ""
135
+ fi
136
+ done
137
+ else
138
+ echo "⚠️ Dependency analysis script not found"
139
+ fi
140
+ } >> "$OUTPUT_FILE"
141
+
142
+ # Step 4: AST Analysis (for TypeScript/JavaScript files)
143
+ echo -e "${YELLOW}[4/6]${NC} 🌳 Running AST analysis..."
144
+ {
145
+ echo "## 🌳 AST Analysis (Semantic Changes)"
146
+ echo ""
147
+
148
+ TS_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx)$' || echo "")
149
+
150
+ if [ -n "$TS_FILES" ] && [ -f "$SCRIPT_DIR/ast-analyze.js" ]; then
151
+ # Check if dependencies are installed
152
+ if node -e "require('@babel/parser')" 2>/dev/null; then
153
+ echo "$TS_FILES" | while read -r file; do
154
+ if [ -f "$file" ]; then
155
+ echo "### AST Analysis for \`$file\`"
156
+ echo ""
157
+ echo '```'
158
+ node "$SCRIPT_DIR/ast-analyze.js" "$file" 2>/dev/null || echo "AST analysis failed for $file"
159
+ echo '```'
160
+ echo ""
161
+ fi
162
+ done
163
+ else
164
+ echo "⚠️ AST analysis dependencies not installed"
165
+ echo ""
166
+ echo "To enable AST analysis, run:"
167
+ echo '```bash'
168
+ echo "npm install --save-dev @babel/parser @babel/traverse"
169
+ echo '```'
170
+ echo ""
171
+ fi
172
+ else
173
+ echo "ℹ️ No TypeScript/JavaScript files to analyze"
174
+ echo ""
175
+ fi
176
+ } >> "$OUTPUT_FILE"
177
+
178
+ # Step 5: Test Coverage
179
+ echo -e "${YELLOW}[5/6]${NC} 🧪 Analyzing test coverage..."
180
+ {
181
+ echo "## 🧪 Test Coverage Analysis"
182
+ echo ""
183
+
184
+ # Check if Jest is available
185
+ if command -v jest &> /dev/null; then
186
+ echo "### Related Tests"
187
+ echo ""
188
+ echo '```'
189
+
190
+ TS_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx)$' || echo "")
191
+ if [ -n "$TS_FILES" ]; then
192
+ jest --listTests --findRelatedTests $TS_FILES 2>/dev/null || echo "No related tests found"
193
+ else
194
+ echo "No testable files changed"
195
+ fi
196
+
197
+ echo '```'
198
+ echo ""
199
+ else
200
+ echo "ℹ️ Jest not available - skipping test coverage analysis"
201
+ echo ""
202
+ fi
203
+ } >> "$OUTPUT_FILE"
204
+
205
+ # Step 6: Feature Mapping
206
+ echo -e "${YELLOW}[6/6]${NC} 🎯 Mapping features..."
207
+ {
208
+ echo "## 🎯 Feature Impact Map"
209
+ echo ""
210
+
211
+ # Simple pattern-based feature detection
212
+ echo "### Affected Features"
213
+ echo ""
214
+
215
+ declare -A features
216
+
217
+ echo "$CHANGED_FILES" | while read -r file; do
218
+ lower=$(echo "$file" | tr '[:upper:]' '[:lower:]')
219
+
220
+ if [[ "$lower" == *"auth"* ]] || [[ "$lower" == *"login"* ]]; then
221
+ echo "- **Authentication & Login**: \`$file\`"
222
+ elif [[ "$lower" == *"user"* ]] || [[ "$lower" == *"profile"* ]]; then
223
+ echo "- **User Profile Management**: \`$file\`"
224
+ elif [[ "$lower" == *"post"* ]] || [[ "$lower" == *"article"* ]]; then
225
+ echo "- **Post Management**: \`$file\`"
226
+ elif [[ "$lower" == *"comment"* ]] || [[ "$lower" == *"reply"* ]]; then
227
+ echo "- **Comment System**: \`$file\`"
228
+ elif [[ "$lower" == *"payment"* ]] || [[ "$lower" == *"checkout"* ]]; then
229
+ echo "- **Payment Processing**: \`$file\`"
230
+ elif [[ "$lower" == *"notification"* ]]; then
231
+ echo "- **Notification System**: \`$file\`"
232
+ elif [[ "$lower" == *"search"* ]] || [[ "$lower" == *"filter"* ]]; then
233
+ echo "- **Search & Filter**: \`$file\`"
234
+ elif [[ "$lower" == *"upload"* ]] || [[ "$lower" == *"file"* ]]; then
235
+ echo "- **File Upload**: \`$file\`"
236
+ elif [[ "$lower" == *"api"* ]]; then
237
+ echo "- **API Layer**: \`$file\`"
238
+ elif [[ "$lower" == *"database"* ]] || [[ "$lower" == *"schema"* ]] || [[ "$lower" == *"migration"* ]]; then
239
+ echo "- **Database**: \`$file\`"
240
+ else
241
+ echo "- **Other**: \`$file\`"
242
+ fi
243
+ done
244
+
245
+ echo ""
246
+ } >> "$OUTPUT_FILE"
247
+
248
+ # Step 7: Recommendations
249
+ {
250
+ echo "## 💡 Recommendations"
251
+ echo ""
252
+ echo "### Before Testing"
253
+ echo ""
254
+ echo "- [ ] Review all changed files"
255
+ echo "- [ ] Check for breaking changes"
256
+ echo "- [ ] Update documentation"
257
+ echo "- [ ] Review dependencies"
258
+ echo ""
259
+ echo "### Testing Checklist"
260
+ echo ""
261
+ echo "- [ ] Run unit tests"
262
+ echo "- [ ] Run integration tests"
263
+ echo "- [ ] Test affected features manually"
264
+ echo "- [ ] Test edge cases"
265
+ echo "- [ ] Test on multiple environments"
266
+ echo ""
267
+ echo "### Before Deployment"
268
+ echo ""
269
+ echo "- [ ] Code review approved"
270
+ echo "- [ ] All tests passing"
271
+ echo "- [ ] Documentation updated"
272
+ echo "- [ ] Stakeholders notified"
273
+ echo "- [ ] Rollback plan ready"
274
+ echo ""
275
+ } >> "$OUTPUT_FILE"
276
+
277
+ # Step 8: Summary
278
+ {
279
+ echo "## 📋 Summary"
280
+ echo ""
281
+
282
+ FILE_COUNT=$(echo "$CHANGED_FILES" | wc -l | tr -d ' ')
283
+
284
+ echo "- **Files Changed**: $FILE_COUNT"
285
+ echo "- **Report Generated**: $(date '+%Y-%m-%d %H:%M:%S')"
286
+ echo "- **Analysis Complete**: ✅"
287
+ echo ""
288
+ echo "---"
289
+ echo ""
290
+ echo "**Next Steps**:"
291
+ echo ""
292
+ echo "1. Review this report thoroughly"
293
+ echo "2. Address all critical issues"
294
+ echo "3. Run test scenarios"
295
+ echo "4. Proceed with code review"
296
+ echo ""
297
+ } >> "$OUTPUT_FILE"
298
+
299
+ echo ""
300
+ echo -e "${GREEN}✅ Analysis complete!${NC}"
301
+ echo ""
302
+ echo -e "${BLUE}📄 Report saved to: ${OUTPUT_FILE}${NC}"
303
+ echo ""
304
+ echo -e "${YELLOW}📖 View report:${NC}"
305
+ echo " cat $OUTPUT_FILE"
306
+ echo ""
307
+ echo -e "${YELLOW}🚀 Next steps:${NC}"
308
+ echo " 1. Review the report"
309
+ echo " 2. Fix critical issues"
310
+ echo " 3. Run tests"
311
+ echo " 4. Create PR"
312
+ echo ""