@@ -16,24 +16,6 @@ const needsSudoForDocker = (): boolean => {
1616 }
1717} ;
1818
19- const runCommand = ( command : string , throwOnError = true ) => {
20- try {
21- let finalCommand = command ;
22- if ( command . includes ( 'docker' ) && needsSudoForDocker ( ) ) {
23- finalCommand = `sudo ${ command } ` ;
24- console . log ( 'ℹ️ Using sudo for Docker commands (run without sudo after logging out/in)' ) ;
25- }
26- execSync ( finalCommand , { stdio : 'inherit' , cwd : ROOT_DIR , env : process . env } ) ;
27- } catch ( error ) {
28- console . error ( `❌ Command failed: ${ command } ` ) ;
29- if ( throwOnError ) {
30- process . exit ( 1 ) ;
31- } else {
32- throw error ;
33- }
34- }
35- } ;
36-
3719async function main ( ) {
3820 console . log ( '\n🚀 Talawa API Local Setup\n' ) ;
3921
@@ -45,7 +27,7 @@ async function main() {
4527 }
4628
4729 console . log ( '\n⚙️ Running database setup (generating JWT secret, configuring services)...' ) ;
48- runCommand ( 'pnpm tsx setup.ts' ) ;
30+ execSync ( 'pnpm tsx setup.ts' ) ;
4931
5032 console . log ( '\n🔄 Adjusting .env for local machine access...' ) ;
5133 let envContent = fs . readFileSync ( ENV_DEST , 'utf-8' ) ;
@@ -83,18 +65,18 @@ async function main() {
8365 console . log ( '✅ .env updated: Database services point to localhost' ) ;
8466
8567 console . log ( '\n📦 Installing DevContainer CLI...' ) ;
86- runCommand ( 'pnpm install -g @devcontainers/cli' ) ;
68+ execSync ( 'pnpm install -g @devcontainers/cli' ) ;
8769
8870 // Add user to docker group if needed (Linux only)
8971 if ( process . platform === 'linux' && needsSudoForDocker ( ) ) {
9072 console . log ( '\n🔧 Adding user to docker group...' ) ;
91- const username = process . env . USER || process . env . USERNAME || 'ubuntu' ;
92- runCommand ( ` sudo usermod -a -G docker ${ username } ` ) ;
73+ execSync ( 'sudo usermod -a -G docker $USER' ) ;
74+ execSync ( ' sudo su $USER -' )
9375 console . log ( 'ℹ️ You may need to log out and back in for docker group changes to take effect' ) ;
9476 }
9577
9678 console . log ( '\n🐳 Starting Database Containers...' ) ;
97- runCommand ( 'devcontainer up --workspace-folder . --skip-post-create' ) ;
79+ execSync ( 'devcontainer up --workspace-folder . --skip-post-create' ) ;
9880
9981 console . log ( '\n⏳ Waiting for database services to be healthy...' ) ;
10082 let retries = 10 ;
@@ -114,7 +96,7 @@ async function main() {
11496 }
11597
11698 console . log ( '\n📊 Applying database migrations...' ) ;
117- runCommand ( 'pnpm run apply_drizzle_migrations' ) ;
99+ execSync ( 'pnpm run apply_drizzle_migrations' ) ;
118100
119101 const dataAnswer = await inquirer . prompt ( [
120102 {
@@ -128,32 +110,19 @@ async function main() {
128110 if ( dataAnswer . addSampleData ) {
129111 console . log ( '\n🌱 Seeding Sample Data...' ) ;
130112 try {
131- runCommand ( 'pnpm run add:sample_data' , false ) ;
113+ execSync ( 'pnpm run add:sample_data' , { stdio : 'inherit' } ) ;
132114 console . log ( '✅ Sample data seeded successfully' ) ;
133115 } catch ( error ) {
134116 console . log ( '⚠️ Sample data seeding failed, but you can run it manually later:' ) ;
135117 console . log ( ' pnpm run add:sample_data' ) ;
136118 }
137119 }
138120
139- const startAnswer = await inquirer . prompt ( [
140- {
141- type : 'confirm' ,
142- name : 'startServer' ,
143- message : 'Do you want to start the development server now?' ,
144- default : true ,
145- } ,
146- ] ) ;
147-
148- if ( startAnswer . startServer ) {
149- console . log ( '\n🚀 Starting Development Server...' ) ;
150- try {
151- execSync ( 'pnpm run start_development_server' , { stdio : 'inherit' } ) ;
152- } catch ( e ) {
153- console . log ( '\nServer stopped.' ) ;
154- }
155- } else {
156- console . log ( '⚠️ Restart your terminal to use pnpm manually.' ) ;
121+ console . log ( '\n🚀 Starting Development Server...' ) ;
122+ try {
123+ execSync ( 'pnpm run start_development_server' , { stdio : 'inherit' } ) ;
124+ } catch ( e ) {
125+ console . log ( '\nServer stopped.' ) ;
157126 }
158127}
159128
0 commit comments