-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-imports-direct.sh
More file actions
executable file
·87 lines (70 loc) · 3.15 KB
/
Copy pathfix-imports-direct.sh
File metadata and controls
executable file
·87 lines (70 loc) · 3.15 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
#!/bin/bash
set -e
# Colors for terminal output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
PACKAGE_NAME="@sraz-sw/fullstack-shared"
echo -e "${YELLOW}Directly fixing all imports (without barrel files)...${NC}"
cd ./client/chat-whatsapp-clone
# Find all files with specific imports from package subpaths
SCHEMA_FILES=$(grep -l -r --include="*.ts" --include="*.tsx" "${PACKAGE_NAME}/schemas" src/ || true)
REALTIME_FILES=$(grep -l -r --include="*.ts" --include="*.tsx" "${PACKAGE_NAME}/realtime" src/ || true)
QUERY_FILES=$(grep -l -r --include="*.ts" --include="*.tsx" "${PACKAGE_NAME}/queryParams" src/ || true)
# Process schema imports - update to import directly from main package
if [ -n "$SCHEMA_FILES" ]; then
echo -e "${YELLOW}Processing files with schema imports:${NC}"
echo "$SCHEMA_FILES"
for file in $SCHEMA_FILES; do
echo -e "${YELLOW}Fixing import in $file...${NC}"
# Extract imported symbols
IMPORTS=$(grep -o "import { .*} from '${PACKAGE_NAME}/schemas'" "$file" | sed -E "s/import \{ (.*) \} from.*$/\1/")
if [ -z "$IMPORTS" ]; then
IMPORTS=$(grep -o "import { .*} from \"${PACKAGE_NAME}/schemas\"" "$file" | sed -E "s/import \{ (.*) \} from.*$/\1/")
fi
if [ -n "$IMPORTS" ]; then
echo -e "${YELLOW}Found imports: $IMPORTS${NC}"
# Check if we have type imports (using regex to find import type or curly braces with type inside)
if [[ "$file" =~ "import type" || "$(grep "import.*from.*${PACKAGE_NAME}/schemas" "$file")" =~ "import".*"type".* ]]; then
echo -e "${YELLOW}Handling type imports${NC}"
sed -i '' "s|import.*from ['\"]${PACKAGE_NAME}/schemas['\"]|import type { $IMPORTS } from '${PACKAGE_NAME}'|g" "$file"
else
echo -e "${YELLOW}Handling value imports${NC}"
sed -i '' "s|import.*from ['\"]${PACKAGE_NAME}/schemas['\"]|import { $IMPORTS } from '${PACKAGE_NAME}'|g" "$file"
fi
fi
echo -e "${GREEN}✓ Fixed${NC}"
done
fi
# Process realtime imports
if [ -n "$REALTIME_FILES" ]; then
echo -e "${YELLOW}Files with realtime imports:${NC}"
echo "$REALTIME_FILES"
for file in $REALTIME_FILES; do
echo -e "${YELLOW}Fixing import in $file...${NC}"
# Direct import is fine for realtime submodule
echo -e "${GREEN}✓ Leaving as is - subpath import is fine${NC}"
done
fi
# Process queryParams imports
if [ -n "$QUERY_FILES" ]; then
echo -e "${YELLOW}Files with queryParams imports:${NC}"
echo "$QUERY_FILES"
for file in $QUERY_FILES; do
echo -e "${YELLOW}Fixing import in $file...${NC}"
# Direct import is fine for queryParams submodule
echo -e "${GREEN}✓ Leaving as is - subpath import is fine${NC}"
done
fi
# Get rid of the types directory if it exists and is empty
if [ -d "src/types" ]; then
# Check if directory is empty (except for .DS_Store)
if [ -z "$(find src/types -type f -not -name ".DS_Store" | head -1)" ]; then
echo -e "${YELLOW}Removing empty types directory...${NC}"
rm -rf src/types
else
echo -e "${YELLOW}Types directory contains files, keeping it.${NC}"
fi
fi
echo -e "${GREEN}✅ All imports have been directly fixed! No barrel files used.${NC}"