crystalschang / gulp-env Goto Github PK
View Code? Open in Web Editor NEWAdd env vars to your process.env
License: MIT License
Add env vars to your process.env
License: MIT License
Why is this called gulp-env
? It has nothing to do with gulp!
I have a .env file which uses comments:
.env
# Here is a comment
DB_HOST=localhost
DB_USER=root
This leads to a crash when using gulp-env
because it cannot parse comments:
[23:29:04] Using gulpfile D:\dev\projects\bennyn\mondlandung\gulpfile.js
[23:29:04] Starting 'set-env'...
[23:29:04] 'set-env' errored after 7.08 ms
[23:29:04] D:\dev\projects\bennyn\mondlandung\.env:1
(function (exports, require, module, __filename, __dirname) { # Here is a comment
^
SyntaxError: Invalid or unexpected token
at new Script (vm.js:73:7)
at createScript (vm.js:245:10)
at Object.runInThisContext (vm.js:297:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
gulpfile.js
const env = require('gulp-env');
const gulp = require('gulp');
gulp.task('default', ['set-env'], () => {
console.log('Hello World', process.env.NODE_DEBUG);
});
gulp.task('set-env', function () {
env({
file: '.env',
vars: {
FORCE_COLOR: 1,
NODE_DEBUG: 'moon:*',
NTBA_FIX_319: 1,
}
});
});
.env.json:
{ "production": true}
Gulpfile:
gulpEnv({
file: ".env.json"
});
gulpUtil.log(typeof process.env.production); // string
plugins.env({
file: '.env.json',
type: string,
vars: {}
});
[11:49:18] Starting 'set-env'...
error with set-env: ReferenceError: string is not defined
I have this test task:
gulp.task('test', () => {
const testEnv = gulpEnv.set({NODE_ENV: 'test'});
return gulp.src(paths.js.test)
.pipe(testEnv)
.pipe(ava({nyc: true}))
.pipe(testEnv.reset);
});
If I run gulp test
the process return value ($?
) is zero, regardless of the outcome of my tests.
This is bad and makes this module unusable for CI purposes.
Currently, npm has this at 0.2.0, and that version doesn't behave as expected based on the current README here. Please publish 0.4.0 to npm, so it matches current master.
Example:
{
"foo": {
"bar": 5
}
}
$FOO becomes [object Object]
➜ benchmark-client git:(51_split_sites) ✗ gulp load-envs
[19:22:17] Using gulpfile ~/Projects/benchmark-client/gulpfile.js
[19:22:17] Starting 'load-envs'...
/Users/kenneth/Projects/benchmark-client/.env:1
ts, require, module, __filename, __dirname) { BENCHMARK_API_URL=http://localho
^
[19:22:17] 'load-envs' errored after 969 μs
[19:22:17] SyntaxError: Unexpected token :
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at module.exports (/Users/kenneth/Projects/benchmark-client/node_modules/gulp-env/index.js:5:15)
at Gulp.gulp.task.gulp.src.pipe.plugins.angularTemplatecache.root (/Users/kenneth/Projects/benchmark-client/gulpfile.js:28:5)
at module.exports (/Users/kenneth/Projects/benchmark-client/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/kenneth/Projects/benchmark-client/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
My .env
file is setup like:
➜ benchmark-client git:(51_split_sites) ✗ cat .env
BENCHMARK_API_URL=http://localhost:8000
Thoughts on supporting this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.