<commit_before>var packageJson = require('./package.json');
var path = require('path');
var fs = require('fs');
var through = require('through2');
var gutil = require('gulp-util');
var _ = require('lodash');
var PluginError = gutil.PluginError;

const IDENT = packageJson.name;
const MANIFEST_RE = /manifest\s?:\s?(\[[\s\w\d\/-{}"'.,]*?\])/m;
const MANIFEST_PREFIX = 'manifest: ';
const MIME_TYPES = {
    png  : 'image/png',
    gif  : 'image/gif',
    jpg  : 'image/jpeg',
    jpeg : 'image/jpeg'
};
const OUTPUT_TYPE = {
    EMBED: 'embed',
    JSON:  'json'
};
const DEFAULT_PARAMS = {
    basepath: '',
    outputType: OUTPUT_TYPE.EMBED,
    jsonFileSuffix: '_manifest',
    ignores: null,
    mimeTypeToManifestTypeMap: {
        image  : 'image',
        audio  : 'sound',
        binary : 'binary'
    },
};

function gulpFlashCcCanvasEmbedDataUrl(option) {
    var settings = _.extend({}, DEFAULT_PARAMS, option || {});

    return through.obj(transform);

    function transform(file, encoding, callback) {
        if (file.isNull()) {
            this.push(file);
            callback();
            return;
        } else if (file.isStream()) {
            this.emit('error', new PluginError(IDENT, 'Streaming not supported'));
            return;
        }
        var contents = file.contents.toString('utf8');
        var matched = MANIFEST_RE.exec(contents);

        if (!matched || matched.length < 2) {
            this.emit('error', new PluginError(IDENT, 'Manifests not found'));
        }
        var manifests = eval(matched[1]);
        var res = [];

        manifests.forEach(function(m) {
            if (_checkIgnoreId(m.id)) {
                return;
            }
            var targetFilePath = path.join(settings.basepath || path.dirname(file.path), m.src);

            if (!fs.existsSync(targetFilePath)) {
                this.emit('error', new PluginError(IDENT, 'Target file not found'));
            }
            var mimeType = _getMimeTypeByFilePath(targetFilePath);
            var targetFile = fs.readFileSync(targetFilePath);

            m.src = _generateDataUrl(targetFile, mimeType);
            m.type =  _getManifestTypeByMimeType(mimeType);
<commit_msg>not throw error if target files not include manifest<commit_after>var packageJson = require('./package.json');
var path = require('path');
var fs = require('fs');
var through = require('through2');
var gutil = require('gulp-util');
var _ = require('lodash');
var PluginError = gutil.PluginError;

const IDENT = packageJson.name;
const MANIFEST_RE = /manifest\s?:\s?(\[[\s\w\d\/-{}"'.,]*?\])/m;
const MANIFEST_PREFIX = 'manifest: ';
const MIME_TYPES = {
    png  : 'image/png',
    gif  : 'image/gif',
    jpg  : 'image/jpeg',
    jpeg : 'image/jpeg'
};
const OUTPUT_TYPE = {
    EMBED: 'embed',
    JSON:  'json'
};
const DEFAULT_PARAMS = {
    basepath: '',
    outputType: OUTPUT_TYPE.EMBED,
    jsonFileSuffix: '_manifest',
    ignores: null,
    mimeTypeToManifestTypeMap: {
        image  : 'image',
        audio  : 'sound',
        binary : 'binary'
    },
};

function gulpFlashCcCanvasEmbedDataUrl(option) {
    var settings = _.extend({}, DEFAULT_PARAMS, option || {});

    return through.obj(transform);

    function transform(file, encoding, callback) {
        if (file.isNull()) {
            this.push(file);
            callback();
            return;
        } else if (file.isStream()) {
            this.emit('error', new PluginError(IDENT, 'Streaming not supported'));
            return;
        }
        var contents = file.contents.toString('utf8');
        var matched = MANIFEST_RE.exec(contents);

        if (!matched || matched.length < 2) {
            gutil.log('Undefined manifest in file: ' + file.base);
            this.push(file);
            callback();
            return;
        }
        var manifests = eval(matched[1]);
        var res = [];

        manifests.forEach(function(m) {
            if (_checkIgnoreId(m.id)) {
                return;
            }
            var targetFilePath = path.join(settings.basepath || path.dirname(file.path), m.src);

            if (!fs.existsSync(targetFilePath)) {
                this.emit('error', new PluginError(IDENT, 'Target file not found'));
            }
            var mimeType = _getMimeTypeByFilePath(targetFilePath);
            var targetFile = fs.readFileSync(targetFilePath);

            m.src = _generateDataUrl(targetFile, mimeType);
            m.type =  _getManifestTypeByMimeType(mimeType);

{'fraction_non_alphanumeric': 0.14403018197958278, 'fraction_numerical': 0.001775410563692854, 'mean_word_length': 2.4015094339622642, 'pattern_counts': {'":': 0, '<': 5, '<?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': '689432', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1354, 'n_words': 288}