/**
 * Minify  files.
 * @function task.worker._minifyFiles
 * @param {object} config - Work configuration.
 * @param {string} config.srcDir - Source css directory.
 * @param {string} config.ignore - Ignore  css pattern. Glob.
 * @param {string} config.pattern - Source css file pattern. Glob.
 * @param {string} config.destDir - Destination html directory.
 * @param {string[]} nameRule - Name convert rule.
 * @param {function} minifier - File minify function.
 * @param {function} callback - Callback when done.
 * @protected
 * @ignore
 * @author Taka Okunishi
 *
 */
var debug = require('./_debug'),
    _convertDirectory = require('./_convert_directory');


exports = module.exports = function (config, nameRule, minifier, callback) {
    _convertDirectory({
        srcDir: config.srcDir,
        destDir: config.destDir,
        pattern: config.pattern,
        ignore: config.ignore,
        fileNameConverter: function (filename) {
            return filename.replace(nameRule[0], nameRule[1]);
        },
        fileContentConverter: function (src, dest, callback) {
            minifier(src, dest, function (err) {
                if (!err) {
                    debug.didCreateFile(dest);
                }
                callback(err);
            });
        }
    }, function (err) {
        callback(err);
    });
};