<commit_before>var fs = require('fs');
var chokidar = require('chokidar');
var knox = require('knox');
var events = require('events');
var uglifyJS = require('uglify-js');
var cleanCSS = require('clean-css');
var preprocessors = {
	handlebars: require('./preprocessors/handlebars.js'),
	jqtpl: require('./preprocessors/jquery-tmpl.js'),
	coffeescript: require('./preprocessors/coffeescript.js')
};

// Simple method to check for an array
var _isArray = function( object ){

	return ( Object.prototype.toString.call( object ) === '[object Array]' );

};

// Find the file extension from a filename
var _getExtension = function( path ){

	var i = path.lastIndexOf('.') + 1;
	return ( i < 0 )
		? ''
		: path.substr( i );

};

// Preprocess all file types with preprocessors available
var _preprocess = function( path, contents, flow ){

	var processed;

	if( flow.type === 'jst' ){
		if( flow.jst_lang === 'handlebars' )
			processed = preprocessors.handlebars( path, contents, flow );
		else if( flow.jst_lang === 'jquery-tmpl' )
			processed = preprocessors.jqtpl( path, contents, flow );
	}

	return processed || contents;

};

// Compute the "true path" of a path
var _getTruePath = function( root, path ){

	var root = root || '';
	var true_path;
	var root_last_character = root.charAt( root.length-1 );
	var root_trailing_slash = ( root_last_character === '/' || root_last_character === '\\' );
	
	if( root_trailing_slash && ( path === '/' || path === '\\' ) )
		true_path = root;
	else {
		true_path = ( root_trailing_slash || root === '' )
			? root + path
			: root +'/'+ path;
	}

	return true_path;

};

var igneous = new events.EventEmitter();
module.exports = igneous;

var flows = igneous.flows = {};
var config = {
	test: false,
	compress: false,
	watch: true,
	base_path: '',
	encoding: 'utf8',
	debug: false
};

//
// Flow
// Flow Class
//

