mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
39 lines
844 B
JavaScript
39 lines
844 B
JavaScript
var through = require('through')
|
|
, jstransform = require('jstransform')
|
|
, createVisitors = require('./visitors')
|
|
|
|
var processEnvPattern = /\bprocess\.env\b/
|
|
|
|
module.exports = function(rootEnv) {
|
|
rootEnv = rootEnv || process.env || {}
|
|
|
|
return function envify(file, argv) {
|
|
if (/\.json$/.test(file)) return through()
|
|
|
|
var buffer = []
|
|
argv = argv || {}
|
|
|
|
return through(write, flush)
|
|
|
|
function write(data) {
|
|
buffer.push(data)
|
|
}
|
|
|
|
function flush() {
|
|
var source = buffer.join('')
|
|
|
|
if (processEnvPattern.test(source)) {
|
|
try {
|
|
var visitors = createVisitors([argv, rootEnv])
|
|
source = jstransform.transform(visitors, source).code
|
|
} catch(err) {
|
|
return this.emit('error', err)
|
|
}
|
|
}
|
|
|
|
this.queue(source)
|
|
this.queue(null)
|
|
}
|
|
}
|
|
}
|