@@ -42,7 +42,7 @@ import DesignReviewsService from '../services/design-reviews.services.js';
4242import BillOfMaterialsService from '../services/boms.services.js' ;
4343import UsersService from '../services/users.services.js' ;
4444import { transformDate } from '../utils/datetime.utils.js' ;
45- import { writeFileSync } from 'fs' ;
45+ import { writeFileSync , readFileSync } from 'fs' ;
4646import WbsElementTemplatesService from '../services/wbs-element-templates.services.js' ;
4747import RecruitmentServices from '../services/recruitment.services.js' ;
4848import OrganizationsService from '../services/organizations.services.js' ;
@@ -332,17 +332,25 @@ const performSeed: () => Promise<void> = async () => {
332332 changeRequest1 . proposedSolutions [ 0 ] . id
333333 ) ;
334334
335- /** Gets the current content of the .env file */
336- const currentEnv = process . env ;
335+ /** Set the organization ID in the current process environment and update .env */
336+ process . env . DEV_ORGANIZATION_ID = organizationId ;
337337
338- currentEnv . DEV_ORGANIZATION_ID = organizationId ;
338+ // Read existing .env file
339+ const envContent = readFileSync ( '.env' , 'utf-8' ) ;
339340
340- /** Write the new .env file with the organization ID */
341- let stringifiedEnv = '' ;
342- Object . keys ( currentEnv ) . forEach ( ( key ) => {
343- stringifiedEnv += `${ key } =${ currentEnv [ key ] } \n` ;
341+ const lines = envContent . split ( '\n' ) ;
342+ const updatedLines = lines . map ( ( line ) => {
343+ if ( line . startsWith ( 'DEV_ORGANIZATION_ID=' ) ) {
344+ return `DEV_ORGANIZATION_ID=${ organizationId } ` ;
345+ }
346+ return line ;
344347 } ) ;
345- writeFileSync ( '.env' , stringifiedEnv ) ;
348+
349+ if ( ! updatedLines . some ( ( line ) => line . startsWith ( 'DEV_ORGANIZATION_ID=' ) ) ) {
350+ updatedLines . push ( `DEV_ORGANIZATION_ID=${ organizationId } ` ) ;
351+ }
352+
353+ writeFileSync ( '.env' , updatedLines . join ( '\n' ) ) ;
346354
347355 /**
348356 * TEAMS
0 commit comments