<commit_before>#!/usr/bin/env node

const fs = require('fs');
const { normalize, join } = require('path');
const babel = require('babel-core');
const envify = require('envify/custom');
const UglifyJS = require('uglify-js');
const browserify = require('browserify');
const babelify = require('babelify');

function debug() {
    if (process.env.DEBUG) console.error(...arguments);
}

const root = normalize(join(__dirname, '..'));
function fromRoot(subPath) {
    return normalize(join(root, subPath));
}

const licence =
    '/*\n' +
    'Jimp v' +
    process.env.npm_package_version +
    '\n' +
    'https://github.com/oliver-moran/jimp\n' +
    'Ported for the Web by <NAME>\n' +
    fs.readFileSync(fromRoot('LICENSE')) +
    '*/';

// Browserify and Babelize.
function bundle(files, config, callback) {
    if (typeof files === 'string') files = [files];
    files = files.map(f => {
        return f[0] === '/' ? f : fromRoot(f); // ensure path.
    });
    console.error('Browserify ' + files.join(', ') + '...');
    config = Object.assign(
        {
            ignoreMissing: true,
            fullPaths: false,
            debug: true,
            paths: [root],
            basedir: root
        },
        config
    );
    debug('browserify config:', config);
    const bundler = browserify(files, config).exclude(
        fromRoot('browser/lib/jimp.js')
    );
    config.exclude = config.exclude || [];
    for (let f, i = 0; (f = config.exclude[i]); i++) {
        bundler.exclude(fromRoot(f));
    }

    bundler
        .transform(
            babelify.configure({ presets: ['env', 'es2015', 'stage-0'] })
        )
        .transform(envify({ ENVIRONMENT: 'BROWSER' }))
        .bundle((err, baseCode) => {
            if (err) return callback(err);
            console.error(
                'Babelize ' +
                    files.map(f => f.replace(/.*\//, '')).join('+') +
                    '...'
            );
            const result = babel.transform(
                "if ((typeof(window)=='undefined' || !window) " +
                    "&& (typeof(self)!='undefined')) var window = self;\n" +
                    baseCode.toString()
            );
            callback(null, result.code);
        });
}

function bundleSimple(files, config, callback) {
    bundle(files, config, (err, code) => {<commit_msg>only babel once<commit_after>#!/usr/bin/env node

const fs = require('fs');
const { normalize, join } = require('path');
const envify = require('envify/custom');
const UglifyJS = require('uglify-js');
const browserify = require('browserify');
const babelify = require('babelify');

function debug() {
    if (process.env.DEBUG) console.error(...arguments);
}

const root = normalize(join(__dirname, '..'));
function fromRoot(subPath) {
    return normalize(join(root, subPath));
}

const licence =
    '/*\n' +
    'Jimp v' +
    process.env.npm_package_version +
    '\n' +
    'https://github.com/oliver-moran/jimp\n' +
    'Ported for the Web by <NAME>\n' +
    fs.readFileSync(fromRoot('LICENSE')) +
    '*/';

// Browserify and Babelize.
function bundle(files, config, callback) {
    if (typeof files === 'string') files = [files];
    files = files.map(f => {
        return f[0] === '/' ? f : fromRoot(f); // ensure path.
    });
    console.error('Browserify ' + files.join(', ') + '...');
    config = Object.assign(
        {
            ignoreMissing: true,
            fullPaths: false,
            debug: true,
            paths: [root],
            basedir: root
        },
        config
    );
    debug('browserify config:', config);
    const bundler = browserify(files, config).exclude(
        fromRoot('browser/lib/jimp.js')
    );
    config.exclude = config.exclude || [];
    for (let f, i = 0; (f = config.exclude[i]); i++) {
        bundler.exclude(fromRoot(f));
    }

    bundler
        .transform(
            babelify.configure({ presets: ['env', 'es2015', 'stage-0'] })
        )
        .transform(envify({ ENVIRONMENT: 'BROWSER' }))
        .bundle((err, baseCode) => {
            if (err) return callback(err);

            callback(
                null,
                "if ((typeof(window)=='undefined' || !window) " +
                    "&& (typeof(self)!='undefined')) var window = self;\n" +
                    baseCode
            );
        });
}

function bundleSimple(files, config, callback) {
    bundle(files, config, (err, code) => {
{'fraction_non_alphanumeric': 0.17577948486217804, 'fraction_numerical': 0.0031631269769543608, 'mean_word_length': 2.196389891696751, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 2, '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': '7113239', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1359, 'n_words': 289}