-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
54 lines (42 loc) · 1.01 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var gif = require("gulp-if");
var argv = require("yargs").argv;
if (argv['gulp-environments-internal-test']) {
// The tests require hard re-loading yargs.
delete require.cache[require.resolve("yargs")];
argv = require("yargs").argv;
}
var currentEnv;
function current(env) {
if(arguments.length > 0) {
currentEnv = env;
} else {
return currentEnv;
}
}
function reset() {
current(make(argv.env || process.env.NODE_ENV || "development"));
}
function make(name) {
if(arguments.length < 1) {
throw "You must provide an name to environments.make()";
}
function envFn(gulpStream) {
var isCurrentEnv = current().$name === name;
if(arguments.length === 0) { return isCurrentEnv; }
return gif(isCurrentEnv, gulpStream);
}
envFn.$name = name;
envFn.task = function(callback) {
current(envFn);
callback();
};
return envFn;
}
reset();
module.exports = {
make: make,
current: current,
reset: reset,
development: make("development"),
production: make("production"),
};