<commit_before>var grunt = require('grunt');
var fs = require('fs');

var proxy = function(func, context) {
	var _func = func;
	var _context = context;
	return function() {
		_func.apply(_context, Array.prototype.slice.call(arguments));
	};
};

var ImageMagicWrapper = {
	"im": undefined,
	"suffixes": [],
	"init": function(file, suffixes, callback, context) {
		try {
			this.im = require('node-imagemagick');
			this.file = file;
			this.path = file.substr(0, file.lastIndexOf('/') + 1);
			this.extention = file.substr(file.lastIndexOf('.') + 1);
			this.name = file.substr(file.lastIndexOf('/') + 1, file.lastIndexOf('.') - file.lastIndexOf('/') - 1);
			this.suffixes = suffixes;
			this.callback = callback;
			this.context = context;

			this.im.identify(['-format', '%wx%h', this.file], proxy(this.resize, this));
		} catch(e) {
			this.complete(false, e);
		}
	},
	"resize": function(err, output) {
		try {
			this.baseWidth = Number(output.split('x')[0]);
			this.baseHeight = Number(output.split('x')[1]);
			var resultName = this.path + this.name.split(this.suffixes[0]).join(this.suffixes[1]) + '.' + this.extention;

			if (fs.existsSync(resultName)) {
				this.complete(this, true);
			} else {
				this.im.resize({
					"width": Math.round(this.baseWidth/2),
					"height": Math.round(this.baseHeight/2),
					"srcPath": this.file,
					"dstPath": resultName
				}, proxy(this.complete, this));
				grunt.log.write('file [', resultName, '] is created.\n');

			}
		} catch (e) {
			this.complete(false, e);
		}
	},
	"complete": function(success, error) {
		this.callback.apply(this.context,[this, success, error]);
	}
};

module.exports = function(grunt) {
	grunt.registerMultiTask('retinaImg', 'generates images set due to configuration', function() {
		var done = this.async();
		grunt.log.warn("\nPlease make sure that you installed imageMagic CLI before start.\n");
		var files = grunt.file.expand(this.data.files);
		var suffixes = this.data.suffixes || ["@2x", "@1x"];

		var cmds=[];
		var cmd;

		function onComplete(cmd, success, err) {
			if (!success) {
				grunt.log.write("Error in: ", cmd.file, " processing: [ ", (err && err.code ? err.code : "UnknownError"), " ]\n");
			}
			cmds.splice(cmds.indexOf(cmd), 1);
			if (!cmds.length) {
				done();
			}
		}

		for (var i = 0; i < files.length; i++) {
			cmd = Object.create(ImageMagicWrapper);<commit_msg>identify format is changed<commit_after>var grunt = require('grunt');
var fs = require('fs');

var proxy = function(func, context) {
	var _func = func;
	var _context = context;
	return function() {
		_func.apply(_context, Array.prototype.slice.call(arguments));
	};
};

var ImageMagicWrapper = {
	"im": undefined,
	"suffixes": [],
	"init": function(file, suffixes, callback, context) {
		try {
			this.im = require('node-imagemagick');
			this.file = file;
			this.path = file.substr(0, file.lastIndexOf('/') + 1);
			this.extention = file.substr(file.lastIndexOf('.') + 1);
			this.name = file.substr(file.lastIndexOf('/') + 1, file.lastIndexOf('.') - file.lastIndexOf('/') - 1);
			this.suffixes = suffixes;
			this.callback = callback;
			this.context = context;
			this.im.identify(this.file, proxy(this.resize, this));
		} catch(e) {
			this.complete(false, e);
		}
	},
	"resize": function(err, features) {
		try {
			if (err) { this.complete(false, err) };
			this.baseWidth = features && features.width ? features.width : 0;
			this.baseHeight = features && features.height ? features.height : 0;
			var resultName = this.path + this.name.split(this.suffixes[0]).join(this.suffixes[1]) + '.' + this.extention;

			if (fs.existsSync(resultName) || !this.baseWidth || !this.baseHeight) {
				this.complete(this, true);
			} else {
				this.im.resize({
					"width": Math.round(this.baseWidth/2),
					"height": Math.round(this.baseHeight/2),
					"srcPath": this.file,
					"dstPath": resultName
				}, proxy(this.complete, this));
				grunt.log.write('file [', resultName, '] is created.\n');

			}
		} catch (e) {
			this.complete(false, e);
		}
	},
	"complete": function(success, error) {
		this.callback.apply(this.context,[this, success, error]);
	}
};

module.exports = function(grunt) {
	grunt.registerMultiTask('retinaImg', 'generates images set due to configuration', function() {
		var done = this.async();
		grunt.log.warn("\nPlease make sure that you installed imageMagic CLI before start.\n");
		var files = grunt.file.expand(this.data.files);
		var suffixes = this.data.suffixes || ["@2x", "@1x"];

		var cmds=[];
		var cmd;

		function onComplete(cmd, success, err) {
			if (!success) {
				grunt.log.write("Error in: ", cmd.file, " processing: [", (err && err.code ? err.code : "UnknownError"), "]\n");
			}
			cmds.splice(cmds.indexOf(cmd), 1);
			if (!cmds.length) {
				done();
			}
		}

		for (var i = 0; i < files.length; i++) {
			cmd = Object.create(ImageMagicWrapper);
{'fraction_non_alphanumeric': 0.18844735764031134, 'fraction_numerical': 0.0061450225317492835, 'mean_word_length': 3.6861804222648753, 'pattern_counts': {'":': 18, '<': 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': '4403437', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1704, 'n_words': 350}