-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
executable file
·187 lines (166 loc) · 5.69 KB
/
Copy pathsetup.js
File metadata and controls
executable file
·187 lines (166 loc) · 5.69 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
#!/usr/bin/env node
const readline = require("readline")
const fs = require("fs")
const path = require("path")
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
const envConfig = {}
console.log("\n🚀 Welcome to Docbase Setup!\n")
console.log("This wizard will help you configure your environment variables.\n")
console.log("Press Ctrl+C at any time to exit.\n")
const questions = [
{
key: "NEXT_PUBLIC_SITE_URL",
question:
"Enter your site URL (e.g., http://localhost:3000 for local, https://yourdomain.com for production): ",
validate: (value) => {
if (!value) return "Site URL is required"
if (!value.startsWith("http://") && !value.startsWith("https://")) {
return "Site URL must start with http:// or https://"
}
return true
},
help: "This is the URL where your application will be accessed. Use http://localhost:3000 for local development.",
},
{
key: "NEXT_PUBLIC_SUPABASE_URL",
question:
"Enter your Supabase project URL (from Supabase Dashboard > Project Settings > API): ",
validate: (value) => {
if (!value) return "Supabase URL is required"
if (!value.includes("supabase.co")) {
return "Should be a Supabase URL (e.g., https://xxx.supabase.co)"
}
return true
},
help: "Get this from: https://app.supabase.com > Your Project > Settings > API > Project URL",
},
{
key: "NEXT_PUBLIC_SUPABASE_ANON_KEY",
question: "Enter your Supabase anon/public key: ",
validate: (value) => (value ? true : "Supabase anon key is required"),
help: "Get this from: https://app.supabase.com > Your Project > Settings > API > Project API keys > anon public",
},
{
key: "SUPABASE_SERVICE_ROLE_KEY",
question: "Enter your Supabase service role key: ",
validate: (value) =>
value ? true : "Supabase service role key is required",
help: "Get this from: https://app.supabase.com > Your Project > Settings > API > Project API keys > service_role (Keep this secret!)",
},
{
key: "NEXT_PUBLIC_GOOGLE_MAPS_API_KEY",
question:
"Enter your Google Maps API key (optional, press Enter to skip): ",
validate: () => true,
optional: true,
help: "Get this from: https://developers.google.com/maps/documentation/javascript/get-api-key",
},
{
key: "RESEND_API_KEY",
question: "Enter your Resend API key (optional, press Enter to skip): ",
validate: () => true,
optional: true,
help: "Get this from: https://resend.com/api-keys (Required for sending emails)",
},
{
key: "OPENAI_API_KEY",
question: "Enter your OpenAI API key (optional, press Enter to skip): ",
validate: () => true,
optional: true,
help: "Get this from: https://platform.openai.com/api-keys (Required for signature block parsing)",
},
{
key: "BRAINTRUST_API_KEY",
question: "Enter your Braintrust API key (optional, press Enter to skip): ",
validate: () => true,
optional: true,
help: "Get this from: https://braintrust.dev (Required for prompt management and logging)",
},
]
function askQuestion(index) {
if (index >= questions.length) {
createEnvFile()
return
}
const q = questions[index]
console.log(`\n📝 ${q.key}`)
console.log(`💡 ${q.help}`)
rl.question(`${q.question}`, (answer) => {
const trimmedAnswer = answer.trim()
// Allow empty for optional fields
if (!trimmedAnswer && q.optional) {
console.log(`⏭️ Skipped (optional)`)
askQuestion(index + 1)
return
}
const validation = q.validate(trimmedAnswer)
if (validation !== true) {
console.log(`❌ ${validation}`)
askQuestion(index) // Ask again
return
}
envConfig[q.key] = trimmedAnswer
console.log("✅ Saved")
askQuestion(index + 1)
})
}
function createEnvFile() {
console.log("\n📄 Creating .env file...\n")
const envContent = Object.entries(envConfig)
.map(([key, value]) => `${key}="${value}"`)
.join("\n")
const envPath = path.join(process.cwd(), ".env")
// Check if .env already exists
if (fs.existsSync(envPath)) {
rl.question(
"\n⚠️ .env file already exists. Overwrite? (y/N): ",
(answer) => {
if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes") {
writeEnvFile(envPath, envContent)
} else {
console.log(
"\n❌ Setup cancelled. Your existing .env file was not modified.\n"
)
rl.close()
}
}
)
} else {
writeEnvFile(envPath, envContent)
}
}
function writeEnvFile(envPath, content) {
fs.writeFileSync(envPath, content)
console.log("✅ .env file created successfully!\n")
console.log("📋 Your configuration:\n")
console.log(content)
console.log("\n")
showNextSteps()
rl.close()
}
function showNextSteps() {
console.log("🎉 Setup Complete!\n")
console.log("📌 Next Steps:\n")
console.log("1. Install dependencies:")
console.log(" npm install\n")
console.log("2. Set up Supabase database:")
console.log(" npx supabase login")
console.log(" npx supabase link")
console.log(" npx supabase db push\n")
console.log("3. Create storage bucket in Supabase Dashboard:")
console.log(" - Go to Storage > Create bucket")
console.log(' - Name: "cube"')
console.log(" - Make it public\n")
console.log("4. (Optional) Set up Braintrust prompts:")
console.log(" npx braintrust push braintrust/docbase.ts\n")
console.log("5. Start the development server:")
console.log(" npm run dev\n")
console.log("6. Open http://localhost:3000 in your browser\n")
console.log("📚 For more details, see README.md\n")
}
// Start the wizard
console.log("Let's get started! 🎯\n")
askQuestion(0)