diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4ccd8b39..0b070d1f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/packages/create-bison-app/tasks/copyFiles.js b/packages/create-bison-app/tasks/copyFiles.js index bd627858..663a64ce 100644 --- a/packages/create-bison-app/tasks/copyFiles.js +++ b/packages/create-bison-app/tasks/copyFiles.js @@ -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 ), @@ -67,7 +61,7 @@ async function copyFiles({ variables, targetFolder }) { copyWithTemplate( fromPath("_.env.test.local.ejs"), - toPath(".env.test"), + toPath(".env.test.local"), variables ), diff --git a/packages/create-bison-app/template/_.env.development.ejs b/packages/create-bison-app/template/_.env.development.ejs index f1b25eb0..f9545726 100644 --- a/packages/create-bison-app/template/_.env.development.ejs +++ b/packages/create-bison-app/template/_.env.development.ejs @@ -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" diff --git a/packages/create-bison-app/template/_.env.development.local.ejs b/packages/create-bison-app/template/_.env.development.local.ejs index 303572b3..e69de29b 100644 --- a/packages/create-bison-app/template/_.env.development.local.ejs +++ b/packages/create-bison-app/template/_.env.development.local.ejs @@ -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" diff --git a/packages/create-bison-app/template/_.env.ejs b/packages/create-bison-app/template/_.env.ejs index 61005980..b68e73c8 100644 --- a/packages/create-bison-app/template/_.env.ejs +++ b/packages/create-bison-app/template/_.env.ejs @@ -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= \ No newline at end of file diff --git a/packages/create-bison-app/template/_.env.local.ejs b/packages/create-bison-app/template/_.env.local.ejs deleted file mode 100644 index 66a72ab5..00000000 --- a/packages/create-bison-app/template/_.env.local.ejs +++ /dev/null @@ -1,12 +0,0 @@ -# Overwrite envs here to mimic production -# 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" diff --git a/packages/create-bison-app/template/_.env.test.ejs b/packages/create-bison-app/template/_.env.test.ejs index e360efd1..a378a27e 100644 --- a/packages/create-bison-app/template/_.env.test.ejs +++ b/packages/create-bison-app/template/_.env.test.ejs @@ -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" diff --git a/packages/create-bison-app/template/_.env.test.local.ejs b/packages/create-bison-app/template/_.env.test.local.ejs index 6656d113..e69de29b 100644 --- a/packages/create-bison-app/template/_.env.test.local.ejs +++ b/packages/create-bison-app/template/_.env.test.local.ejs @@ -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" diff --git a/packages/create-bison-app/template/_.gitignore b/packages/create-bison-app/template/_.gitignore index 4a8fe4b3..d468979b 100644 --- a/packages/create-bison-app/template/_.gitignore +++ b/packages/create-bison-app/template/_.gitignore @@ -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 diff --git a/packages/create-bison-app/template/package.json.ejs b/packages/create-bison-app/template/package.json.ejs index 930df243..018816e3 100644 --- a/packages/create-bison-app/template/package.json.ejs +++ b/packages/create-bison-app/template/package.json.ejs @@ -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", @@ -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" }, diff --git a/packages/create-bison-app/test/tasks/copyFiles.test.js b/packages/create-bison-app/test/tasks/copyFiles.test.js index 1a91a8ea..43726150 100644 --- a/packages/create-bison-app/test/tasks/copyFiles.test.js +++ b/packages/create-bison-app/test/tasks/copyFiles.test.js @@ -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); @@ -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;