Append new rules to existing .htaccess file instead of overwriting it.

This commit is contained in:
Bad Manners 2024-09-01 09:17:47 -03:00
parent 5ac64c5db6
commit 4b56fd20ae
Signed by: badmanners
GPG key ID: 8C88292CCB075609
2 changed files with 16 additions and 1 deletions

13
CHANGELOG.md Normal file
View file

@ -0,0 +1,13 @@
# Changelog
## 0.2.0
Append new rules to existing `.htaccess` file instead of overwriting it.
## 0.1.2
Fix redirects by checking the `redirect` field.
## 0.1.1
Initial release.

View file

@ -1,4 +1,5 @@
import type { AstroIntegration } from "astro";
import { existsSync } from "node:fs";
import { writeFile } from "node:fs/promises";
import path, { posix as pathPosix } from "node:path";
import { fileURLToPath, URL } from "node:url";
@ -176,7 +177,8 @@ export const integration = ({ generateHtaccessFile, errorPages, redirects, custo
.map((fn) => fn())
.flat();
if (!error) {
await writeFile(path.join(assetsDir, ".htaccess"), htaccess.join("\n"));
const htaccessPath = path.join(assetsDir, ".htaccess");
await writeFile(htaccessPath, [existsSync(htaccessPath) ? "\n" : "", htaccess.join("\n")], { flag: 'a' });
logger.info(`Generated .htaccess with ${htaccess.length} ${htaccess.length === 1 ? "rule" : "rules"}`);
}
},