UNPKG

@redwoodjs/sdk

Version:

A full-stack webapp toolkit designed for TypeScript, Vite, and React Server Components

32 lines (31 loc) 1.28 kB
import { resolve } from "node:path"; import { symlink, copyFile } from "node:fs/promises"; import { pathExists } from "fs-extra"; export async function setupEnvFiles({ rootDir, }) { const envPath = resolve(rootDir, ".env"); const devVarsPath = resolve(rootDir, ".dev.vars"); const envExamplePath = resolve(rootDir, ".env.example"); const envExists = await pathExists(envPath); const devVarsExists = await pathExists(devVarsPath); const envExampleExists = await pathExists(envExamplePath); // If .env.example exists but .env doesn't, copy from example to .env if (!envExists && !devVarsExists && envExampleExists) { try { await copyFile(envExamplePath, envPath); console.log("Created .env file from .env.example"); } catch (error) { console.warn("Failed to copy .env.example to .env:", error); } } // Create symlink from .env to .dev.vars if needed if ((await pathExists(envPath)) && !devVarsExists) { try { await symlink(envPath, devVarsPath); console.log("Created symlink from .env to .dev.vars"); } catch (error) { console.warn("Failed to create symlink from .env to .dev.vars:", error); } } }