diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 00000000..49972c47 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +bun run dev:restore diff --git a/bun.lock b/bun.lock index c50477ef..b4f84baf 100644 --- a/bun.lock +++ b/bun.lock @@ -47,6 +47,7 @@ "@types/react-dom": "^19.2.3", "eslint": "^9.39.1", "eslint-config-next": "16.0.7", + "husky": "^9.1.7", "postcss": "^8.5.6", "prettier": "^3.7.4", "prettier-plugin-tailwindcss": "^0.7.2", @@ -905,6 +906,8 @@ "html-void-elements": ["html-void-elements@3.0.0", "", {}, "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg=="], + "husky": ["husky@9.1.7", "", { "bin": { "husky": "bin.js" } }, "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA=="], + "hyphenate-style-name": ["hyphenate-style-name@1.1.0", "", {}, "sha512-WDC/ui2VVRrz3jOVi+XtjqkDjiVjTtFaAGiW37k6b+ohyQ5wYDOGkvCZa8+H0nx3gyvv0+BST9xuOgIyGQ00gw=="], "ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], diff --git a/package.json b/package.json index 7997901a..e537cf20 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,15 @@ "scripts": { "build": "bun run prebuild.ts && next build", "dev": "bun run prebuild.ts && next dev", + "dev:local": "bun run predev.ts && next dev", + "dev:restore": "bun run restore-languages.ts", "start": "next start", "types:check": "fumadocs-mdx && tsc --noEmit", "postinstall": "fumadocs-mdx", "lint": "eslint", "format": "prettier --write .", - "format:check": "prettier --check ." + "format:check": "prettier --check .", + "prepare": "husky" }, "dependencies": { "@mdx-js/mdx": "^3.1.1", @@ -55,6 +58,7 @@ "@types/react-dom": "^19.2.3", "eslint": "^9.39.1", "eslint-config-next": "16.0.7", + "husky": "^9.1.7", "postcss": "^8.5.6", "prettier": "^3.7.4", "prettier-plugin-tailwindcss": "^0.7.2", diff --git a/predev.ts b/predev.ts new file mode 100644 index 00000000..e729e209 --- /dev/null +++ b/predev.ts @@ -0,0 +1,57 @@ +import { $ } from "bun"; +import { rmdir } from "fs/promises"; +import { existsSync } from "fs"; + +console.log("Preparing development environment..."); + +//check if git is available +$`git --version`.catch(() => { + console.warn("Git is not available. Skipping git-info.json generation."); + process.exit(0); +}); + + +const languagesToRemove = [ + "af-ZA", + "ar-SA", + "cs-CZ", + "da-DK", + "de-DE", + "es-ES", + "fr-FR", + "hi-IN", + "hu-HU", + "id-ID", + "it-IT", + "ja-JP", + "lt-LT", + "lv-LV", + "nl-NL", + "pl-PL", + "pt-BR", + "pt-PT", + "ro-RO", + "ru-RU", + "sq-AL", + "sv-SE", + "tr-TR", + "uk-UA", + "vi-VN", +]; + +console.log("Removing non-English language directories from content/docs/..."); + +const removePromises = languagesToRemove.map(async (lang) => { + const path = `content/docs/${lang}`; + if (existsSync(path)) { + await rmdir(path, { recursive: true }); + console.log(`Removed ${lang}`); + } +}); + +await Promise.all(removePromises); + +console.log("Development environment ready (English only for faster builds)"); +console.log( + "Run 'bun run dev:restore' to restore all languages after development", +); diff --git a/restore-languages.ts b/restore-languages.ts new file mode 100644 index 00000000..fdd86b90 --- /dev/null +++ b/restore-languages.ts @@ -0,0 +1,54 @@ +console.log("Restoring language directories..."); + +import { $ } from "bun"; + +const languagesToRestore = [ + "af-ZA", + "ar-SA", + "cs-CZ", + "da-DK", + "de-DE", + "es-ES", + "fr-FR", + "hi-IN", + "hu-HU", + "id-ID", + "it-IT", + "ja-JP", + "lt-LT", + "lv-LV", + "nl-NL", + "pl-PL", + "pt-BR", + "pt-PT", + "ro-RO", + "ru-RU", + "sq-AL", + "sv-SE", + "tr-TR", + "uk-UA", + "vi-VN", +]; + +console.log("Restoring deleted language directories from git..."); + +try { + // Restore each language directory individually + for (const lang of languagesToRestore) { + const path = `./content/docs/${lang}/`; + try { + await $`git reset -q -- ${path}`; // Unstage any changes to the directory + await $`git restore -q ${path}`; // Restore the directory from the last commit + await $`git add ${path}`; // Stage the restored directory + console.log(` Restored ${lang}`); + } catch { + // If the directory was not deleted or already restored, ignore the error + } + } + + console.log("All language directories restored successfully"); + console.log("Your changes in content/docs/en remain untouched\n"); +} catch (error) { + console.log("Something went wrong while restoring languages:"); + console.error(error); +}