<commit_before>/*global require:true*/
/*global module:true*/
/*global __dirname:true*/
/*global console:true*/
(function(){
	"use strict";

	var path = require( "path" );
	var os = require( "os" );

	var fs = require( "fs-extra" );
	var uglify = require( "uglify-js" );
	var DirectoryColorfy = require( "directory-colorfy" );
	var DirectoryEncoder = require( "directory-encoder" );
	var svgToPng = require( "svg-to-png" );
	var _ = require( "lodash" );
	_.mixin({ 'defaultsDeep': require('merge-defaults') });

//	var loadCSSpath = require.resolve( "fg-loadcss" );
	var helper = require( "./grunticon-helper.js" );

	var defaults = {
		datasvgcss: "icons.data.svg.css",
		datapngcss: "icons.data.png.css",
		urlpngcss: "icons.fallback.css",
		previewhtml: "preview.html",
		loadersnippet: "grunticon.loader.js",
		cssbasepath: path.sep,
		customselectors: {},
		cssprefix: ".icon-",
		defaultWidth: "400px",
		defaultHeight: "300px",
		colors: {},
		dynamicColorOnly: false,
		pngfolder: "png",
		pngpath: "",
		template: "",
		tmpPath: os.tmpDir(),
		tmpDir: "grunticon-tmp",
		previewTemplate: path.join( __dirname, "..", "static", "preview.hbs" ),
		compressPNG: false,
		optimizationLevel: 3,
		enhanceSVG: false,
		corsEmbed: false,
		logger: {
			verbose: console.info,
			fatal: console.error,
			ok: console.log
		}
	};


	var Grunticon = function(files, output, config){
		config = config || {};

		if( !Array.isArray( files ) ){
			throw new Error( "The first argument passed into the Grunticon constructor must be an array of files" );
		}

		if( typeof output !== "string" ){
			throw new Error( "The second argument passed into the Grunticon constructor must be a string, a path to an output directory" );
		}

		this.files = files;
		this.output = output;

		this.options = _.defaultsDeep( config, defaults );
		this.logger = this.options.logger;
	};

	Grunticon.prototype._generateLoader = function(){

		var files = {
			loader: path.join( __dirname, "..", "static", "grunticon.loader.js"),
			embed: path.join( __dirname, "..", "static", "grunticon.embed.js"),
			corsEmbed: path.join( __dirname, "..", "static", "grunticon.embed.cors.js"),
			banner: path.join( __dirname, "..", "static", "grunticon.loader.banner.js")
		};

		var logger = this.logger;
		var config = this.options;
		var min = [];

		// minify the source of the grunticon loader and write that to the output
		logger.verbose( "grunticon now minifying the stylesheet loader source." );
		var banner = fs.readFileSync( files.banner ).toString( "utf-8" );
//		var loadcss = fs.readFileSync( loadCSSpath ).toString( "utf-8" );

//		min = min.concat( loadcss )
			min = min.concat( banner )
			.concat( "\n" )
			.concat( uglify.minify( files.loader ).code );
		if( config.enhanceSVG ){
			min = min.concat( uglify.minify( files.embed ).code );
			if( config.corsEmbed ){
				min = min.concat( uglify.minify( files.corsEmbed ).code );
			}
		}

		return min.join( "" );
	};


	Grunticon.prototype.process = function(cb){
		// folder name (within the output folder) for generated png files
		var config = this.options;
		var logger = this.logger;

		var pngfolder = path.join.apply( null, config.pngfolder.split( path.sep ) );

		// create the output directory
		fs.mkdirpSync( this.output );

		// minify the source of the grunticon loader and write that to the output
		var loader = config.min = this._generateLoader();
		fs.writeFileSync( path.join( this.output, config.loadersnippet ), loader );
		logger.verbose( "grunticon loader file created." );
<commit_msg>This is a static method<commit_after>/*global require:true*/
/*global module:true*/
/*global __dirname:true*/
/*global console:true*/
(function(){
	"use strict";

	var path = require( "path" );
	var os = require( "os" );

	var fs = require( "fs-extra" );
	var uglify = require( "uglify-js" );
	var DirectoryColorfy = require( "directory-colorfy" );
	var DirectoryEncoder = require( "directory-encoder" );
	var svgToPng = require( "svg-to-png" );
	var _ = require( "lodash" );
	_.mixin({ 'defaultsDeep': require('merge-defaults') });

//	var loadCSSpath = require.resolve( "fg-loadcss" );
	var helper = require( "./grunticon-helper.js" );

	var defaults = {
		datasvgcss: "icons.data.svg.css",
		datapngcss: "icons.data.png.css",
		urlpngcss: "icons.fallback.css",
		previewhtml: "preview.html",
		loadersnippet: "grunticon.loader.js",
		cssbasepath: path.sep,
		customselectors: {},
		cssprefix: ".icon-",
		defaultWidth: "400px",
		defaultHeight: "300px",
		colors: {},
		dynamicColorOnly: false,
		pngfolder: "png",
		pngpath: "",
		template: "",
		tmpPath: os.tmpDir(),
		tmpDir: "grunticon-tmp",
		previewTemplate: path.join( __dirname, "..", "static", "preview.hbs" ),
		compressPNG: false,
		optimizationLevel: 3,
		enhanceSVG: false,
		corsEmbed: false,
		logger: {
			verbose: console.info,
			fatal: console.error,
			ok: console.log
		}
	};


	var Grunticon = function(files, output, config){
		config = config || {};

		if( !Array.isArray( files ) ){
			throw new Error( "The first argument passed into the Grunticon constructor must be an array of files" );
		}

		if( typeof output !== "string" ){
			throw new Error( "The second argument passed into the Grunticon constructor must be a string, a path to an output directory" );
		}

		this.files = files;
		this.output = output;

		this.options = _.defaultsDeep( config, defaults );
		this.logger = this.options.logger;
	};

	Grunticon.generateLoader = function( enhanceSVG, corsEmbed, logger ){

		var files = {
			loader: path.join( __dirname, "..", "static", "grunticon.loader.js"),
			embed: path.join( __dirname, "..", "static", "grunticon.embed.js"),
			corsEmbed: path.join( __dirname, "..", "static", "grunticon.embed.cors.js"),
			banner: path.join( __dirname, "..", "static", "grunticon.loader.banner.js")
		};

		var min = [];

		// minify the source of the grunticon loader and write that to the output
		logger.verbose( "grunticon now minifying the stylesheet loader source." );
		var banner = fs.readFileSync( files.banner ).toString( "utf-8" );
//		var loadcss = fs.readFileSync( loadCSSpath ).toString( "utf-8" );

//		min = min.concat( loadcss )
			min = min.concat( banner )
			.concat( "\n" )
			.concat( uglify.minify( files.loader ).code );
		if( enhanceSVG ){
			min = min.concat( uglify.minify( files.embed ).code );
			if( corsEmbed ){
				min = min.concat( uglify.minify( files.corsEmbed ).code );
			}
		}

		return min.join( "" );
	};


	Grunticon.prototype.process = function(cb){
		// folder name (within the output folder) for generated png files
		var config = this.options;
		var logger = this.logger;

		var pngfolder = path.join.apply( null, config.pngfolder.split( path.sep ) );

		// create the output directory
		fs.mkdirpSync( this.output );

		// minify the source of the grunticon loader and write that to the output
		var loader = config.min = Grunticon.generateLoader( config.enhanceSVG, config.corsEmbed, logger );
		fs.writeFileSync( path.join( this.output, config.loadersnippet ), loader );
		logger.verbose( "grunticon loader file created." );

{'fraction_non_alphanumeric': 0.15450704225352113, 'fraction_numerical': 0.0025352112676056337, 'mean_word_length': 3.6840369393139842, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2317039', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2356, 'n_words': 638}