Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Simplify env files. #313

Merged
merged 9 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ jobs:
- name: Build production bison app
run: yarn build
env:
DATABASE_URL: not_used_but_needs_to_be_set_to_pass_zod_config_check
DATABASE_URL: postgresql://postgres:postgres@localhost/${{ needs.create-app.outputs.appName }}_test
NODE_ENV: test

- name: Lint bison app
run: yarn lint
Expand Down
10 changes: 2 additions & 8 deletions packages/create-bison-app/tasks/copyFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,9 @@ async function copyFiles({ variables, targetFolder }) {

copyWithTemplate(fromPath("_.env.ejs"), toPath(".env"), variables),

copyWithTemplate(
fromPath("_.env.local.ejs"),
toPath(".env.local"),
variables
),

copyWithTemplate(
fromPath("_.env.development.ejs"),
toPath(".env.local"),
toPath(".env.development"),
variables
),

Expand All @@ -67,7 +61,7 @@ async function copyFiles({ variables, targetFolder }) {

copyWithTemplate(
fromPath("_.env.test.local.ejs"),
toPath(".env.test"),
toPath(".env.test.local"),
variables
),

Expand Down
10 changes: 1 addition & 9 deletions packages/create-bison-app/template/_.env.development.ejs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# Copy with real values to .env.development.local

# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables

# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

# Include NODE_ENV for package script withEnv to work as expected
# Override values in .env.development.local

NEXT_PUBLIC_APP_ENV="development"
NODE_ENV="development"
Expand Down
19 changes: 0 additions & 19 deletions packages/create-bison-app/template/_.env.development.local.ejs
Original file line number Diff line number Diff line change
@@ -1,19 +0,0 @@
# Include your development ENVs here

# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables

# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

# Include NODE_ENV for package script withEnv to work as expected

NEXT_PUBLIC_APP_ENV="development"
NODE_ENV="development"
PORT=3000
SHOULD_MIGRATE=0

DATABASE_URL="postgresql://<%= db.dev.user %><% if (db.dev.password) { %>:<%= db.dev.password %><% } %>@<%= db.dev.host %>:<%= db.dev.port %>/<%= db.dev.name %>?schema=public"

NEXTAUTH_SECRET="bisonDev"
NEXTAUTH_URL="http://localhost:3000"
24 changes: 7 additions & 17 deletions packages/create-bison-app/template/_.env.ejs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# Copy to .env.local to mimic production
NEXT_PUBLIC_APP_ENV=
NODE_ENV=
PORT=

# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables
# Set to 1 to run a database migration when building the app (likely only in
# production)
SHOULD_MIGRATE=

# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

# Include NODE_ENV for package script withEnv to work as expected

NEXT_PUBLIC_APP_ENV="production"
NODE_ENV="development" # production // change if you truly want PROD
PORT=3000
SHOULD_MIGRATE=0

DATABASE_URL="postgresql://<%= db.dev.user %><% if (db.dev.password) { %>:<%= db.dev.password %><% } %>@<%= db.dev.host %>:<%= db.dev.port %>/<%= db.dev.name %>?schema=public"

NEXTAUTH_SECRET="bisonProd"
NEXTAUTH_URL="http://localhost:3000"
DATABASE_URL=
12 changes: 0 additions & 12 deletions packages/create-bison-app/template/_.env.local.ejs

This file was deleted.

3 changes: 1 addition & 2 deletions packages/create-bison-app/template/_.env.test.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copy to .env.test.local to override
# Include NODE_ENV for package script withEnv to work as expected
# Override values in .env.test.local

NEXT_PUBLIC_APP_ENV="test"
NODE_ENV="test"
Expand Down
12 changes: 0 additions & 12 deletions packages/create-bison-app/template/_.env.test.local.ejs
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
# ENV vars here override .env.test when running locally
# Include NODE_ENV for package script withEnv to work as expected

NEXT_PUBLIC_APP_ENV="test"
NODE_ENV="test"
PORT=3001
SHOULD_MIGRATE=0

DATABASE_URL="postgresql://<%= db.dev.user %><% if (db.dev.password) { %>:<%= db.dev.password %><% } %>@<%= db.dev.host %>:<%= db.dev.port %>/<%= db.test.name %>?schema=public"

NEXTAUTH_SECRET="bisonTest"
NEXTAUTH_URL="http://localhost:3001"
5 changes: 1 addition & 4 deletions packages/create-bison-app/template/_.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
.env*.local

.vercel

Expand Down
7 changes: 4 additions & 3 deletions packages/create-bison-app/template/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"build": "yarn ts-node-wrap ./scripts/buildProd",
"build:prisma": "prisma generate",
"build:next": "next build",
"db:migrate": "prisma migrate dev",
"db:migrate": "yarn withEnv:dev prisma migrate dev",
"db:migrate:prod": "prisma migrate deploy",
"db:deploy": "prisma migrate deploy",
"db:reset": "prisma migrate reset",
"db:reset": "yarn withEnv:dev prisma migrate reset",
"db:reset:test": "yarn withEnv:test prisma migrate reset",
"db:seed": "prisma db seed",
"db:seed": "yarn withEnv:dev prisma db seed",
"db:seed:prod": "cross-env NODE_ENV=production prisma db seed",
"db:setup": "yarn db:reset",
"dev": "next dev",
Expand Down Expand Up @@ -44,6 +44,7 @@
"test:e2e": "yarn withEnv:test playwright test --workers 1",
"test:e2e:debug": "PWDEBUG=1 yarn test:e2e",
"ts-node-wrap": "ts-node --project tsconfig.cjs.json -r tsconfig-paths/register",
"withEnv:dev": "dotenv -c development --",
"withEnv:test": "dotenv -c test --",
"watch:ts": "yarn dev:typecheck --watch"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/create-bison-app/test/tasks/copyFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe("copyFiles", () => {
expect(() => fs.statSync(target)).not.toThrowError();
});

it("copies and renames .env.local and env.test", async () => {
const files = [".env.local", ".env.test"];
it("copies and renames .env.development and env.test", async () => {
const files = [".env.development", ".env.test"];

files.forEach((file) => {
const filePath = path.join(targetFolder, file);
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("copyFiles", () => {
});

it("copies env with the correct contents", async () => {
const target = path.join(targetFolder, ".env");
const target = path.join(targetFolder, ".env.development");
const file = await fs.promises.readFile(target);
const fileString = file.toString();
const { user, password, host, port, name } = variables.db.dev;
Expand Down