-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (24 loc) · 970 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var replaceTask = require('gulp-replace-task'),
chalk = require('chalk');
function injectEnvironmentVariables(environmentVariables) {
var pattern = '<%=EnvironmentVariable:(.*?)%>';
var regex = new RegExp(pattern, 'g');
return replaceTask({
patterns: [
{
match: regex,
replacement: function (fullMatch, envVariable) {
var envVariableValue = environmentVariables[envVariable];
if (typeof envVariableValue === 'undefined' || envVariableValue === null) {
var errormsg = 'No environment variable specified for ' + envVariable;
console.log(chalk.bold.red(errormsg));
throw new Error(errormsg);
} else {
return envVariableValue;
}
}
}
]
})
};
module.exports = injectEnvironmentVariables;