Skip to content

Commit

Permalink
Merge branch 'MDL-50766_29' of git://github.com/dmonllao/moodle into …
Browse files Browse the repository at this point in the history
…MOODLE_29_STABLE
  • Loading branch information
stronk7 committed Sep 15, 2015
2 parents 49e22cf + 6e29f12 commit 34ed3b4
Showing 1 changed file with 97 additions and 15 deletions.
112 changes: 97 additions & 15 deletions Gruntfile.js
Expand Up @@ -24,6 +24,7 @@

module.exports = function(grunt) {
var path = require('path'),
fs = require('fs'),
tasks = {},
cwd = process.env.PWD || process.cwd();

Expand Down Expand Up @@ -102,22 +103,103 @@ module.exports = function(grunt) {
args.push('--lint-stderr');
}

var execShifter = function() {

shifter = exec("node", args, {
cwd: cwd,
stdio: 'inherit',
env: process.env
});

// Tidy up after exec.
shifter.on('exit', function (code) {
if (code) {
grunt.fail.fatal('Shifter failed with code: ' + code);
} else {
grunt.log.ok('Shifter build complete.');
done();
}
});
};

// Actually run shifter.
shifter = exec("node", args, {
cwd: cwd,
stdio: 'inherit',
env: process.env
});

// Tidy up after exec.
shifter.on('exit', function (code) {
if (code) {
grunt.fail.fatal('Shifter failed with code: ' + code);
} else {
grunt.log.ok('Shifter build complete.');
done();
}
});
if (!options.recursive) {
execShifter();
} else {
// Check that there are yui modules otherwise shifter ends with exit code 1.
var found = false;
var hasYuiModules = function(directory, callback) {
fs.readdir(directory, function(err, files) {
if (err) {
return callback(err, null);
}

// If we already found a match there is no need to continue scanning.
if (found === true) {
return;
}

// We need to track the number of files to know when we return a result.
var pending = files.length;

// We first check files, so if there is a match we don't need further
// async calls and we just return a true.
for (var i = 0; i < files.length; i++) {
if (files[i] === 'yui') {
return callback(null, true);
}
}

// Iterate through subdirs if there were no matches.
files.forEach(function (file) {

var p = path.join(directory, file);
stat = fs.statSync(p);
if (!stat.isDirectory()) {
pending--;
} else {

// We defer the pending-1 until we scan the whole dir and subdirs.
hasYuiModules(p, function(err, result) {
if (err) {
return callback(err);
}

if (result === true) {
// Once we get a true we notify the caller.
found = true;
return callback(null, true);
}

pending--;
if (pending === 0) {
// Notify the caller that the whole dir has been scaned and there are no matches.
return callback(null, false);
}
});
}

// No subdirs here, otherwise the return would be deferred until all subdirs are scanned.
if (pending === 0) {
return callback(null, false);
}
});
});
};

hasYuiModules(cwd, function(err, result) {
if (err) {
grunt.fail.fatal(err.message);
}

if (result === true) {
execShifter();
} else {
grunt.log.ok('No YUI modules to build.');
done();
}
});
}
};

tasks.startup = function() {
Expand Down

0 comments on commit 34ed3b4

Please sign in to comment.