/**
 * Expand glob patterns.
 * @function lib.file.expandGlob
 * @param {string|string[]} patterns - Glob patterns.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */
var path = require('path');
module.exports = function (patterns, callback) {
    var async = require('async'),
        glob = require('glob');
    async.parallel(
        [].concat(patterns)
            .map(function (pattern) {
                return pattern && path.resolve(pattern);
            })
            .map(function (pattern) {
                return function (callback) {
                    try {
                        glob(pattern, callback);
                    } catch (e) {
                        callback(e);
                    }
                };
            }),
        function (err, filenames) {
            if (err) {
                callback(err);
            } else {
                var result = filenames
                    .reduce(function (a, b) {
                        return a.concat(b);
                    }, []);
                callback(null, result);
            }

        }
    );

};