<commit_before>/**
 * Created by Ely on 1/15/2015.
 */

/**
 * Created by edelacruz on 11/19/2014.
 */

'use strict';

require('sjljs');

require('es6-promise').polyfill();

// Import base task proxy to extend
var WranglerTaskProxy = require('../WranglerTaskProxy'),
    fs = require('fs'),
    path = require('path'),
    yaml = require('js-yaml'),
    inquirer = require('inquirer'),
    chalk = require('chalk');

module.exports = WranglerTaskProxy.extend(function ConfigProxy (options) {
    WranglerTaskProxy.call(this, options);
}, {

    registerStaticTasks: function (gulp, wrangler) {
        var taskKeys = Object.keys(wrangler.tasks),
            questions = [
                {
                    name: 'configFormat',
                    type: 'list',
                    message: 'In what format would you like your config outputted?',
                    choices: [
                        '.json',
                        '.yaml'
                    ]
                },
                {
                    name: 'tasks',
                    type: 'checkbox',
                    //defaults: taskKeys,
                    message: 'Please deselect the tasks you don\'t plan on initially configuring from you newly generated bundle wrangler config file?',
                    choices: taskKeys
                }
            ];

        gulp.task('config', function () {
            return (new Promise(function (fulfill, reject) {

                console.log(chalk.cyan('Running "config" task.\n\n') +
                chalk.dim('** Note ** - Any existing config will be backed up to "' + wrangler.localConfigBackupPath + '" before generating a new one.'));

                inquirer.prompt(questions, function (answers) {
                    var newConfig = wrangler.loadConfigFile(path.join(__dirname, '/../../../configs/default.wrangler.config.yaml')),
                        newConfigPath = null,
                        oldConfig = wrangler.loadConfigFile(wrangler.configPath),
                        oldFileName = path.basename(wrangler.configPath),
                        oldFileExt = path.extname(oldFileName),
                        backupPath = path.join(process.cwd(), wrangler.localConfigBackupPath),
                        backupFilePath = path.join(backupPath, oldFileName),
                        tmpFileName,
                        tmpPathName,
                        jsonSpace = '     ';

                    // Ensure backup file path exists
                    wrangler.ensurePathExists(backupPath);

                    // If backup file already exists create a timestamped version name
                    if (fs.existsSync(backupFilePath)) {
                        tmpFileName = path.basename(oldFileName, oldFileExt);
                        tmpFileName += '--' + (new Date()).getTime();
                        backupFilePath = path.join(backupPath, tmpFileName + (oldFileExt === '.json' || oldFileExt === '.js' ? '.json' : '.yaml'));
                    }

                    // Get the content to backup based on file type
                    if (oldFileExt === '.json' || oldFileExt === '.js') {
                        oldConfig = JSON.stringify(oldConfig, null, jsonSpace);
                    }
                    else {
                        oldConfig = yaml.safeDump(oldConfig);
                    }

                    // Backup current config file
                    fs.writeFileSync(backupFilePath, oldConfig);

                    // 'Backup complete' message
                    console.log(chalk.dim('\nOld config backed up successfully to "' + backupFilePath + '".\n'));

                    // Remove sections that were not specified to be kept by the user
                    taskKeys.forEach(function (key) {
                        if (answers.tasks.indexOf(key) === -1) {
                            newConfig.tasks[key] = null;
                            delete newConfig.tasks[key];
                        }
                    });

                    // Get new config's contents
                    newConfig = answers.configFormat === '.json' ?
                        JSON.stringify(newConfig, null, jsonSpace) : yaml.safeDump(newConfig);
<commit_msg>Updated 'ConfigProxy' to output a prettierly named backup file.<commit_after>/**
 * Created by Ely on 1/15/2015.
 */

/**
 * Created by edelacruz on 11/19/2014.
 */

'use strict';

require('sjljs');

require('es6-promise').polyfill();

// Import base task proxy to extend
var WranglerTaskProxy = require('../WranglerTaskProxy'),
    fs = require('fs'),
    path = require('path'),
    yaml = require('js-yaml'),
    inquirer = require('inquirer'),
    chalk = require('chalk');

module.exports = WranglerTaskProxy.extend(function ConfigProxy (options) {
    WranglerTaskProxy.call(this, options);
}, {

    registerStaticTasks: function (gulp, wrangler) {
        var taskKeys = Object.keys(wrangler.tasks),
            questions = [
                {
                    name: 'configFormat',
                    type: 'list',
                    message: 'In what format would you like your config outputted?',
                    choices: [
                        '.json',
                        '.yaml'
                    ]
                },
                {
                    name: 'tasks',
                    type: 'checkbox',
                    message: 'Please select the tasks you would like to configure from your newly generated wrangler config file:',
                    choices: taskKeys
                }
            ];

        gulp.task('config', function () {
            return (new Promise(function (fulfill, reject) {

                console.log(chalk.cyan('Running "config" task.\n\n') +
                chalk.dim('** Note ** - Any existing config will be backed up to "' + wrangler.localConfigBackupPath + '" before generating a new one.'));

                inquirer.prompt(questions, function (answers) {
                    var newConfig = wrangler.loadConfigFile(path.join(__dirname, '/../../../configs/default.wrangler.config.yaml')),
                        newConfigPath = null,
                        oldConfig = wrangler.loadConfigFile(wrangler.configPath),
                        oldFileName = path.basename(wrangler.configPath),
                        oldFileExt = path.extname(oldFileName),
                        backupPath = path.join(process.cwd(), wrangler.localConfigBackupPath),
                        backupFilePath = path.join(backupPath, oldFileName),
                        tmpFileName,
                        tmpPathName,
                        jsonSpace = '     ',
                        date,
                        month;

                    // Ensure backup file path exists
                    wrangler.ensurePathExists(backupPath);

                    // If backup file already exists create a timestamped version name
                    if (fs.existsSync(backupFilePath)) {
                        date = new Date();
                        month = date.getMonth() + 1;
                        month = month < 10 ? '0' + month : month;
                        date = [date.getFullYear(), month, date.getDate(), date.getHours(), date.getMinutes(), date.getMilliseconds()].join('-');
                        tmpFileName = path.basename(oldFileName, oldFileExt);
                        tmpFileName += '--' + date;
                        backupFilePath = path.join(backupPath, tmpFileName + (oldFileExt === '.json' || oldFileExt === '.js' ? '.json' : '.yaml'));
                    }

                    // Get the content to backup based on file type
                    if (oldFileExt === '.json' || oldFileExt === '.js') {
                        oldConfig = JSON.stringify(oldConfig, null, jsonSpace);
                    }
                    else {
                        oldConfig = yaml.safeDump(oldConfig);
                    }

                    // Backup current config file
                    fs.writeFileSync(backupFilePath, oldConfig);

                    // 'Backup complete' message
                    console.log(chalk.dim('\nOld config backed up successfully to "' + backupFilePath + '".\n'));

                    // Remove sections that were not specified to be kept by the user
                    taskKeys.forEach(function (key) {
                        if (answers.tasks.indexOf(key) === -1) {
                            newConfig.tasks[key] = null;
                            delete newConfig.tasks[key];
                        }
                    });

                    // Get new config's contents
                    newConfig = answers.configFormat === '.json' ?
                        JSON.stringify(newConfig, null, jsonSpace) : yaml.safeDump(newConfig);

{'fraction_non_alphanumeric': 0.10891763104152484, 'fraction_numerical': 0.004311322895393692, 'mean_word_length': 1.3766513885144245, 'pattern_counts': {'":': 0, '<': 4, '<?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': '6189131', 'n_tokens_mistral': 2219, 'n_tokens_neox': 2047, 'n_words': 514}