From 5bf2c5bc0c32fd92c966c282c3f2f54308bee6ad Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 22 Jan 2024 20:17:18 +0100 Subject: [PATCH] feat: automatically add `.wrangler/state/v3` to `.gitignore` --- examples/nuxt/.gitignore | 2 ++ src/index.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/examples/nuxt/.gitignore b/examples/nuxt/.gitignore index 4a7f73a..1b37995 100644 --- a/examples/nuxt/.gitignore +++ b/examples/nuxt/.gitignore @@ -22,3 +22,5 @@ logs .env .env.* !.env.example + +.wrangler/state/v3 diff --git a/src/index.ts b/src/index.ts index f765fa6..9b6a1d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ import { fileURLToPath } from "node:url"; import { relative, resolve } from "node:path"; +import { promises as fs } from "node:fs"; import type { Nitro } from "nitropack"; import type { Nuxt } from "nuxt/schema"; import consola from "consola"; @@ -21,6 +22,18 @@ async function nitroModule(nitro: Nitro) { // Resolve the persist dir const persistDir = resolve(nitro.options.rootDir, ".wrangler/state/v3"); + // Add `.wrnagle/state/v3` to `.gitignore` + const gitIgnorePath = await findFile(".gitignore", { + startingFrom: nitro.options.rootDir, + }).catch(() => undefined); + if (gitIgnorePath) { + const gitIgnore = await fs.readFile(gitIgnorePath, "utf8"); + if (!gitIgnore.includes(".wrangler/state/v3")) { + consola.info("Adding `.wrangler/state/v3` to `.gitignore`..."); + await fs.writeFile(gitIgnorePath, gitIgnore + "\n.wrangler/state/v3\n"); + } + } + consola.box( [ "🔥 Cloudflare context bindings enabled for dev server",