/**
 * Increment version number.
 * @function ci.worker.VersionUp
 * @param {object} config - Task configuration
 * @param {string} config.versionFile - Version file name.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */
var path = require('path'),
    debug = require('./_debug'),
    fs = require('fs');

module.exports = function (config, callback) {
    var versionFilePath = path.resolve(config.versionFile),
        data = fs.readFileSync(versionFilePath).toString().trim();
    var versions = data.split('.');
    versions.push(Number(versions.pop()) + 1);
    var newData = versions.join('.');
    fs.writeFile(versionFilePath, newData, function (err) {
        debug('Version incremeted to %s', newData);
        callback(err, newData);
    });
};