Skip to content

Commit 74501fa

Browse files
committed
feat: add check-env script
1 parent e9c38cb commit 74501fa

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev",
6+
"check-env": "node ./src/scripts/check-env.js",
7+
"dev": "npm run check-env && next dev",
8+
"build": "npm run check-env && next build",
79
"ngrok": "ngrok http --domain=subtly-growing-gorilla.ngrok-free.app 3000",
810
"ngrok-silver": "ngrok http --domain=open-evolving-seal.ngrok-free.app 3000",
9-
"build": "next build",
1011
"start": "next start",
1112
"lint": "next lint",
1213
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,scss,md}\" --list-different",
@@ -39,6 +40,7 @@
3940
"typescript": "5.2.2"
4041
},
4142
"devDependencies": {
43+
"@next/env": "^13.5.2",
4244
"@types/jsonwebtoken": "^9.0.3",
4345
"csstype": "^3.1.2",
4446
"husky": "^8.0.0",

pnpm-lock.yaml

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scripts/check-env.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const nextEnv = require('@next/env');
2+
3+
const { loadEnvConfig } = nextEnv;
4+
5+
loadEnvConfig(process.cwd());
6+
7+
const requiredEnvVariables = [
8+
'DATABASE_URL',
9+
'BOT_API_TOKEN',
10+
// Add more required environment variables here
11+
];
12+
13+
const missingEnvVariables = requiredEnvVariables.filter(
14+
envVar => !process.env[envVar]
15+
);
16+
17+
if (missingEnvVariables.length > 0) {
18+
console.error('Error: Some required environment variables are missing:');
19+
missingEnvVariables.forEach(envVar => {
20+
console.error(`- ${envVar}`);
21+
});
22+
process.exit(1);
23+
} else {
24+
console.log(
25+
'All required environment variables are set. Proceeding with the build.'
26+
);
27+
}

tsconfig.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
"@/*": ["./src/*"]
1818
}
1919
},
20-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "next.config.js"],
20+
"include": [
21+
"next-env.d.ts",
22+
"**/*.ts",
23+
"**/*.tsx",
24+
"next.config.js",
25+
"src/scripts/check-env.js"
26+
],
2127
"exclude": ["node_modules"]
2228
}

0 commit comments

Comments
 (0)