diff --git a/src/module.ts b/src/module.ts index 45f0b0c..780a98c 100644 --- a/src/module.ts +++ b/src/module.ts @@ -19,6 +19,7 @@ export interface ModuleOptions { devtools: boolean watch: boolean watchPrompt: true + dbWatchMode: boolean dbschemaDir: string queriesDir: string queryBuilderDir: string @@ -56,6 +57,7 @@ const nuxtModule = defineNuxtModule({ devtools: true, watch: true, watchPrompt: true, + dbWatchMode: false, generateTarget: 'ts', dbschemaDir: 'dbschema', queriesDir: 'queries', @@ -311,7 +313,34 @@ const nuxtModule = defineNuxtModule({ * Watchers */ - if (canPrompt && options.watch) { + if (options.dbWatchMode && !nuxt.options._prepare) { + const edb_watch_process = execa.execa('edgedb', ['watch', '--verbose'], { cwd: resolveProject(), buffer: false }) + + const extractDDLs = (input: string) => { + const pattern = /(?:ALTER|CREATE|DROP)([\s\S]+?(};))/g + const matches = input.match(pattern) + return matches || [] + } + const excluded_logs = [ + 'EdgeDB Watch initialized.', + `Monitoring "${resolveProject()}".`, + ] + + edb_watch_process.stderr!.on('data', async (chunk: string) => { + const content = chunk.toString() + const ddls = extractDDLs(content) + if (ddls.length) { + await generateInterfaces() + await generateQueryBuilder() + success(`EdgeDB - schema changes detected`) + } + else if (!excluded_logs.some(e => content.includes(e))) { + console.log(content) + } + }) + success('Running \'edgedb watch\' mode in the background.', true) + } + else if (canPrompt && options.watch) { nuxt.options.watch.push(`${dbschemaDir}/*`) nuxt.options.watch.push(`${dbschemaDir}/migrations/*`) nuxt.options.watch.push(`${queriesDir}/*`)