New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-env

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-env - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

9

index.js

@@ -8,5 +8,12 @@ 'use strict';

for (var prop in env) {
process.env[prop] = env[prop]
process.env[prop] = env[prop];
}
}
if (options.vars) {
var vars = options.vars
for (var prop in vars) {
process.env[prop] = vars[prop];
}
}
}

2

package.json
{
"name": "gulp-env",
"version": "0.1.0",
"version": "0.2.0",
"description": "Add env vars from a .env file to your process.env",

@@ -5,0 +5,0 @@ "main": "index.js",

gulp-env
========
Add env vars from a .env or .env.json file to your process.env
Add env vars to your process.env

@@ -17,22 +17,5 @@

gulp-env handles two kinds of .env files:
##Quick Example
```
//.env.json
{
MONGO_URI: "mongodb://localhost:27017/testdb
}
```
```
//.env
module.exports = {
MONGO_URI: "mongodb://localhost:27017/testdb
}
```
You can add the properties of this object to your process.env via
`env({file: ".env"})` or `env({file: ".env.json"})` in your gulpfile.
```
//gulpfile.js

@@ -48,3 +31,8 @@ gulp = require('gulp'),

gulp.task('set-env', function () {
env({file: ".env.json"});
env({
file: ".env.json",
vars: {
//any vars you want to overwrite
}
});
});

@@ -55,26 +43,51 @@

TODO
========
##The Details
For now, this plug-in is stupid simple.
gulp-env handles two options: `file` and `vars`.
Seriously, this is all of the code!
###options.file
The `file` option uses `require()` under the hood to pull in data and assign it to
the `process.env`. `gulp-env` has test coverage for two options: JSON, and a JS
object exported as a module.
```
'use strict';
//.env.json
{
MONGO_URI: "mongodb://localhost:27017/testdb
}
module.exports = function(options) {
if (options.file) {
var env = require(process.cwd() + "/" + options.file);
//.env
module.exports = {
MONGO_URI: "mongodb://localhost:27017/testdb
}
for (var prop in env) {
process.env[prop] = env[prop]
}
}
}
//gulpfile.js
var env = require('gulp-env')
env({
file: ".env"
//OR
file: ".env.json"
})
```
TODO:
###options.vars
Properties passed to the vars option will be set on process.env as well.
These properties will overwrite the external file's properties.
```
//gulpfile.js
var env = require('gulp-env')
env({
vars: {
MONGO_URI: "mongodb://localhost:27017/testdb-for-british-eyes-only",
PORT: 9001
}
})
```
TODO
========
- handle ini files
- allow for simple variable setting (i.e. `env({PORT: 4000})`, etc.)

@@ -9,32 +9,81 @@ var env = require('../'),

beforeEach(function() {
delete process.env.STARK;
delete process.env.BARATHEON;
delete process.env.LANNISTER;
describe('reads properties from files', function() {
afterEach(function() {
delete process.env.STARK;
delete process.env.BARATHEON;
delete process.env.LANNISTER;
});
it('should add process.env vars from a local module', function() {
expect(process.env.STARK).not.to.exist
expect(process.env.BARATHEON).not.to.exist
expect(process.env.LANNISTER).not.to.exist
env({file: "test/mock-env-module"})
expect(process.env.STARK).to.equal("direwolf");
expect(process.env.BARATHEON).to.equal("stag");
expect(process.env.LANNISTER).to.equal("lion");
});
it('should add process.env vars from a local json file', function() {
expect(process.env.STARK).not.to.exist
expect(process.env.BARATHEON).not.to.exist
expect(process.env.LANNISTER).not.to.exist
env({file: "test/mock-env-json.json"})
expect(process.env.STARK).to.equal("direwolf");
expect(process.env.BARATHEON).to.equal("stag");
expect(process.env.LANNISTER).to.equal("lion");
});
});
it('should add process.env vars from a local module', function() {
expect(process.env.STARK).not.to.equal("direwolf");
expect(process.env.BARATHEON).not.to.equal("stag");
expect(process.env.LANNISTER).not.to.equal("lion");
describe('reads vars from vars object', function(){
afterEach(function() {
delete process.env.NED;
delete process.env.ROBERT;
delete process.env.TYWIN;
});
env({file: "test/mock-env-module"})
it('should add process.env vars from vars object', function() {
expect(process.env.NED).not.to.exist
expect(process.env.ROBERT).not.to.exist
expect(process.env.TYWIN).not.to.exist
expect(process.env.STARK).to.equal("direwolf");
expect(process.env.BARATHEON).to.equal("stag");
expect(process.env.LANNISTER).to.equal("lion");
env({vars: {
NED: true,
ROBERT: 'fat',
TYWIN: 9001
}})
expect(process.env.NED).to.equal('true');
expect(process.env.ROBERT).to.equal('fat');
expect(process.env.TYWIN).to.equal('9001');
});
});
it('should add process.env vars from a local json file', function() {
expect(process.env.STARK).not.to.equal("direwolf");
expect(process.env.BARATHEON).not.to.equal("stag");
expect(process.env.LANNISTER).not.to.equal("lion");
describe('reads properties from files and vars object', function() {
afterEach(function() {
delete process.env.STARK;
delete process.env.BARATHEON;
delete process.env.LANNISTER;
});
env({file: "test/mock-env-json.json"})
it('should overwrite files with inline-vars by default', function() {
expect(process.env.STARK).not.to.exist
expect(process.env.STARK).to.equal("direwolf");
expect(process.env.BARATHEON).to.equal("stag");
expect(process.env.LANNISTER).to.equal("lion");
env({
file: "test/mock-env-json.json",
vars: {
STARK: "wolfenstein"
}
});
expect(process.env.STARK).to.equal('wolfenstein')
expect(process.env.BARATHEON).to.equal('stag')
expect(process.env.LANNISTER).to.equal('lion')
});
});
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc