|
1 | 1 | import { spawn, ChildProcess } from "child_process"; |
2 | 2 | import { join } from "path"; |
| 3 | +import { existsSync, copyFileSync } from "fs"; |
3 | 4 | import fetch from "node-fetch"; |
4 | 5 |
|
5 | 6 | // Helper function to kill process tree |
@@ -167,6 +168,9 @@ export class TemplateServerManager { |
167 | 168 | `Starting server for ${template.name} on port ${template.port}...`, |
168 | 169 | ); |
169 | 170 |
|
| 171 | + // Copy example env files if they exist |
| 172 | + this.copyEnvFiles(template.path); |
| 173 | + |
170 | 174 | const server = spawn("npm", ["run", "dev"], { |
171 | 175 | cwd: template.path, |
172 | 176 | stdio: "pipe", |
@@ -254,6 +258,23 @@ export class TemplateServerManager { |
254 | 258 | await Promise.all(promises); |
255 | 259 | } |
256 | 260 |
|
| 261 | + private copyEnvFiles(templatePath: string): void { |
| 262 | + const envFileMappings = [ |
| 263 | + { example: ".dev.vars.example", target: ".dev.vars" }, |
| 264 | + { example: ".env.local.example", target: ".env.local" }, |
| 265 | + ]; |
| 266 | + |
| 267 | + for (const { example, target } of envFileMappings) { |
| 268 | + const examplePath = join(templatePath, example); |
| 269 | + const targetPath = join(templatePath, target); |
| 270 | + |
| 271 | + if (existsSync(examplePath) && !existsSync(targetPath)) { |
| 272 | + copyFileSync(examplePath, targetPath); |
| 273 | + console.log(`Copied ${example} to ${target}`); |
| 274 | + } |
| 275 | + } |
| 276 | + } |
| 277 | + |
257 | 278 | private async waitForServer(url: string, timeout: number): Promise<void> { |
258 | 279 | const start = Date.now(); |
259 | 280 |
|
|
0 commit comments