Skip to content

Commit

Permalink
Add conditional section processing
Browse files Browse the repository at this point in the history
  • Loading branch information
aredridel committed Jul 5, 2013
1 parent 44f5557 commit a3f1c16
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Expand Up @@ -3,6 +3,7 @@ var path = require('path');
var fs = require('fs');
var expansions = require('gyp-expansions');
var load = require('gyp-load');
var cond = require('gyp-conditions');

var gyp = module.exports = function gyp(arg, variables, cb) {
if (typeof arg == 'string' || arg instanceof String) {
Expand Down Expand Up @@ -96,7 +97,13 @@ function handle(thing, variables, which, cb) {
}

if (thing.conditions) {
/// @todo do conditional processing
thing.conditions.forEach(function (e) {
if (cond(e[0], variables)) {
thing = merge(e[1], thing);
} else if (e[2]) {
thing = merge(e[2], thing);
}
});
}

oiter(thing, function(e, cont, key) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"gyp-merge": "0.2.x",
"gyp-expansions": "0.0.x",
"gyp-conditions": "0.0.4",
"gyp-load": "0.0.x"
},
"devDependencies": {
Expand Down
16 changes: 16 additions & 0 deletions test/conditions.js
@@ -0,0 +1,16 @@
var test = require('tap').test;
var gyp = require('..');

test("Conditional sections", function(t) {
var tests = 2;
gyp({ a: 1, conditions: [["merge==1", { b: 2}]] }, {merge: 1}, function(err, out) {
t.equal(out.a, "1", "a should be 1");
t.equal(out.b, "2", "b should be 2");
if (--tests == 0) t.end();
});
gyp({ a: 1, conditions: [["merge==2", { b: 2}]] }, {merge: 1}, function(err, out) {
t.equal(out.a, "1", "a should be 1");
t.not(out.b, "2", "b should not be 2");
if (--tests == 0) t.end();
});
});

0 comments on commit a3f1c16

Please sign in to comment.