All files index.ts

0% Statements 0/12
0% Branches 0/2
0% Functions 0/1
0% Lines 0/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                                                                         
import fs from 'fs';
import { dotenvLoader, fileWriter } from './functions';
 
const main = () => {
  //* Change directory to the project root where the .env file is located *//
  process.chdir('../');
 
  //* Check current directory is project root *//
  if (!fs.existsSync('pay-crew2')) {
    throw new Error('This script must be run from the root directory of the project');
  }
 
  //* Load environment variables from .env file *//
  const envConfig = dotenvLoader();
 
  //* Create secret configuration files *//
  {
    // frontend
    const frontendDotenvData = `VITE_API_URL=${envConfig.frontendConfig.viteApiUrl}
VITE_CLIENT_URL=${envConfig.frontendConfig.viteClientUrl}
VITE_IDENTEAPOT_SALT=${envConfig.frontendConfig.viteIdenteapotSalt}
`;
    fileWriter('./products/frontend/.env', frontendDotenvData);
  }
 
  {
    // backend
    const wranglerData = `{
    "$schema": "node_modules/wrangler/config-schema.json",
    "name": "pay-crew2-backend",
    "main": "src/index.ts",
    "compatibility_date": "2025-12-04",
    "compatibility_flags": [
        "nodejs_compat"
    ],
    "hyperdrive": [
        {
            "binding": "HYPERDRIVE",
            "id": "dummy",
            "localConnectionString": "postgresql://${envConfig.backendConfig.postgresUser}:${envConfig.backendConfig.postgresPassword}@localhost:${envConfig.backendConfig.postgresPort}/${envConfig.backendConfig.postgresDb}"
        }
    ],
    "vars": {
        "BETTER_AUTH_URL": "${envConfig.backendConfig.betterAuthUrl}",
        "BETTER_AUTH_SECRET": "${envConfig.backendConfig.betterAuthSecret}",
        "DISCORD_CLIENT_ID": "${envConfig.backendConfig.discordClientId}",
        "DISCORD_CLIENT_SECRET": "${envConfig.backendConfig.discordClientSecret}",
        "GOOGLE_CLIENT_ID": "${envConfig.backendConfig.googleClientId}",
        "GOOGLE_CLIENT_SECRET": "${envConfig.backendConfig.googleClientSecret}"
    }
}
`;
    fileWriter('./products/backend/wrangler.local.jsonc', wranglerData);
 
    const backendDotenvData = `DATABASE_URL=postgresql://${envConfig.backendConfig.postgresUser}:${envConfig.backendConfig.postgresPassword}@localhost:${envConfig.backendConfig.postgresPort}/${envConfig.backendConfig.postgresDb}
DATABASE_CREDENTIALS_SSL_REJECT_UNAUTHORIZED=${envConfig.backendConfig.dbCredentialsSslRejectUnauthorized}
BETTER_AUTH_URL=${envConfig.backendConfig.betterAuthUrl}
BETTER_AUTH_SECRET=${envConfig.backendConfig.betterAuthSecret}
DISCORD_CLIENT_ID=${envConfig.backendConfig.discordClientId}
DISCORD_CLIENT_SECRET=${envConfig.backendConfig.discordClientSecret}
GOOGLE_CLIENT_ID=${envConfig.backendConfig.googleClientId}
GOOGLE_CLIENT_SECRET=${envConfig.backendConfig.googleClientSecret}
`;
    fileWriter('./products/backend/.env', backendDotenvData);
  }
};
 
main();