<commit_before>var fs = require('fs');
var path = require('path');
var async = require('async');
var readline = require('readline');

// The default version number is pulled from `package.json` which we assume is
// in the format `major.minor.build`. If it's not in this format then all we
// can do is choke and die. By default the build number is bumped by 1, but this
// can be overridden by the user.

function getDefaultVersion(repo, callback) {
    fs.readFile(repo + path.sep + 'package.json', function (err, data) {
        if (err) { callback(err); }

        var nextVersion;
        var currentVersion = JSON.parse(data).version;
        var build = currentVersion.replace(/[0-9]+\.[0-9]+\./, '');

        if (isNaN(build)) {
            callback('Invalid version number: %s' + currentVersion);
        }

        build++;
        nextVersion = currentVersion.replace(/[0-9]+$/, build);
        callback(null, nextVersion);
    });
}

// The user then gets a chance to override the derived default version number,
// which is then checked to ensure it's in the correct format.

function getVersion(defaultVersion, callback) {

    var prompt = 'Version number [' + defaultVersion + '] ';

    var rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });

    async.forever(
        function (next) {
            rl.question(prompt, function(answer) {
                if (answer === '') {
                    next(defaultVersion);
                } else if (/[0-9]+\.[0-9]+\.[0-9]+/.test(answer)) {
                    next(answer);
                } else {
                    console.log('Invalid version number: %s', answer);
                    next();
                }
            });
        },
        function (version) {
            rl.close();
            callback(null, version);
        }
    );
}<commit_msg>Update docs for version.js<commit_after>var fs = require('fs');
var path = require('path');
var async = require('async');
var readline = require('readline');

// The default version number is pulled from `package.json` which we assume is
// in the format `major.minor.build`. If it's not in this format then all we
// can do is choke and die. By default the build number is bumped by 1, but this
// can be overridden by the user.

function getDefaultVersion(repo, callback) {
    fs.readFile(repo + path.sep + 'package.json', function (err, data) {
        if (err) { callback(err); }

        var nextVersion;
        var currentVersion = JSON.parse(data).version;
        var build = currentVersion.replace(/[0-9]+\.[0-9]+\./, '');

        if (isNaN(build)) {
            callback('Invalid version number: %s' + currentVersion);
        }

        build++;
        nextVersion = currentVersion.replace(/[0-9]+$/, build);
        callback(null, nextVersion);
    });
}

// The user then gets a chance to override the derived default version number,
// which is then checked to ensure it's in the correct format. There's a slight
// abuse of async.forever here which uses the feature that passing `next` a
// string exits the loop and passes the string to the callback. This is used
// to break out of the loop with the version number.

function getVersion(defaultVersion, callback) {

    var prompt = 'Version number [' + defaultVersion + '] ';

    var rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });

    async.forever(
        function (next) {
            rl.question(prompt, function(answer) {
                if (answer === '') {
                    next(defaultVersion);
                } else if (/[0-9]+\.[0-9]+\.[0-9]+/.test(answer)) {
                    next(answer);
                } else {
                    console.log('Invalid version number: %s', answer);
                    next();
                }
            });
        },
        function (version) {
            rl.close();
            callback(null, version);
        }
    );
}
{'fraction_non_alphanumeric': 0.13157894736842105, 'fraction_numerical': 0.006516290726817042, 'mean_word_length': 2.0747303543913715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5061434', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1067, 'n_words': 354}