GiveToken / GiftBox

Repository for Sizzle
0 stars 0 forks source link

New Gulp recursively require feature #1098

Closed shreydesai closed 8 years ago

shreydesai commented 8 years ago

Added a recursive require feature for Gulp that synchronously scans the js/gulp/tasks directory (with the Node.js fs module) and includes *.js files in the build path. This eliminates the need to manually input a new Gulp file in the path when the directory is updated.

function walk(target) {
  fs.readdirSync(target).forEach(function(file) {
    let trail = target + '/' + file;
    let stats = fs.statSync(trail);
    if (stats.isDirectory()) walk(trail);
    if (stats.isFile() && trail.includes('.js')) {
      var split = function(string) {
        if (string.includes(__dirname)) {
          string = string.replace(__dirname, '.');
          string = string.replace('.js', '');
          require(string);
        }
      }(trail);
    }
  });
}
wogsland commented 8 years ago

I see what you're doing here . . . ES6 it is!