elee
elee
DDeno
Created by elee on 10/14/2024 in #help
how to add a code generation hook pre-build in fresh
I have a bootstrapped fresh project. when running in dev mode with deno run --watch ... dev.ts, it uses deno's native watch feature and restarts the server when a file changes. in my needs, when a specific file types.ts I need to run a different generation script, something like deno ./generate.ts ./libs/types.ts ./libs/types.gen.ts If i try to execute this however in the dev.ts file, it loops forever, since the watcher triggers when the generated file is created, which causes the watcher to trigger generation again. first i tried to add the generation to the pre-build hook in the fresh config, but this seems to never trigger. is that prehook only related to generating the routes or something? or am i using it wrong? i then tried to use Deno.watchFs with just specifically the ./libs/types.ts file, but it seems that deno run --watch restarts the process before that event has a chance to run. and hmr watching seems to be 1. broken (i can't seem to get events), and 2. not supported for fresh anyways so at this point i'm confused what i'm supposed to do. adding --watch-exclude doesn't work because then my project doesn't restart when the generated file is created. to get something working, i just started running a separate watcher deno run --watch=./libs/types.ts, but this is really bad dx, needing to run a separate background task. i want ideally, to run a single script, which restarts when files changes, and runs the generation script on specific files changing. my current best thought is if is there any way perhaps to tell which files are the ones that changed when running with --watch, i could chose to only run the generation script on specific filenames changing
5 replies