<commit_before>'use strict';

var Stream = require('stream');
var gutil = require('gulp-util');
var minimatch = require('minimatch');

var PLUGIN_NAME = 'gulp-cordova-app-loader-manifest';


var calManifest = function calManifest(options) {
    options = options || {};

    if (!options.load) {
        options.load = ['**'];
    } else if (!(options.load instanceof Array)) {
        options.load = [options.load];
    }

    var manifest = {
        files: {},
        load: [],
        root: options.root || './'
    };

    var stream = new Stream.Transform({objectMode: true});

    stream._transform = function (file, unused, done) {
        if (file.isNull() || !file.stat.isFile()) {
            return done();
        }

        if (file.isStream()) {
            this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streams are not supported!'));
            return done();
        }

        var hasher = require('crypto').createHash('sha256');
        var filename = encodeURI(file.relative);
        var key = filename.replace(/\//g, '_');
        manifest.files[key] = {
            filename: filename,
            version: hasher.update(file.contents).digest('hex')
        };

        options.load.forEach(function (pattern) {
            if (minimatch(filename, pattern)) {
                manifest.load.push(filename);
            }
        });

        done();
    };

    stream._flush = function (done) {
        var file = new gutil.File({
            path: 'manifest.json',
            contents: new Buffer(JSON.stringify(manifest, null, 4))
        });
        stream.push(file);
        return done();
    };


    return stream;
};

module.exports = calManifest;<commit_msg>Properly deal with negated patterns in options.load<commit_after>'use strict';

var Stream = require('stream');
var gutil = require('gulp-util');
var minimatch = require('minimatch');

var PLUGIN_NAME = 'gulp-cordova-app-loader-manifest';


var calManifest = function calManifest(options) {
    options = options || {};

    if (!options.load) {
        options.load = ['**'];
    } else if (!(options.load instanceof Array)) {
        options.load = [options.load];
    }

    var manifest = {
        files: {},
        load: [],
        root: options.root || './'
    };

    var stream = new Stream.Transform({objectMode: true});

    stream._transform = function (file, unused, done) {
        if (file.isNull() || !file.stat.isFile()) {
            return done();
        }

        if (file.isStream()) {
            this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streams are not supported!'));
            return done();
        }

        var hasher = require('crypto').createHash('sha256');
        var filename = encodeURI(file.relative);
        var key = filename.replace(/\//g, '_');
        manifest.files[key] = {
            filename: filename,
            version: hasher.update(file.contents).digest('hex')
        };

        var i, pattern;
        var doLoad = false;
        for (i = 0; i < options.load.length; i++) {
            pattern = options.load[i];
            if (pattern.charAt(0) === '!') {
                if (minimatch(filename, pattern, {flipNegate: true})) {
                    doLoad = false;
                    break;
                }
            } else {
                if (minimatch(filename, pattern)) {
                    doLoad = true;
                }
            }
        }
        if (doLoad) {
            manifest.load.push(filename);
        }

        done();
    };

    stream._flush = function (done) {
        var file = new gutil.File({
            path: 'manifest.json',
            contents: new Buffer(JSON.stringify(manifest, null, 4))
        });
        stream.push(file);
        return done();
    };


    return stream;
};

module.exports = calManifest;
{'fraction_non_alphanumeric': 0.14847616566814276, 'fraction_numerical': 0.0026048450117218025, 'mean_word_length': 1.8850488354620587, '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': '5051270', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1071, 'n_words': 240}