<commit_before>var
	fs = require('fs'),
	path = require('path'),
	merge = require('merge'),

	Promise = require('bluebird'),
	Builder = require('systemjs-builder'),

	DEFAULTS = {
		config: null,
		configPath: undefined,
		basePath: undefined,
		pluginPathes: [],
		out: '../build/',
		onMessage: function(/* message */) {}
	},

	MESSAGE_TYPE_ERROR = 'error',
	MESSAGE_TYPE_INFO = 'info',
	MESSAGE_TYPE_SUCCESS = 'success'
;


function PluginBuilder(options) {
	this._options = merge({}, DEFAULTS, options);
	this._builder = new Builder();
}

PluginBuilder.prototype.build = function() {
	return new Promise(function(resolve, reject) {

		this._loadConfig()
			.then(this._buildBase.bind(this))
			.then(this._buildPlugins.bind(this))
			.then(resolve)
			.error(reject);

	}.bind(this));
};

PluginBuilder.prototype.getConfig = function() {
	return merge({}, this._builder.loader.pluginLoader);
};

PluginBuilder.prototype._log = function(message, type) {
	this._options.onMessage({
		message: message,
		type: type
	});
};

PluginBuilder.prototype._logError = function(message) {
	this._log(message, MESSAGE_TYPE_ERROR);
};

PluginBuilder.prototype._logInfo = function(message) {
	this._log(message, MESSAGE_TYPE_INFO);
};

PluginBuilder.prototype._logSuccess = function(message) {
	this._log(message, MESSAGE_TYPE_SUCCESS);
};

PluginBuilder.prototype._getStat = function(filepath) {
	var stat = null;

	if (typeof filepath === 'string') {
		try {
			stat = fs.statSync(filepath);
		} catch(error) {}
	}

	return stat;
};

PluginBuilder.prototype._getOutpath = function(filepath, out) {
	var
		dir = path.dirname(filepath),
		name = path.basename(filepath)
	;

	return path.join(dir, out, name);
};

PluginBuilder.prototype._loadConfig = function() {
	return new Promise(function(resolve, reject) {

		var stat = this._getStat(this._options.configPath);

		if (stat && stat.isDirectory()) {
			reject(new Error('Config file path is an directory'));
		}

		if (stat && stat.isFile()) {
			this._builder
				.loadConfig(this._options.configPath)
				.then(this._mergeConfig.bind(this))
				.then(resolve);
		} else {
			this._mergeConfig()
				.then(resolve)
				.error(reject);
		}

	}.bind(this));
};

PluginBuilder.prototype._mergeConfig = function() {
	return new Promise(function(resolve) {
		if (this._options.config && typeof this._options.config === 'object') {
			var message = 'Use config: ';

			Object.keys(this._options.config).forEach(function(key) {
				message += key + ': "' + this._options.config[key] + '"';
			}.bind(this));

			this._logInfo(message);
			this._builder.config(this._options.config);
		}
		resolve();

	}.bind(this));
};
<commit_msg>Update merge process<commit_after>var
	fs = require('fs'),
	path = require('path'),
	merge = require('merge'),

	Promise = require('bluebird'),
	Builder = require('systemjs-builder'),

	DEFAULTS = {
		config: null,
		configPath: undefined,
		basePath: undefined,
		pluginPathes: [],
		out: '../build/',
		onMessage: function(/* message */) {}
	},

	MESSAGE_TYPE_ERROR = 'error',
	MESSAGE_TYPE_INFO = 'info',
	MESSAGE_TYPE_SUCCESS = 'success'
;


function PluginBuilder(options) {
	this._options = merge({}, DEFAULTS, options);
	this._builder = new Builder();
}

PluginBuilder.prototype.build = function() {
	return new Promise(function(resolve, reject) {

		this._loadConfig()
			.then(this._mergeConfig.bind(this))
			.then(this._buildBase.bind(this))
			.then(this._buildPlugins.bind(this))
			.then(resolve)
			.error(reject);

	}.bind(this));
};

PluginBuilder.prototype.getConfig = function() {
	return merge({}, this._builder.loader.pluginLoader);
};

PluginBuilder.prototype._log = function(message, type) {
	this._options.onMessage({
		message: message,
		type: type
	});
};

PluginBuilder.prototype._logError = function(message) {
	this._log(message, MESSAGE_TYPE_ERROR);
};

PluginBuilder.prototype._logInfo = function(message) {
	this._log(message, MESSAGE_TYPE_INFO);
};

PluginBuilder.prototype._logSuccess = function(message) {
	this._log(message, MESSAGE_TYPE_SUCCESS);
};

PluginBuilder.prototype._getStat = function(filepath) {
	var stat = null;

	if (typeof filepath === 'string') {
		try {
			stat = fs.statSync(filepath);
		} catch(error) {}
	}

	return stat;
};

PluginBuilder.prototype._getOutpath = function(filepath, out) {
	var
		dir = path.dirname(filepath),
		name = path.basename(filepath)
	;

	return path.join(dir, out, name);
};

PluginBuilder.prototype._loadConfig = function() {
	return new Promise(function(resolve, reject) {

		var stat = this._getStat(this._options.configPath);

		if (stat && stat.isDirectory()) {
			reject(new Error('Config file path is an directory'));
		}

		if (stat && stat.isFile()) {
			this._builder
				.loadConfig(this._options.configPath)
				.then(resolve);
		}

	}.bind(this));
};

PluginBuilder.prototype._mergeConfig = function() {
	return new Promise(function(resolve) {
		if (this._options.config && typeof this._options.config === 'object') {
			var message = 'Use config: ';

			Object.keys(this._options.config).forEach(function(key) {
				message += key + ': "' + this._options.config[key] + '"';
			}.bind(this));

			this._logInfo(message);
			this._builder.config(this._options.config);
		}
		resolve();

	}.bind(this));
};

{'fraction_non_alphanumeric': 0.16233643087426514, 'fraction_numerical': 0.0, 'mean_word_length': 4.448347107438017, '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': '4851950', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1714, 'n_words': 312}