Skip to content

Commit

Permalink
πŸ“¦ Use release hooks to manage .gitignore files
Browse files Browse the repository at this point in the history
  • Loading branch information
siguici committed Dec 25, 2024
1 parent 9495339 commit e1daaeb
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 10 deletions.
7 changes: 3 additions & 4 deletions libs/create-qwikdev-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -86,10 +88,7 @@
},
"./package.json": "./package.json"
},
"files": [
"dist",
"stubs"
],
"files": ["dist", "stubs"],
"bin": "./dist/cli.js",
"keywords": [
"astro-integration",
Expand Down
35 changes: 35 additions & 0 deletions libs/create-qwikdev-astro/src/prepare.ts
Original file line number Diff line number Diff line change
@@ -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.`);
}
7 changes: 1 addition & 6 deletions libs/qwikdev-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e1daaeb

Please sign in to comment.