/*!
Load commands from JS files in a directory path.
508416
function _loadCommandsFromDir(dirPath, disabled, callback) {
    var commands = {};
    fs.readdir(dirPath, function(err, fileNames) {
        if (err) {
            return callback(err);
        }

        // Load each JS file as a command into the session
        _.chain(fileNames)

            // Only accept JS files
            .filter(function(fileName) {
                return (fileName.split('.').pop() === 'js');
            })

            // Pluck out the extension of the file name to get the command name
            .map(function(fileName) {
                return fileName.split('.').slice(0, -1).join('.');
            })

            // Don't accept any from the disabled list of command names
            .difference(disabled)

            // Add each command to the session
            .each(function(commandName) {
                commands[commandName] = require(path.join(dirPath, commandName));
            });

        return callback(null, commands);
    });
}
124060
function loadModule(moduleName, moduleFileName, oxModulesDirPath, options) {
    var Module;
    try {
        Module = require(path.join(oxModulesDirPath, moduleFileName));
    } catch (e) {
        if (e instanceof ModuleUnavailableError) {
            logger.warn('Loading module: ' + moduleName + '. Failed to load - ' + e.message);
            return;
        } else {
            throw e;
        }
    }

    var mod = new Module(options, ctx, resultStore, logger);

    // load external commands
    var cmdDir = path.join(oxModulesDirPath, 'module-' + moduleName, 'commands');
    if (fs.existsSync(cmdDir)) {
        var commandName = null;
        try {
            var files = fs.readdirSync(cmdDir);
            for (var fileName of files) {
                commandName = fileName.slice(0, -3);
                if (commandName.indexOf('.') !== 0) {   // ignore possible hidden files (i.e. starting with '.')
                    var cmdFunc = require(path.join(cmdDir, commandName));
                    // bind function's "this" to module's "this"
                    var fnc = cmdFunc.bind(mod._this || mod);
                    mod[commandName] = fnc;
                    // since commands have access only to _this, reference all
                    // commands on it, so commands could have access to each other.
                    // note that command defined in the main module won't be referenced.
                    mod._this[commandName] = fnc;
                }
            }
        } catch (e) {
            logger.error("Can't load command '" + commandName + ': ' + e.message);
            logger.debug(e.stack);
        }
    }

    // apply this for functions inside 'helpers' methods collection if found
    if (mod.helpers || (mod._this && mod._this.helpers)) {
        var helpers = mod.helpers || mod._this.helpers;
        for (var funcName in helpers) {
            if (typeof helpers[funcName] === 'function') {
                helpers[funcName] = helpers[funcName].bind(mod._this || mod);
            }
        }
    }

    logger.debug('Loading module: ' + moduleName);
    modules[moduleName] = sandbox[moduleName] = global.ox[moduleName] = moduleWrapper(moduleName, mod, resultStore);
}
230739
function readDir() {
      var filePaths = project.theme.readDir(path.join('data', pathReq));
      var cacheNames = [];

      for (var filePath of filePaths) {
        var cacheName = path.parse(filePath).name;
        var cachePath = objPath + '.' + cacheName;

        loadFile(filePath, cachePath);

        cacheNames.push(cacheName);
      }

      cache.dirs.set(objPath, cacheNames);
    }
447404
private function cmdJs()
    {
        echo "\n - JS -\n";
        if ($js = $this->config->get('js')) {
            if (!$this->subCmd) {
                foreach ($js as $k => $v) {
                    echo "\n - $k:\n";
                    $this->minify($v->filename, $v->add, $this->yuicompressor, $this->config->baseDir);
                }
                return;
            }

            if (isset($js->{$this->subCmd})) {
                echo "\n - ".$this->subCmd."\n";
                $this->minify($js->{$this->subCmd}->filename,
                  $js->{$this->subCmd}->add,
                  $this->yuicompressor,
                  $this->config->baseDir);
            } else {
                echo "\n Err: Not found!\n";
                return;
            }
        }
    }
413874
def list_js_files(dir):
    
    for dirpath, dirnames, filenames in os.walk(dir):
        for filename in filenames:
            if is_js_file(filename):
                yield os.path.join(dirpath, filename)
640239
function (path, next) {
      var t$ = this

      var files = typeof path === 'string' ? [path] : path

      for (var i = 0; i < files.length; i++) {
        var name = files[i].replace(/^\s|\s$/g, '')
        var att = name.split('.')
        var ext = att[att.length - 1].toLowerCase()
        var isCSS = ext === 'css'
        var tag = isCSS ? 'link' : 'script'
        var attr = isCSS ? ' type=\'text/css\' rel=\'stylesheet\' ' : ' language=\'javascript\' type=\'text/javascript\' '
        var link = (isCSS ? 'href' : 'src') + '=\'' + t$.includePath + name + '\''
        if ($(tag + '[' + link + ']').length === 0) {
          if ($.inArray(path, t$.cache) === -1) {
            t$.cache.push(path)
            var content = '<' + tag + attr + link + '></' + tag + '>'
            isCSS ? $('head').append(content) : $('head').append(content)
          }
        }
      }
      next && next()
    }
917630
function(dirPath, callback) {

            if (!dirPath || typeof dirPath !== 'string') {
                callback("dirPath must be a string");
            } else {
                fs.readdir(dirPath, function(err, list) {
                    var dir = [];

                    if (err) {
                        callback(err, null);
                    } else {
                        list.forEach(function(item) {
                            dir.push(readNode(path.join(dirPath, item)));
                        });

                        callback(null, dir);
                    }

                });
            }

        }
498226
private function cmdJss()
    {
        if ($jss = $this->config->get('jss')) {
            echo "\n - Compiled JS+CSS -\n";

            if (!$this->subCmd) {
                foreach ($jss as $k => $v) {
                    echo "\n - $k:\n";
                    $this->jssCompiler($v);
                }
                return;
            }

            if (isset($jss->{$this->subCmd})) {
                echo "\n - ".$this->subCmd."\n";
                
                $this->jssCompiler($jss->{$this->subCmd});
                return;
            } else {
                echo "\n Err: Not found!\n";
                return;
            }
        }
    }
101741
function(paths) {
    return (
        gulp
        .src(paths.src.path)
        .pipe($.if(config.sourcemaps, $.sourcemaps.init({ loadMaps: true })))
        .pipe($.concat(paths.changeExtension(paths.output.name, '.js')))
        .pipe($.if(config.production, $.uglify()))
        .pipe($.if(config.sourcemaps, $.sourcemaps.write('.')))
        .pipe(gulp.dest(paths.output.baseDir))
    );
}
717201
function recurseSrcDirectories (grunt, fileData, options) {
    let promises = [];

    // Ignore everything except directories and Javascript files.
    // Store function in array for recursive-readdir module.
    let ignoreCallback = [(file, stats) => !(stats.isDirectory() || path.extname(file) === '.js')];

    for (let i = 0, max = fileData.src.length; i < max; i++) {
        promises.push(readDir(fileData.src[i], ignoreCallback).then((value) => value, (err) => err));
    }

    Promise.all(promises)
        .then((values) => {
            streamMatches(grunt, fileData, options, values, values.flat());
        }, throwAsyncError);
}
1187783
function(dir, prefix) {
    if (fs.existsSync(dir)) {
      let dirname = path.relative(this.project.root, dir);
      let globs = this.parentRegistry.extensionsForType('js').map((extension) => `**/*.${extension}`);

      return walkSync(dir, { directories: false, globs }).map(file => {
        let module = prefix + '/' + file.replace(EXT_RE, '.js');
        this.fileLookup[module] = path.join(dirname, file);
        return module;
      });
    } else {
      return [];
    }
  }
592424
function loadTasks(dir) {
    /**
     * Resolve any relative paths
     *
     * @type    {String}
     */
    dir = require('path').resolve(dir);

    /**
     * Interal collection of modules loaded
     *
     * @type    {Object}
     */
    var modules = {};

    /**
     * Get a list of items in a directory. This is synchronous since we're
     * only doing this once on application load
     *
     * @type    {Array}
     */
    var list = require('fs').readdirSync(dir);

    /**
     * Setup the Regex to filter out *.js files but exclude files with
     * multiple `.` in them
     *
     * @type    {RegExp}
     */
    var jsFileTest = /^\w+\.js$/i;

    // Cycle through each item in the directory
    list.forEach(function(module) {
      //Check to see if with have a match and if we split it apartment
      if (jsFileTest.test(module)) {
        // If we find a match try to load and save it. Otherwise log an error
        try {
          modules[module] = require(dir + '/' + module);
        } catch (err) {
          console.error('Unable to load ' + dir + '/' + module, err);
        }
      }
    });

    return modules;
  }
752231
function explode ( filepaths ) {
		var json, res = [];
		filepaths.filter ( existence ).forEach ( function ( filepath ) {
			switch ( path.extname ( filepath )) {
				case ".json" :
					json = grunt.file.readJSON ( filepath );
					res.push.apply ( res, json.map ( function ( localpath ) {
						return path.dirname ( filepath ) + "/" + localpath;
					}));
					break;
				case ".js" :
					res.push ( filepath );
					break;
			}
		});
		return res;
	}
600114
function readDir (dir, regex = /^(?:)$/) {
  return new Promise((resolve, reject) =>
    fs.readdir(dir, (err, files) => err
      ? reject(err)
      : resolve(Promise.all(files.map(checkFileName.bind(null, dir, regex))))))
    .then(values =>
      [].concat(...values)
        .filter(i => i))
}
301987
function (path, dir, cb) {
		var self = this;

		if (!cb) {
			cb = dir;
			dir = null;
		}

		fs.readdir(path, function (err, files) {
			if (err) return cb(err);

			var dirs = [];
			var routes = {};

			files.forEach(function (file) {
				if (file && file.match('.json')) {
					(dir) ? routes[file.replace('.json', '').toLowerCase()] = require(path + '/' + file) : routes[file.replace('.json', '').toLowerCase()] = require(self.routeFilePath(file)) ;
				} else if (file && file.match('.js')) {
					(dir) ? routes[file.replace('.js', '').toLowerCase()] = require(path + '/' + file) : routes[file.replace('.js', '').toLowerCase()] = require(self.routeFilePath(file)) ;
				} else {
					dirs.push(file);
				}
			});

			cb(null, { dirs: dirs, routes: routes, pathDir: path, rootApiPath: dir });
		});
	}
283593
function load(filename, envs) {
    const config = {};
    if (!path.isAbsolute(filename)) {
        filename = path.resolve(process.cwd(), filename);
    }
    if (fs.existsSync(filename)) {
        const stat = fs.lstatSync(filename);
        if (stat.isFile()) {
            if (/.json$/.test(filename)) {
                const content = fs.readFileSync(filename, 'utf8');
                Object.assign(config, fn.resolve(JSON.parse(content), envs));
            }
        } else if (stat.isDirectory()) {
            const files = fs
                .readdirSync(filename)
                .filter(
                    f =>
                        fs.lstatSync(path.resolve(filename, f)).isFile() &&
                        /.json$/.test(f)
                );
            files.forEach(file => {
                const content = fs.readFileSync(
                    path.resolve(filename, file),
                    'utf8'
                );
                const basename = path.basename(file, path.extname(file));
                Object.assign(config, {
                    [basename]: fn.resolve(JSON.parse(content), envs)
                });
            });
        }
    }

    return config;
}
343788
function (pluginsPath) {
    var plugins = fs.readdirSync(pluginsPath);
    var loadedPlugin = [];
    plugins.forEach(function (pluginName) {
        if (pluginName !== 'index.js') {
            loadedPlugin.push(require(path.resolve(pluginsPath, path.basename(pluginName, '.js'))));
        }
    });
    return loadedPlugin;
}