<commit_before>/* global -Promise */

'use strict';

var Git      = require('./git');
var Npm      = require('./npm');
var Promise  = global.Promise || require('es6-promise').Promise;
var readline = require('readline');

var git = new Git();
var npm = new Npm();

var resolve = Promise.resolve.bind(Promise);

var MultiTask = function (grunt, options) {
    this.check = options.check ? function () {
        return git.getBranch().then(function (branch) {
            if (branch !== options.branch) {
                grunt.fail.warn('Not on branch ' + options.branch + '.');
            }

            grunt.log.ok('On branch ' + branch + '.');
        }).then(git.getStatus).then(function (status) {
            if (status) {
                grunt.fail.warn('Unclean working tree.');
            }

            grunt.log.ok('Clean working tree.');
        });
    } : resolve;

    this.publish = options.publish ? function () {
        return npm.publish().then(function () {
            grunt.log.ok('Published to npm.');
        });
    } : resolve;

    this.release = options.release ? function () {
        var pkg     = grunt.file.readJSON('package.json');
        var version = 'v' + pkg.version;
        var message = 'Release ' + version;

        return new Promise(function (resolve, reject) {
            var rl = readline.createInterface({
                input: process.stdin,
                output: process.stdout
            });

            rl.question(message + '? [Y/n]\n', function (answer) {
                rl.close();

                if (!(/^\s*y/i).test(answer)) {
                    git.resetHard().then(function () {
                        grunt.fail.warn('Release aborted.');
                    }).catch(reject);
                } else {
                    resolve();
                }
            });
        }).then(git.addAll).then(function () {
            return git.commit(message);
        }).then(function () {
            return git.tag(version, message);
        }).then(git.pushAll).then(function () {
            grunt.log.ok('Released ' + version + '.');
        });
    } : resolve;

    var createCopyright = function () {
        var currentYear   = new Date().getFullYear();
        var pkg           = grunt.file.readJSON('package.json');
        var inceptionYear = parseInt(pkg.inceptionYear, 10);

        if (isNaN(inceptionYear)) {
            inceptionYear = currentYear;
        }

        var copyright = 'Copyright (c) ' + inceptionYear;

        if (inceptionYear !== currentYear) {
            copyright += ', ' + currentYear;
        }

        copyright += ' ' + pkg.author.name;<commit_msg>Improve usage of git reset<commit_after>/* global -Promise */

'use strict';

var Git      = require('./git');
var Npm      = require('./npm');
var Promise  = global.Promise || require('es6-promise').Promise;
var readline = require('readline');

var git = new Git();
var npm = new Npm();

var resolve = Promise.resolve.bind(Promise);

var MultiTask = function (grunt, options) {
    this.check = options.check ? function () {
        return git.getBranch().then(function (branch) {
            if (branch !== options.branch) {
                grunt.fail.warn('Not on branch ' + options.branch + '.');
            }

            grunt.log.ok('On branch ' + branch + '.');
        }).then(git.getStatus).then(function (status) {
            if (status) {
                grunt.fail.warn('Unclean working tree.');
            }

            grunt.log.ok('Clean working tree.');
        });
    } : resolve;

    this.publish = options.publish ? function () {
        return npm.publish().then(function () {
            grunt.log.ok('Published to npm.');
        });
    } : resolve;

    this.release = options.release ? function () {
        var pkg     = grunt.file.readJSON('package.json');
        var version = 'v' + pkg.version;
        var message = 'Release ' + version;

        return new Promise(function (resolve, reject) {
            var rl = readline.createInterface({
                input: process.stdin,
                output: process.stdout
            });

            rl.question(message + '? [Y/n]\n', function (answer) {
                rl.close();

                if (!(/^\s*y/i).test(answer)) {
                    var message = 'Release aborted.';

                    if (options.check) {
                        git.resetHard().then(function () {
                            grunt.fail.warn(message);
                        }).catch(reject);
                    } else {
                        grunt.fail.warn(message);
                    }
                } else {
                    resolve();
                }
            });
        }).then(git.addAll).then(function () {
            return git.commit(message);
        }).then(function () {
            return git.tag(version, message);
        }).then(git.pushAll).then(function () {
            grunt.log.ok('Released ' + version + '.');
        });
    } : resolve;

    var createCopyright = function () {
        var currentYear   = new Date().getFullYear();
        var pkg           = grunt.file.readJSON('package.json');
        var inceptionYear = parseInt(pkg.inceptionYear, 10);

        if (isNaN(inceptionYear)) {
            inceptionYear = currentYear;
        }

        var copyright = 'Copyright (c) ' + inceptionYear;

        if (inceptionYear !== currentYear) {
            copyright += ', ' + currentYear;
        }

        copyright += ' ' + pkg.author.name;
{'fraction_non_alphanumeric': 0.1483625836801158, 'fraction_numerical': 0.001085579880586213, 'mean_word_length': 1.626128266033254, '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': '2228631', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1477, 'n_words': 310}