igneous.Flow = function( attributes ){

	var attributes = attributes || {};
	var flow = this;
	var s3;
	var tmp;

	flow.name =				attributes.name;
	flow.type =				attributes.type;
	flow.extensions =		attributes.extensions;
	flow.base_path =		attributes.base_path || config.base_path;
	flow.paths =			attributes.paths;
	flow.files =			{};
	flow.compress =			attributes.compress || config.compress;
	flow.watch =			attributes.watch || config.watch;
	flow.jst_lang =			attributes.jst_lang;
	flow.jst_namespace =	attributes.jst_namespace;
	flow.encoding =			attributes.encoding || config.encoding;
	flow.string =			'';
	flow.url =				'';

	// Validate flow name
	if( typeof flow.name === 'function' )
		flow.name = flow.name();
	if( typeof flow.name !== 'string' )
		throw new Error('\'name\' must be a string or a function that returns a string');
	if( flow.name.length < 1 )
		throw new Error('\'name\' cannot be empty');

	// Validate flow type
	if( typeof flow.type === 'function' )
		flow.type = flow.type();
	if( typeof flow.type !== 'string' )
		throw new Error('\'type\' must be a string or a function that returns a string');
	if( flow.type !== 'css' && flow.type !== 'js' && flow.type !== 'javascript' && flow.type !== 'jst' )
		throw new Error('\'type\' must be \'css\', \'js\', or \'jst\'');
	if( flow.type === 'javascript' )
		flow.type === 'js';
	
	// Set valid extensions for this flow
	if( !flow.extensions ){
		if( flow.type === 'js' )
			flow.extensions = ['js'];
		else if( flow.type === 'css' )
			flow.extensions = ['css'];
		else if( flow.type === 'jst' )
			flow.extensions = ['jst'];
	}
	
	// Validate paths
	if( typeof flow.paths === 'string' )
		flow.paths = [flow.paths];
	if( !_isArray(flow.paths) )
		throw new Error('\'paths\' must be a string or array of strings');
	if( flow.paths.length < 1 )
		throw new Error('\'paths\' must contain relative paths as strings');
	flow.paths.forEach( function( path, i ){
		if( typeof path === 'function' )
			path = path();
	});

	// Validate host
	if( !config.host )
		throw new Error('\'host\' must be set');

	// Validate host (s3)
	if( config.host.provider === 's3' ){
		if( !config.aws_key )
			throw new Error('\'aws_key\' must be set');
		if( !config.aws_secret )
			throw new Error('\'aws_secret\' must be set');
		if( !config.s3_bucket )
			throw new Error('\'bucket\' must be set');
		// Create knox client
		s3 = knox.createClient({<commit_msg>fix error with s3 configuration<commit_after>var fs = require('fs');
var chokidar = require('chokidar');
var knox = require('knox');
var events = require('events');
var uglifyJS = require('uglify-js');
var cleanCSS = require('clean-css');
var preprocessors = {
	handlebars: require('./preprocessors/handlebars.js'),
	jqtpl: require('./preprocessors/jquery-tmpl.js'),
	coffeescript: require('./preprocessors/coffeescript.js')
};

// Simple method to check for an array
var _isArray = function( object ){

	return ( Object.prototype.toString.call( object ) === '[object Array]' );

};

// Find the file extension from a filename
var _getExtension = function( path ){

	var i = path.lastIndexOf('.') + 1;
	return ( i < 0 )
		? ''
		: path.substr( i );

};

// Preprocess all file types with preprocessors available
var _preprocess = function( path, contents, flow ){

	var processed;

	if( flow.type === 'jst' ){
		if( flow.jst_lang === 'handlebars' )
			processed = preprocessors.handlebars( path, contents, flow );
		else if( flow.jst_lang === 'jquery-tmpl' )
			processed = preprocessors.jqtpl( path, contents, flow );
	}

	return processed || contents;

};

// Compute the "true path" of a path
var _getTruePath = function( root, path ){

	var root = root || '';
	var true_path;
	var root_last_character = root.charAt( root.length-1 );
	var root_trailing_slash = ( root_last_character === '/' || root_last_character === '\\' );
	
	if( root_trailing_slash && ( path === '/' || path === '\\' ) )
		true_path = root;
	else {
		true_path = ( root_trailing_slash || root === '' )
			? root + path
			: root +'/'+ path;
	}

	return true_path;

};

var igneous = new events.EventEmitter();
module.exports = igneous;

var flows = igneous.flows = {};
var config = {
	test: false,
	compress: false,
	watch: true,
	base_path: '',
	encoding: 'utf8',
	debug: false
};

//
// Flow
// Flow Class
//

igneous.Flow = function( attributes ){

	var attributes = attributes || {};
	var flow = this;
	var s3;
	var tmp;

	flow.name =				attributes.name;
	flow.type =				attributes.type;
	flow.extensions =		attributes.extensions;
	flow.base_path =		attributes.base_path || config.base_path;
	flow.paths =			attributes.paths;
	flow.files =			{};
	flow.compress =			attributes.compress || config.compress;
	flow.watch =			attributes.watch || config.watch;
	flow.jst_lang =			attributes.jst_lang;
	flow.jst_namespace =	attributes.jst_namespace;
	flow.encoding =			attributes.encoding || config.encoding;
	flow.string =			'';
	flow.url =				'';

	// Validate flow name
	if( typeof flow.name === 'function' )
		flow.name = flow.name();
	if( typeof flow.name !== 'string' )
		throw new Error('\'name\' must be a string or a function that returns a string');
	if( flow.name.length < 1 )
		throw new Error('\'name\' cannot be empty');

	// Validate flow type
	if( typeof flow.type === 'function' )
		flow.type = flow.type();
	if( typeof flow.type !== 'string' )
		throw new Error('\'type\' must be a string or a function that returns a string');
	if( flow.type !== 'css' && flow.type !== 'js' && flow.type !== 'javascript' && flow.type !== 'jst' )
		throw new Error('\'type\' must be \'css\', \'js\', or \'jst\'');
	if( flow.type === 'javascript' )
		flow.type === 'js';
	
	// Set valid extensions for this flow
	if( !flow.extensions ){
		if( flow.type === 'js' )
			flow.extensions = ['js'];
		else if( flow.type === 'css' )
			flow.extensions = ['css'];
		else if( flow.type === 'jst' )
			flow.extensions = ['jst'];
	}
	
	// Validate paths
	if( typeof flow.paths === 'string' )
		flow.paths = [flow.paths];
	if( !_isArray(flow.paths) )
		throw new Error('\'paths\' must be a string or array of strings');
	if( flow.paths.length < 1 )
		throw new Error('\'paths\' must contain relative paths as strings');
	flow.paths.forEach( function( path, i ){
		if( typeof path === 'function' )
			path = path();
	});

	// Validate host
	if( !config.host )
		throw new Error('\'host\' must be set');

	// Validate host (s3)
	if( config.host.provider === 's3' ){
		if( !config.host.aws_key )
			throw new Error('\'aws_key\' must be set');
		if( !config.host.aws_secret )
			throw new Error('\'aws_secret\' must be set');
		if( !config.host.s3_bucket )
			throw new Error('\'bucket\' must be set');
		// Create knox client
		s3 = knox.createClient({
{'fraction_non_alphanumeric': 0.1718513340323896, 'fraction_numerical': 0.002679715717115228, 'mean_word_length': 3.484848484848485, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1301247', 'n_tokens_mistral': 3076, 'n_tokens_neox': 2901, 'n_words': 815}