Skip to content

Commit

Permalink
fix(dotenvcreate): update dotenvcreate script to ensure .env file is …
Browse files Browse the repository at this point in the history
…created in the script's directory
  • Loading branch information
merrcury committed Dec 30, 2024
1 parent 3aecbe3 commit ba7a3d1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions apps/api/src/dotenvcreate.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

console.time('dotenvcreate');

Expand All @@ -10,6 +11,10 @@ const secretsManagerClient = new SecretsManagerClient({

const secretName = process.argv[2];

// Get the directory of the current script
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Function to retrieve secret value
async function getSecretValue(secretName) {
try {
Expand Down Expand Up @@ -45,7 +50,7 @@ function escapeValue(value) {
async function updateEnvFile() {
try {
const secret = await getSecretValue(secretName);
const envPath = resolve('.env');
const envPath = resolve(__dirname, '.env'); // Ensure .env is created in the script's directory

// Read the existing .env file if it exists
let envContent = '';
Expand Down Expand Up @@ -90,4 +95,4 @@ async function updateEnvFile() {

// Run the script
updateEnvFile();
console.timeEnd('dotenvcreate');
console.timeEnd('dotenvcreate');

0 comments on commit ba7a3d1

Please sign in to comment.