/**
 * Generate config data json.
 * @function ci.worker.generateConfigDataJson
 * @param {object} config - Task configuration
 * @param {string} config.src - Source config file name.
 * @param {string} [config.dest] - Destination file name.
 * @author Taka Okunishi
 */
var path = require('path'),
    generateDataJson = require('./generate_data_json');

exports = module.exports = function (config, callback) {
    var src = path.resolve(config.src),
        dest = path.resolve(config.dest || exports._defaultDest(src)),
        data = require(src);
    generateDataJson({
        data: data,
        dest: dest
    }, callback);
};

exports._defaultDest = function (filename) {
    var dirname = path.dirname(filename),
        extname = path.extname(filename),
        basename = path.basename(filename, extname);
    return path.resolve(
        dirname,
            '.' + basename + '-data.json'
    );
};