Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

create .env generation script

Amruth Pillaif9b6aefffe1a
diff --git a/.env.example b/.env.example
index 47f0c9f15..1692f9f6f 100644
--- a/.env.example
+++ b/.env.example
@@ -11,7 +11,7 @@ POSTGRES_PASSWORD=postgres
# Server
SECRET_KEY=
-POSTGRES_HOST=postgres
+POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_SSL_CERT=
JWT_SECRET=
diff --git a/.eslintrc.json b/.eslintrc.json
index fb1370756..93f268448 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -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"
diff --git a/.gitpod.yml b/.gitpod.yml
index 748c4b59b..5d8b461db 100644
--- a/.gitpod.yml
+++ b/.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
diff --git a/package.json b/package.json
index df99d5365..ab977ac46 100644
--- a/package.json
+++ b/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": {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index dec3f33f4..058077ec2 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -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: [email protected]
prettier: 2.8.1
+ ts-node: 10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi
typescript: 4.9.4
client:
diff --git a/scripts/generate-env.ts b/scripts/generate-env.ts
index eb065f93f..401eb024b 100644
--- a/scripts/generate-env.ts
+++ b/scripts/generate-env.ts
@@ -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();