mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-09 20:12:26 +10:00
create .env generation script
This commit is contained in:
@ -11,7 +11,7 @@ POSTGRES_PASSWORD=postgres
|
||||
|
||||
# Server
|
||||
SECRET_KEY=
|
||||
POSTGRES_HOST=postgres
|
||||
POSTGRES_HOST=localhost
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_SSL_CERT=
|
||||
JWT_SECRET=
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
// TypeScript ESLint
|
||||
"@typescript-eslint/no-unused-vars": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/interface-name-prefix": "off",
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off"
|
||||
|
||||
12
.gitpod.yml
12
.gitpod.yml
@ -2,18 +2,12 @@ tasks:
|
||||
- name: Run PostgreSQL Database
|
||||
command: docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d postgres
|
||||
|
||||
- name: Restore Environment Variables
|
||||
- name: Generate Environment Variables
|
||||
command: |
|
||||
if [ -f .env ]; then
|
||||
echo "Found .env in workspace"
|
||||
echo "Found .env in workspace, skipping generation"
|
||||
else
|
||||
if [ -z "${DOTENV}" ]; then
|
||||
echo "Setting example .env"
|
||||
cp .env.gitpod .env
|
||||
else
|
||||
echo "Restoring .env from Gitpod"
|
||||
echo "${DOTENV}" | base64 -d > .env
|
||||
fi
|
||||
pnpm generate-env
|
||||
fi
|
||||
|
||||
- name: Install Project Dependencies
|
||||
|
||||
10
package.json
10
package.json
@ -4,10 +4,11 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "env-cmd --silent cross-var cross-env VERSION=$npm_package_version turbo run dev",
|
||||
"lint": "turbo run lint",
|
||||
"build": "env-cmd --silent cross-var cross-env VERSION=$npm_package_version turbo run build",
|
||||
"start": "env-cmd --silent cross-var cross-env VERSION=$npm_package_version turbo run start",
|
||||
"format": "prettier --write ."
|
||||
"generate-env": "ts-node ./scripts/generate-env.ts",
|
||||
"format": "prettier --write .",
|
||||
"lint": "turbo run lint"
|
||||
},
|
||||
"workspaces": [
|
||||
"schema",
|
||||
@ -18,15 +19,18 @@
|
||||
"cross-env": "^7.0.3",
|
||||
"cross-var": "^1.1.0",
|
||||
"env-cmd": "^10.1.0",
|
||||
"turbo": "^1.6.3"
|
||||
"turbo": "^1.6.3",
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.15",
|
||||
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
||||
"@typescript-eslint/parser": "^5.46.1",
|
||||
"eslint": "^8.29.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-simple-import-sort": "^8.0.0",
|
||||
"prettier": "^2.8.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.9.4"
|
||||
},
|
||||
"resolutions": {
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@ -8,6 +8,7 @@ importers:
|
||||
|
||||
.:
|
||||
specifiers:
|
||||
'@types/node': ^18.11.15
|
||||
'@typescript-eslint/eslint-plugin': ^5.46.1
|
||||
'@typescript-eslint/parser': ^5.46.1
|
||||
cross-env: ^7.0.3
|
||||
@ -17,20 +18,25 @@ importers:
|
||||
eslint-plugin-import: ^2.26.0
|
||||
eslint-plugin-simple-import-sort: ^8.0.0
|
||||
prettier: ^2.8.1
|
||||
ts-node: ^10.9.1
|
||||
turbo: ^1.6.3
|
||||
typescript: ^4.9.4
|
||||
uuid: ^9.0.0
|
||||
dependencies:
|
||||
cross-env: 7.0.3
|
||||
cross-var: 1.1.0
|
||||
env-cmd: 10.1.0
|
||||
turbo: 1.6.3
|
||||
uuid: 9.0.0
|
||||
devDependencies:
|
||||
'@types/node': 18.11.15
|
||||
'@typescript-eslint/eslint-plugin': 5.46.1_imrg37k3svwu377c6q7gkarwmi
|
||||
'@typescript-eslint/parser': 5.46.1_ha6vam6werchizxrnqvarmz2zu
|
||||
eslint: 8.29.0
|
||||
eslint-plugin-import: 2.26.0_z7hwuz3w5sq2sbhy7d4iqrnsvq
|
||||
eslint-plugin-simple-import-sort: 8.0.0_eslint@8.29.0
|
||||
prettier: 2.8.1
|
||||
ts-node: 10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi
|
||||
typescript: 4.9.4
|
||||
|
||||
client:
|
||||
|
||||
@ -1 +1,66 @@
|
||||
console.log('Hello, World!');
|
||||
import { randomBytes } from 'crypto';
|
||||
import fs from 'fs/promises';
|
||||
|
||||
const envMap = {
|
||||
TZ: 'UTC',
|
||||
PUBLIC_URL: '',
|
||||
PUBLIC_SERVER_URL: '',
|
||||
PUBLIC_GOOGLE_CLIENT_ID: '',
|
||||
POSTGRES_DB: 'postgres',
|
||||
POSTGRES_USER: 'postgres',
|
||||
POSTGRES_PASSWORD: 'postgres',
|
||||
SECRET_KEY: '',
|
||||
POSTGRES_HOST: 'localhost',
|
||||
POSTGRES_PORT: '5432',
|
||||
POSTGRES_SSL_CERT: '',
|
||||
JWT_SECRET: '',
|
||||
JWT_EXPIRY_TIME: '604800',
|
||||
GOOGLE_CLIENT_SECRET: '',
|
||||
GOOGLE_API_KEY: '',
|
||||
MAIL_FROM_NAME: '',
|
||||
MAIL_FROM_EMAIL: '',
|
||||
MAIL_HOST: '',
|
||||
MAIL_PORT: '',
|
||||
MAIL_USERNAME: '',
|
||||
MAIL_PASSWORD: '',
|
||||
STORAGE_BUCKET: '',
|
||||
STORAGE_REGION: '',
|
||||
STORAGE_ENDPOINT: '',
|
||||
STORAGE_URL_PREFIX: '',
|
||||
STORAGE_ACCESS_KEY: '',
|
||||
STORAGE_SECRET_KEY: '',
|
||||
PDF_DELETION_TIME: '345600000',
|
||||
PUBLIC_FLAG_DISABLE_SIGNUPS: 'false',
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
// URLs
|
||||
// If running in a Gitpod environment, auto generated the URLs
|
||||
if (process.env.GITPOD_WORKSPACE_URL) {
|
||||
const baseUrl = new URL(process.env.GITPOD_WORKSPACE_URL!);
|
||||
|
||||
envMap['PUBLIC_SERVER_URL'] = `https://3100-${baseUrl}`;
|
||||
envMap['PUBLIC_URL'] = `https://3000-${baseUrl}`;
|
||||
}
|
||||
// Otherwise, fallback to localhost
|
||||
else {
|
||||
envMap['PUBLIC_SERVER_URL'] = 'https://localhost:3100';
|
||||
envMap['PUBLIC_URL'] = 'https://localhost:3000';
|
||||
}
|
||||
|
||||
// Secret Key
|
||||
envMap['SECRET_KEY'] = randomBytes(20).toString('hex');
|
||||
envMap['JWT_SECRET'] = randomBytes(40).toString('hex');
|
||||
|
||||
const envFile = Object.entries(envMap)
|
||||
.reduce((acc, [key, value]) => {
|
||||
acc.push(`${key}=${value}`);
|
||||
|
||||
return acc;
|
||||
}, [] as string[])
|
||||
.join('\n');
|
||||
|
||||
await fs.writeFile('.env', envFile);
|
||||
};
|
||||
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user