diff --git a/.travis.yml b/.travis.yml index 3ebfa5fc..263ce3dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,8 @@ node_js: - 6 - 8 - 9 + +script: + - npm run lint + - npm run test + - npm run coverage diff --git a/appveyor.yml b/appveyor.yml index aa0cee3e..ae0252f1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,14 @@ -version: 4.0.{build} -build: - verbosity: minimal +version: "{build}" +build: off +environment: + matrix: + - nodejs_version: "4" + - nodejs_version: "6" + - nodejs_version: "8" + - nodejs_version: "9" +install: + - ps: Install-Product node $env:nodejs_version + - npm install +test_script: + - npm run lint + - npm run test diff --git a/lib/main.js b/lib/main.js index 1f0df927..cc6fb924 100644 --- a/lib/main.js +++ b/lib/main.js @@ -3,12 +3,14 @@ const fs = require('fs') const path = require('path') +const dotenv = module.exports = {} + /* * Parses a string or buffer into an object * @param {(string|Buffer)} src - source to be parsed * @returns {Object} keys and values from src */ -function parse (src) { +dotenv.parse = function parse (src) { const obj = {} // convert Buffers before splitting into lines and processing @@ -45,7 +47,7 @@ function parse (src) { * @param {string} [options.encoding=utf8] - encoding of .env file * @returns {Object} parsed object or error */ -function config (options) { +dotenv.config = dotenv.load = function config (options) { let dotenvPath = path.resolve(process.cwd(), '.env') let encoding = 'utf8' @@ -60,7 +62,7 @@ function config (options) { try { // specifying an encoding returns a string instead of a buffer - const parsed = parse(fs.readFileSync(dotenvPath, { encoding })) + const parsed = dotenv.parse(fs.readFileSync(dotenvPath, { encoding })) Object.keys(parsed).forEach(function (key) { if (!process.env.hasOwnProperty(key)) { @@ -73,7 +75,3 @@ function config (options) { return { error: e } } } - -module.exports.config = config -module.exports.load = config -module.exports.parse = parse diff --git a/package.json b/package.json index 104d4154..322e819c 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,11 @@ "description": "Loads environment variables from .env file", "main": "lib/main.js", "scripts": { - "pretest": "npm run lint", - "test": "lab test/* -r lcov | coveralls", + "test": "lab", "lint": "standard", "postlint": "npm run lint-md", - "lint-md": "standard-markdown" + "lint-md": "standard-markdown", + "coverage": "lab -r lcov | coveralls" }, "repository": { "type": "git", diff --git a/test/config.js b/test/config.js index ab5b6fc2..a57feff1 100644 --- a/test/config.js +++ b/test/config.js @@ -12,7 +12,7 @@ describe('config', function () { describe('preload', function () { it('loads .env', function (done) { cp.exec( - nodeBinary + ' -r ../config -e "console.log(process.env.BASIC)" dotenv_config_path=./test/.env', + '"' + nodeBinary + '" -r ../config -e "console.log(process.env.BASIC)" dotenv_config_path=./test/.env', function (err, stdout, stderr) { if (err) { return done(err)