/**
 * Publish static files with symbolic link.
 * @function task.worker.publishStaticFiles
 * @param {object} config - Task configuration.
 * @param {string} config.srcDir - Source jade directory.
 * @param {string} config.ignore - Ignore  jade pattern. Glob.
 * @param {string} config.pattern - Source jade file pattern. Glob.
 * @param {string} config.destDir - Destination html directory.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */

var path = require('path'),
    debug = require('./_debug'),
    lib = require('../../lib'),
    compile = lib.compile,
    file = lib.file,
    relativeSymlink = file.relativeSymlink,
    _convertDirectory = require('./_convert_directory');


module.exports = function (config, callback) {
    require('async').series(
        [].concat(config.destDir).map(function (destDir) {
            return function (callback) {
                _convertDirectory({
                    srcDir: config.srcDir,
                    destDir: destDir,
                    pattern: config.pattern || '**/*',
                    ignore: config.ignore,
                    fileNameConverter: function (filename) {
                        return filename;
                    },
                    fileContentConverter: function (src, dest, callback) {
                        relativeSymlink(src, dest, function (err) {
                            if (!err) {
                                debug.didCreateLink(src, dest);
                            }
                            callback(err);
                        });
                    }
                }, function (err) {
                    callback(err);
                });
            }
        }),
        function (err) {
            callback(err);
        }
    );
};
