-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.ps1
More file actions
131 lines (112 loc) · 4.25 KB
/
setup.ps1
File metadata and controls
131 lines (112 loc) · 4.25 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
# PowerShell script for setting up Fullstack Blog (Next.js + Supabase)
# Equivalent to setup.sh but for Windows users
# Set error action preference to stop on error
$ErrorActionPreference = "Stop"
# Helper function for colored output
function Write-ColorOutput($ForegroundColor) {
$fc = $host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = $ForegroundColor
if ($args) {
Write-Output $args
}
else {
$input | Write-Output
}
$host.UI.RawUI.ForegroundColor = $fc
}
Write-ColorOutput Yellow "Fullstack Blog Setup (Next.js + Supabase)"
Write-Output "This script will set up your blog project with Next.js and Supabase."
# Step 1: Create a temporary directory for Next.js initialization
Write-ColorOutput Green "`nStep 1: Creating temporary directory for Next.js initialization..."
$TEMP_DIR = "temp-nextjs-setup-$(Get-Date -Format 'yyyyMMddHHmmss')"
New-Item -Path $TEMP_DIR -ItemType Directory -Force | Out-Null
Write-Output "Temporary directory created at: $TEMP_DIR"
# Step 2: Initialize Next.js in the temporary directory
Write-ColorOutput Green "`nStep 2: Initializing Next.js in temporary directory..."
Set-Location -Path $TEMP_DIR
npx --registry=https://registry.npmjs.org/ create-next-app@latest . `
--typescript `
--tailwind `
--eslint `
--app `
--src-dir `
--import-alias "@/*" `
--use-npm
# Step 3: Copy Next.js files back to the current project directory
Write-ColorOutput Green "`nStep 3: Copying Next.js files to project directory..."
Set-Location -Path ..
# Create an array of files to preserve
$PRESERVE_FILES = @(
".nvmrc",
".npmrc",
".cursor\.cursorrules",
".cursor\tasks\init.md",
"README.md",
".env.local",
".env.example",
"setup.sh",
"setup.ps1"
)
# Copy all files from temp directory except those we want to preserve
$SOURCE_DIR = Join-Path -Path $PWD -ChildPath $TEMP_DIR
$ITEMS = Get-ChildItem -Path $SOURCE_DIR -Recurse -Force
foreach ($ITEM in $ITEMS) {
$RELATIVE_PATH = $ITEM.FullName.Substring($SOURCE_DIR.Length + 1)
# Skip .git and node_modules
if ($RELATIVE_PATH -like ".git\*" -or $RELATIVE_PATH -like "node_modules\*") {
continue
}
# Skip preserved files
$SKIP = $false
foreach ($FILE in $PRESERVE_FILES) {
if ($RELATIVE_PATH -eq $FILE) {
$SKIP = $true
break
}
}
if (-not $SKIP) {
$TARGET = Join-Path -Path $PWD -ChildPath $RELATIVE_PATH
$TARGET_DIR = Split-Path -Parent $TARGET
if (-not (Test-Path -Path $TARGET_DIR)) {
New-Item -Path $TARGET_DIR -ItemType Directory -Force | Out-Null
}
if (-not $ITEM.PSIsContainer) {
Copy-Item -Path $ITEM.FullName -Destination $TARGET -Force
}
}
}
# Step 4: Install Supabase
Write-ColorOutput Green "`nStep 4: Installing Supabase client..."
try {
npm --registry=https://registry.npmjs.org/ i @supabase/supabase-js@latest
} catch {
Write-ColorOutput Yellow "Initial installation failed. Trying with legacy peer deps..."
npm --registry=https://registry.npmjs.org/ i @supabase/supabase-js@latest --legacy-peer-deps
}
# Create environment files (only if they don't exist)
Write-ColorOutput Green "`nStep 5: Creating environment files..."
if (-not (Test-Path -Path ".env.local")) {
@"
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
"@ | Out-File -FilePath ".env.local" -Encoding utf8
}
if (-not (Test-Path -Path ".env.example")) {
@"
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
"@ | Out-File -FilePath ".env.example" -Encoding utf8
}
# Clean up temporary directory
Write-ColorOutput Green "`nCleaning up..."
try {
Remove-Item -Path $TEMP_DIR -Recurse -Force -ErrorAction Stop
Write-Output "Temporary directory removed successfully"
} catch {
Write-ColorOutput Yellow "Warning: Could not remove temporary directory automatically."
Write-ColorOutput Yellow "Please manually remove: $TEMP_DIR"
Write-ColorOutput Yellow "You can try: Remove-Item -Path '$TEMP_DIR' -Recurse -Force"
}
Write-ColorOutput Yellow "`nSetup complete!"
Write-Output "Your Next.js + Supabase blog template is ready."
Write-Output "Run 'npm run dev' to start the development server."