/**
 * Generate a data json file.
 * @function ci.worker.generateDataJson
 * @param {object} config - Task configuration
 * @param {string} config.dest - Destination file name.
 * @param {object} config.data - Json data.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */

var lib = require('../../lib'),
    path = require('path'),
    debug = require('./_debug'),
    file = lib.file,
    writeReadonlyFile = file.writeReadonlyFile;


exports = module.exports = function (config, callback) {
    var dest = path.resolve(config.dest),
        data = config.data;
    var content = JSON.stringify(data, null, 4);
    writeReadonlyFile(dest, content, function (err) {
        if (!err) {
            debug.didCreateFile(dest);
        }
        callback(err);
    });
};
