Skip to content

Commit

Permalink
Support and use .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharaal committed Sep 12, 2021
1 parent 5c7a642 commit c7397c1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:example@localhost:5432/postgres
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:example@localhost:5432/postgres
8 changes: 8 additions & 0 deletions bin/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ try {
debug = console.log
}

try {
debug('try to use the `.env` file via `dotenv-safe`')
require('dotenv-safe').config()
} catch (e) {
debug('package `dotenv-safe` or file `.env` not found')
debug = console.log
}

const fs = require('fs')
const path = require('path')

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
"lint": "standard",
"lint:fix": "standard --fix",
"test": "npm run test:unit && npm run test:integration && npm run test:package",
"test:integration": "export DATABASE_URL=postgres://postgres:example@localhost:5432/postgres && node ./bin/migrate && mocha --require intelli-espower-loader --recursive './test/integration/**/*.js'",
"test:package": "npm pack && tar -xzf *.tgz -C ./ && cp -r test package/test && cd package && mkdir -p migrations && npm i && npm run test:unit && npm run test:integration",
"test:integration": "node ./bin/migrate && mocha --require intelli-espower-loader --recursive './test/integration/**/*.js'",
"test:package": "npm pack && tar -xzf *.tgz -C ./ && cp .env.example package/.env.example && cp .env package/.env && cp -r test package/test && cd package && mkdir -p migrations && npm i && npm run test:unit && npm run test:integration",
"test:unit": "nyc mocha --require intelli-espower-loader --recursive './test/unit/**/*.js'",
"version": "npx readme-releases && git add README.md"
},
"devDependencies": {
"dotenv-safe": "^8.2.0",
"espower-loader": "^1.2.2",
"intelli-espower-loader": "^1.1.0",
"mocha": "^9.1.1",
Expand All @@ -40,6 +41,7 @@
},
"peerDependencies": {
"debug": "^4.3.2",
"dotenv-safe": "^8.2.0",
"pg": "^8.7.1"
},
"directories": {
Expand Down
2 changes: 2 additions & 0 deletions test/integration/sql.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('dotenv-safe').config()

const assert = require('power-assert').strict

function sleep (ms) {
Expand Down

0 comments on commit c7397c1

Please sign in to comment.