🔧 create example env
Create .env.example to help you figure out what variables should be in the .env file. Run the command `bun run env:publish` to sync the .env.example file with the .env file.
This commit is contained in:
8
.env.example
Normal file
8
.env.example
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
APP_NAME="Astofo TV"
|
||||||
|
APP_ENV="development"
|
||||||
|
APP_DOMAIN=
|
||||||
|
APP_PORT=3000
|
||||||
|
|
||||||
|
MAIN_BACKEND_API_URL=
|
||||||
|
API_KEY=
|
||||||
|
JWT_TOKEN=
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -31,7 +31,7 @@ yarn-error.log*
|
|||||||
.pnpm-debug.log*
|
.pnpm-debug.log*
|
||||||
|
|
||||||
# env files (can opt-in for committing if needed)
|
# env files (can opt-in for committing if needed)
|
||||||
.env*
|
.env
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|||||||
@ -7,8 +7,9 @@
|
|||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"commit": "bunx git-cz",
|
"git:commit": "bunx git-cz",
|
||||||
"push": "bun ./scripts/git-multipush.ts"
|
"git:push": "bun ./scripts/git-multipush.ts",
|
||||||
|
"env:publish": "bun ./scripts/create-env-example.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@heroui/react": "^2.8.2",
|
"@heroui/react": "^2.8.2",
|
||||||
|
|||||||
49
scripts/create-env-example.ts
Normal file
49
scripts/create-env-example.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
// These keys will not be cleared in the .env.example file
|
||||||
|
const PRESERVED_KEYS = ["APP_NAME", "APP_ENV", "APP_PORT"];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script to create or update the .env.example file based on the .env file.
|
||||||
|
* It preserves certain keys and clears their values in the .env.example file.
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
const envPath = path.join(process.cwd(), ".env");
|
||||||
|
const envExamplePath = path.join(process.cwd(), ".env.example");
|
||||||
|
|
||||||
|
if (!fs.existsSync(envPath)) {
|
||||||
|
console.error(`.env file not found at ${envPath}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const envContent = fs.readFileSync(envPath, "utf-8");
|
||||||
|
|
||||||
|
const lines = envContent.split("\n");
|
||||||
|
const processedLines = lines.map((line) => {
|
||||||
|
const trimmedLine = line.trim();
|
||||||
|
|
||||||
|
if (trimmedLine.startsWith("#") || trimmedLine === "") {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
const delimeterIndex = line.indexOf("=");
|
||||||
|
if (delimeterIndex === -1) {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = line.substring(0, delimeterIndex).trim();
|
||||||
|
const value = line.substring(delimeterIndex + 1).trim();
|
||||||
|
|
||||||
|
if (PRESERVED_KEYS.includes(key)) {
|
||||||
|
return `${key}=${value}`;
|
||||||
|
}
|
||||||
|
return `${key}=`;
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.writeFileSync(envExamplePath, processedLines.join("\n"));
|
||||||
|
console.log("File .env.example berhasil diperbarui!");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error while creating .env.example:", error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user