-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-all.sh
More file actions
executable file
·140 lines (126 loc) · 3.2 KB
/
update-all.sh
File metadata and controls
executable file
·140 lines (126 loc) · 3.2 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
#!/bin/bash
# Script to update all package.json files with latest React 19 and Next.js 15
# Define the folders to update
folders=(
"01-server-components/checkpoint"
"01-server-components/complete"
"02-react-patterns/start"
"02-react-patterns/checkpoint"
"02-react-patterns/complete"
"03-tanstack-query/start"
"03-tanstack-query/checkpoint"
"03-tanstack-query/complete"
"04-advanced-patterns/start"
"04-advanced-patterns/checkpoint"
"04-advanced-patterns/complete"
)
# Function to update package.json
update_package_json() {
local folder=$1
local port=$2
echo "Updating $folder..."
# Update package.json
cat > "$folder/package.json" << EOF
{
"name": "$(basename "$folder" | tr '/' '-')",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p $port",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"clsx": "^2.1.1",
"lucide-react": "^0.454.0",
"next": "^15.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@types/node": "^22",
"@types/react": "^19",
"@types/react-dom": "^19",
"autoprefixer": "^10.4.20",
"eslint": "^9",
"eslint-config-next": "^15.0.0",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3"
}
}
EOF
# Update next.config.js if it exists
if [ -f "$folder/next.config.js" ]; then
cat > "$folder/next.config.js" << EOF
/** @type {import('next').NextConfig} */
const nextConfig = {
serverExternalPackages: [],
}
module.exports = nextConfig
EOF
fi
}
# Update TanStack Query folders (need additional dependencies)
update_tanstack_package_json() {
local folder=$1
local port=$2
echo "Updating $folder (with TanStack Query)..."
# Update package.json with TanStack Query
cat > "$folder/package.json" << EOF
{
"name": "$(basename "$folder" | tr '/' '-')",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p $port",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@tanstack/react-query": "^5.59.0",
"@tanstack/react-query-devtools": "^5.59.0",
"clsx": "^2.1.1",
"lucide-react": "^0.454.0",
"next": "^15.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@types/node": "^22",
"@types/react": "^19",
"@types/react-dom": "^19",
"autoprefixer": "^10.4.20",
"eslint": "^9",
"eslint-config-next": "^15.0.0",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3"
}
}
EOF
# Update next.config.js if it exists
if [ -f "$folder/next.config.js" ]; then
cat > "$folder/next.config.js" << EOF
/** @type {import('next').NextConfig} */
const nextConfig = {
serverExternalPackages: [],
}
module.exports = nextConfig
EOF
fi
}
# Update each folder with appropriate port
port=3002
for folder in "${folders[@]}"; do
if [[ $folder == *"tanstack"* ]] || [[ $folder == *"advanced"* ]]; then
update_tanstack_package_json "$folder" "$port"
else
update_package_json "$folder" "$port"
fi
port=$((port + 1))
done
echo "All package.json files updated!"
echo "Run 'npm install' in each folder to install the new dependencies."