diff --git a/libs/create-qwikdev-astro/package.json b/libs/create-qwikdev-astro/package.json index e2f9741c..0a9414d5 100644 --- a/libs/create-qwikdev-astro/package.json +++ b/libs/create-qwikdev-astro/package.json @@ -7,6 +7,8 @@ "scripts": { "check": "tsc --noEmit", "build": "pnpm check && tsup-node --env.NODE_ENV production", + "prepublishOnly": "node --loader tsm src/prepare.ts", + "postpublish": "node --loader tsm src/prepare.ts --restore", "start": "tsup-node --env.NODE_ENV development --watch", "test": "NODE_ENV=test node --loader tsm --enable-source-maps bin/test.ts" }, @@ -86,10 +88,7 @@ }, "./package.json": "./package.json" }, - "files": [ - "dist", - "stubs" - ], + "files": ["dist", "stubs"], "bin": "./dist/cli.js", "keywords": [ "astro-integration", diff --git a/libs/create-qwikdev-astro/src/prepare.ts b/libs/create-qwikdev-astro/src/prepare.ts new file mode 100644 index 00000000..befdbea0 --- /dev/null +++ b/libs/create-qwikdev-astro/src/prepare.ts @@ -0,0 +1,35 @@ +import { existsSync, readdirSync, renameSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { logError, logInfo, logSuccess } from "./console"; +import { __dirname } from "./utils"; + +function renameGitignore(dir: string, restore = false) { + const files = readdirSync(dir, { withFileTypes: true }); + + for (const file of files) { + const filePath = join(dir, file.name); + + if (file.isDirectory()) { + renameGitignore(filePath, restore); + } else if (file.name === (restore ? ".gitignore" : "gitignore")) { + const newName = join(dir, restore ? "gitignore" : ".gitignore"); + renameSync(filePath, newName); + logSuccess(`Renamed "${filePath}" to "${newName}"`); + } + } +} + +const templates = join(dirname(__dirname), "stubs", "templates"); +const restore = process.argv.includes("--restore"); + +if (restore) { + logInfo("Restoring files to their original names..."); +} else { + logInfo("Backing up files to gitignore..."); +} + +if (existsSync(templates)) { + renameGitignore(templates, restore); +} else { + logError(`The "${templates}" directory doesn't exist.`); +} diff --git a/libs/create-qwikdev-astro/stubs/templates/deno-biome/.gitignore b/libs/create-qwikdev-astro/stubs/templates/deno-biome/gitignore similarity index 100% rename from libs/create-qwikdev-astro/stubs/templates/deno-biome/.gitignore rename to libs/create-qwikdev-astro/stubs/templates/deno-biome/gitignore diff --git a/libs/create-qwikdev-astro/stubs/templates/deno/.gitignore b/libs/create-qwikdev-astro/stubs/templates/deno/gitignore similarity index 100% rename from libs/create-qwikdev-astro/stubs/templates/deno/.gitignore rename to libs/create-qwikdev-astro/stubs/templates/deno/gitignore diff --git a/libs/create-qwikdev-astro/stubs/templates/node-biome/.gitignore b/libs/create-qwikdev-astro/stubs/templates/node-biome/gitignore similarity index 100% rename from libs/create-qwikdev-astro/stubs/templates/node-biome/.gitignore rename to libs/create-qwikdev-astro/stubs/templates/node-biome/gitignore diff --git a/libs/create-qwikdev-astro/stubs/templates/node/.gitignore b/libs/create-qwikdev-astro/stubs/templates/node/gitignore similarity index 100% rename from libs/create-qwikdev-astro/stubs/templates/node/.gitignore rename to libs/create-qwikdev-astro/stubs/templates/node/gitignore diff --git a/libs/create-qwikdev-astro/stubs/templates/none-biome/.gitignore b/libs/create-qwikdev-astro/stubs/templates/none-biome/gitignore similarity index 100% rename from libs/create-qwikdev-astro/stubs/templates/none-biome/.gitignore rename to libs/create-qwikdev-astro/stubs/templates/none-biome/gitignore diff --git a/libs/create-qwikdev-astro/stubs/templates/none/.gitignore b/libs/create-qwikdev-astro/stubs/templates/none/gitignore similarity index 100% rename from libs/create-qwikdev-astro/stubs/templates/none/.gitignore rename to libs/create-qwikdev-astro/stubs/templates/none/gitignore diff --git a/libs/qwikdev-astro/package.json b/libs/qwikdev-astro/package.json index 23037b98..5f55c69e 100644 --- a/libs/qwikdev-astro/package.json +++ b/libs/qwikdev-astro/package.json @@ -40,12 +40,7 @@ "./utils": "./src/utils.ts", "./q-astro-manifest.json": "./q-astro-manifest.json" }, - "files": [ - "src", - "src/index.ts", - "server.ts", - "env.d.ts" - ], + "files": ["src", "src/index.ts", "server.ts", "env.d.ts"], "keywords": [ "astro-integration", "astro-component",