| 9 | const scriptDir = import.meta.dirname; |
| 10 | const openapiPath = join(scriptDir, "../../../apps/api/openapi/openapi.json"); |
| 11 | |
| 12 | function waitForFile() { |
| 13 | if (existsSync(openapiPath)) { |
| 14 | logger.info("✅ openapi.json found, starting watcher..."); |
| 15 | const child = exec( |
| 16 | `chokidar "${openapiPath}" -c "pnpm generate" --initial`, |
| 17 | { cwd: join(scriptDir, "..") }, |
| 18 | (error) => { |
| 19 | if (error) { |
| 20 | logger.error({ error }, "❌ Watcher error"); |
| 21 | process.exit(1); |
| 22 | } |
| 23 | } |
| 24 | ); |
| 25 | child.stdout?.pipe(process.stdout); |
| 26 | child.stderr?.pipe(process.stderr); |
| 27 | } else { |
| 28 | logger.info("⏳ Waiting for openapi.json..."); |
| 29 | setTimeout(waitForFile, 500); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | waitForFile(); |