Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80522 views
1
var through = require('through')
2
, jstransform = require('jstransform')
3
, createVisitors = require('./visitors')
4
5
var processEnvPattern = /\bprocess\.env\b/
6
7
module.exports = function(rootEnv) {
8
rootEnv = rootEnv || process.env || {}
9
10
return function envify(file, argv) {
11
if (/\.json$/.test(file)) return through()
12
13
var buffer = []
14
argv = argv || {}
15
16
return through(write, flush)
17
18
function write(data) {
19
buffer.push(data)
20
}
21
22
function flush() {
23
var source = buffer.join('')
24
25
if (processEnvPattern.test(source)) {
26
try {
27
var visitors = createVisitors([argv, rootEnv])
28
source = jstransform.transform(visitors, source).code
29
} catch(err) {
30
return this.emit('error', err)
31
}
32
}
33
34
this.queue(source)
35
this.queue(null)
36
}
37
}
38
}
39
40