@@ -304,70 +304,25 @@ export default defineNuxtModule<ModuleOptions>({
304
304
* Watchers
305
305
*/
306
306
307
- async function maybeTriggerGenerateQueries ( path : string ) {
308
- if ( path . includes ( options . queriesDir ) && path . endsWith ( '.edgeql' ) ) {
309
- success ( `Queries changes detected on: ${ edgeColor ( path . replace ( options . dbschemaDir , '' ) ) } ` )
310
- try {
311
- if ( options . watchPrompt ) {
312
- if ( activePrompts . queriesPrompt )
313
- return
314
-
315
- activePrompts . queriesPrompt = prompts (
316
- {
317
- type : 'confirm' ,
318
- name : 'value' ,
319
- message : 'Do you want to generate queries files?' ,
320
- } ,
321
- {
322
- onSubmit ( ) {
323
- activePrompts . queriesPrompt = undefined
324
- } ,
325
- onCancel ( ) {
326
- activePrompts . queriesPrompt = undefined
327
- } ,
328
- } ,
329
- )
330
- const response = await activePrompts . queriesPrompt
331
- if ( response ?. value === true ) {
332
- await generateQueries ( )
333
- success ( 'Successfully generated queries!' )
334
- }
335
- }
336
- else {
337
- await generateQueries ( )
338
- success ( 'Successfully generated queries!' )
339
- }
340
- }
341
- catch ( e ) {
342
- //
343
- }
344
- return
345
- }
346
-
347
- }
348
-
349
307
if ( options . dbWatchMode ) {
350
- const edb_watch_process = execa . execa ( 'edgedb' , [ 'watch' ] , { cwd : resolveProject ( ) , detached : true , stdio : 'ignore' } )
351
- edb_watch_process . unref ( )
352
-
353
- success ( "Running 'edgedb watch' mode in the background." , true )
354
- nuxt . options . watch . push ( `${ dbschemaDir } /*` )
355
- nuxt . options . watch . push ( `${ queriesDir } /*` )
308
+ const edb_watch_process = execa . execa ( 'edgedb' , [ 'watch' , '--verbose' ] , { cwd : resolveProject ( ) , buffer : false } )
356
309
357
- nuxt . hook ( 'builder:watch' , async ( event , path ) => {
358
- if ( event === 'add' || event === 'change' || event === 'unlink' || event === 'unlinkDir' ) {
359
- // Queries
360
- await maybeTriggerGenerateQueries ( path )
310
+ const extractDDLs = ( input : string ) => {
311
+ const pattern = / (?: A L T E R | C R E A T E | D R O P ) ( [ \s \S ] + ?( } ; ) ) / g
312
+ const matches = input . match ( pattern )
313
+ return matches || [ ]
314
+ }
361
315
362
- // Query Builder & Interface
363
- if ( path . includes ( options . dbschemaDir ) && path . endsWith ( '.esdl' ) ) {
364
- success ( `Schema changes detected on: ${ edgeColor ( path . replace ( options . dbschemaDir , '' ) ) } ` )
365
- await generateInterfaces ( )
366
- await generateQueryBuilder ( )
367
- }
316
+ edb_watch_process . stderr ! . on ( 'data' , async ( chunk : string ) => {
317
+ const content = chunk . toString ( )
318
+ const ddls = extractDDLs ( content )
319
+ if ( ddls . length ) {
320
+ await generateInterfaces ( )
321
+ await generateQueryBuilder ( )
322
+ success ( `Schema changes detected - interface & query builder updated` )
368
323
}
369
-
370
324
} )
325
+ success ( 'Running \'edgedb watch\' mode in the background.' , true )
371
326
}
372
327
else if ( canPrompt && options . watch ) {
373
328
nuxt . options . watch . push ( `${ dbschemaDir } /*` )
@@ -377,7 +332,44 @@ export default defineNuxtModule<ModuleOptions>({
377
332
nuxt . hook ( 'builder:watch' , async ( event , path ) => {
378
333
if ( event === 'add' || event === 'change' || event === 'unlink' || event === 'unlinkDir' ) {
379
334
// Queries
380
- await maybeTriggerGenerateQueries ( path )
335
+ if ( path . includes ( options . queriesDir ) && path . endsWith ( '.edgeql' ) ) {
336
+ success ( `Queries changes detected on: ${ edgeColor ( path . replace ( options . dbschemaDir , '' ) ) } ` )
337
+ try {
338
+ if ( options . watchPrompt ) {
339
+ if ( activePrompts . queriesPrompt )
340
+ return
341
+
342
+ activePrompts . queriesPrompt = prompts (
343
+ {
344
+ type : 'confirm' ,
345
+ name : 'value' ,
346
+ message : 'Do you want to generate queries files?' ,
347
+ } ,
348
+ {
349
+ onSubmit ( ) {
350
+ activePrompts . queriesPrompt = undefined
351
+ } ,
352
+ onCancel ( ) {
353
+ activePrompts . queriesPrompt = undefined
354
+ } ,
355
+ } ,
356
+ )
357
+ const response = await activePrompts . queriesPrompt
358
+ if ( response ?. value === true ) {
359
+ await generateQueries ( )
360
+ success ( 'Successfully generated queries!' )
361
+ }
362
+ }
363
+ else {
364
+ await generateQueries ( )
365
+ success ( 'Successfully generated queries!' )
366
+ }
367
+ }
368
+ catch ( e ) {
369
+ //
370
+ }
371
+ return
372
+ }
381
373
382
374
// Migrations
383
375
if ( path . includes ( `${ options . dbschemaDir } /migrations` ) && path . endsWith ( '.edgeql' ) ) {
0 commit comments