@@ -5,9 +5,18 @@ import log from 'electron-log';
55import path from 'node:path' ;
66import fs from 'node:fs/promises' ;
77import { exec } from 'node:child_process' ;
8- import { promisify } from 'node:util' ;
98
10- const execAsync = promisify ( exec ) ;
9+ const execAsync = ( command : string , options ?: any ) => {
10+ return new Promise < string > ( ( resolve , reject ) => {
11+ exec ( command , options , ( error , stdout , _stderr ) => {
12+ if ( error ) {
13+ reject ( error ) ;
14+ } else {
15+ resolve ( stdout ?. toString ( ) || '' ) ;
16+ }
17+ } ) ;
18+ } ) ;
19+ } ;
1120import * as pkg from '../../package.json' ;
1221import { setupAutoUpdater } from './utils/auto-update' ;
1322import { isDev , DEFAULT_PORT } from './utils/constants' ;
@@ -163,18 +172,18 @@ declare global {
163172
164173 const rendererURL = await ( isDev
165174 ? ( async ( ) => {
166- await initViteServer ( ) ;
175+ await initViteServer ( ) ;
167176
168- if ( ! viteServer ) {
169- throw new Error ( 'Vite server is not initialized' ) ;
170- }
177+ if ( ! viteServer ) {
178+ throw new Error ( 'Vite server is not initialized' ) ;
179+ }
171180
172- const listen = await viteServer . listen ( ) ;
173- global . __electron__ = electron ;
174- viteServer . printUrls ( ) ;
181+ const listen = await viteServer . listen ( ) ;
182+ global . __electron__ = electron ;
183+ viteServer . printUrls ( ) ;
175184
176- return `http://localhost:${ listen . config . server . port } ` ;
177- } ) ( )
185+ return `http://localhost:${ listen . config . server . port } ` ;
186+ } ) ( )
178187 : `http://localhost:${ DEFAULT_PORT } ` ) ;
179188
180189 console . log ( 'Using renderer URL:' , rendererURL ) ;
@@ -301,6 +310,7 @@ declare global {
301310 await execAsync ( 'git commit -m "Init codinit app"' , { cwd : projectDir } ) ;
302311 } catch ( gitError ) {
303312 console . warn ( `Git initialization failed for ${ projectName } :` , gitError ) ;
313+
304314 // Don't fail the whole process if git fails
305315 }
306316
@@ -311,27 +321,30 @@ declare global {
311321 }
312322 } ) ;
313323
314- ipcMain . handle ( 'save-file-local' , async ( _ , projectName : string , filePath : string , content : string | Uint8Array ) => {
315- try {
316- const home = app . getPath ( 'home' ) ;
317- const appsDir = path . join ( home , 'codinit-apps' ) ;
318- const projectDir = path . join ( appsDir , projectName ) ;
319- const fullPath = path . join ( projectDir , filePath ) ;
320-
321- await fs . mkdir ( path . dirname ( fullPath ) , { recursive : true } ) ;
322-
323- if ( typeof content === 'string' ) {
324- await fs . writeFile ( fullPath , content , 'utf8' ) ;
325- } else {
326- await fs . writeFile ( fullPath , Buffer . from ( content ) ) ;
324+ ipcMain . handle (
325+ 'save-file-local' ,
326+ async ( _ , projectName : string , filePath : string , content : string | Uint8Array ) => {
327+ try {
328+ const home = app . getPath ( 'home' ) ;
329+ const appsDir = path . join ( home , 'codinit-apps' ) ;
330+ const projectDir = path . join ( appsDir , projectName ) ;
331+ const fullPath = path . join ( projectDir , filePath ) ;
332+
333+ await fs . mkdir ( path . dirname ( fullPath ) , { recursive : true } ) ;
334+
335+ if ( typeof content === 'string' ) {
336+ await fs . writeFile ( fullPath , content , 'utf8' ) ;
337+ } else {
338+ await fs . writeFile ( fullPath , Buffer . from ( content ) ) ;
339+ }
340+
341+ return true ;
342+ } catch ( error ) {
343+ console . error ( 'Failed to save file locally:' , error ) ;
344+ return false ;
327345 }
328-
329- return true ;
330- } catch ( error ) {
331- console . error ( 'Failed to save file locally:' , error ) ;
332- return false ;
333- }
334- } ) ;
346+ } ,
347+ ) ;
335348
336349 return win ;
337350 } )
0 commit comments