<commit_before>/*!
 * contentstack-express
 * copyright (c) Built.io Contentstack
 * MIT Licensed
 */

'use strict';

/*!
 * Module dependencies
 */
var _ = require('lodash'),
	pathToRegexp = require('path-to-regexp'),
	fs = require('graceful-fs'),
	path = require('path'),
	mkdirp = require('mkdirp');

path.isAbsolute = path.isAbsolute || function(_path){return /^[a-zA-Z]\:\\/.test(_path) || (/^[/]/.test(_path));};

/**
 * overrides default configuration with environment specific configuration
 */
function Config() {
	try {
		var env = process.env.NODE_ENV || "development",
			server = process.env.SERVER || process.env.server || 'default',
			sync = process.env.SYNC || "true",
			_dirname = (process.env.SITE_PATH) ? path.resolve(process.env.SITE_PATH) : process.cwd();

		var _path = path.join(_dirname, 'config'),
			_default =  require('./default'),
			_all = fs.existsSync(path.join(_path, 'all.js')) ? require(path.join(_path, 'all')) : {},
			_env = fs.existsSync(path.join(_path, env + '.js')) ? require(path.join(_path, env)) : {};

		// merge default configuration with specified environment
		var _config = _.merge(_default, _.merge(_all, _env));

		// set other configurations
		var _theme = path.join(_dirname, 'themes', _config.theme);
		_config.environment = env;
		_config.server = server;
		_config.sync = sync;

        if(!_config.storage) throw new Error('Storage must be specified.');
		// set path
		_config.path = {
			base: _dirname,
			theme: _theme,
			templates: path.join(_theme, 'templates'),
			favicon: (path.isAbsolute(_config.static.path)) ? path.resolve(_config.static.path, 'favicon.ico') : path.resolve(_theme, _config.static.path, 'favicon.ico'),
			logs: (path.isAbsolute(_config.logs.path)) ? _config.logs.path : path.join(_dirname, _config.logs.path),
			storage: (_config.storage && _config.storage.options && path.isAbsolute(_config.storage.options.basedir)) ? _config.storage.options.basedir : path.join(_dirname, ((_config.storage && _config.storage.options) ? _config.storage.options.basedir || "./_content" : "./_content")),
		};

        if(_config.storage && _config.storage.provider.toLowerCase() !== 'filesystem') {
            _config.path.assets = (_config.assets && path.isAbsolute(_config.assets.basedir)) ? _config.assets.basedir : path.join(_dirname, (_config.assets.basedir || "./assets"));
        }
		// configure storage
        _config.assets = storage(_config.assets);

		// configure languages
		_config.languages = languages(_config);

		this._config = _config;
	} catch (e) {
		console.error('Error in loading config.'+ e.message);
	}
}<commit_msg>added url path as _uid for rte assets added sync as option false<commit_after>/*!
 * contentstack-express
 * copyright (c) Built.io Contentstack
 * MIT Licensed
 */

'use strict';

/*!
 * Module dependencies
 */
var _ = require('lodash'),
	pathToRegexp = require('path-to-regexp'),
	fs = require('graceful-fs'),
	path = require('path'),
	mkdirp = require('mkdirp');

path.isAbsolute = path.isAbsolute || function(_path){return /^[a-zA-Z]\:\\/.test(_path) || (/^[/]/.test(_path));};

/**
 * overrides default configuration with environment specific configuration
 */
function Config() {
	try {
		var env = process.env.NODE_ENV || "development",
			server = process.env.SERVER || process.env.server || 'default',
			_dirname = (process.env.SITE_PATH) ? path.resolve(process.env.SITE_PATH) : process.cwd();

		var _path = path.join(_dirname, 'config'),
			_default =  require('./default'),
			_all = fs.existsSync(path.join(_path, 'all.js')) ? require(path.join(_path, 'all')) : {},
			_env = fs.existsSync(path.join(_path, env + '.js')) ? require(path.join(_path, env)) : {};

		// merge default configuration with specified environment
		var _config = _.merge(_default, _.merge(_all, _env));

		// set other configurations
		var _theme = path.join(_dirname, 'themes', _config.theme);
		_config.environment = env;
		_config.server = server;

        if(!_config.storage) throw new Error('Storage must be specified.');
		// set path
		_config.path = {
			base: _dirname,
			theme: _theme,
			templates: path.join(_theme, 'templates'),
			favicon: (path.isAbsolute(_config.static.path)) ? path.resolve(_config.static.path, 'favicon.ico') : path.resolve(_theme, _config.static.path, 'favicon.ico'),
			logs: (path.isAbsolute(_config.logs.path)) ? _config.logs.path : path.join(_dirname, _config.logs.path),
			storage: (_config.storage && _config.storage.options && path.isAbsolute(_config.storage.options.basedir)) ? _config.storage.options.basedir : path.join(_dirname, ((_config.storage && _config.storage.options) ? _config.storage.options.basedir || "./_content" : "./_content")),
		};

        if(_config.storage && _config.storage.provider.toLowerCase() !== 'filesystem') {
            _config.path.assets = (_config.assets && path.isAbsolute(_config.assets.basedir)) ? _config.assets.basedir : path.join(_dirname, (_config.assets.basedir || "./assets"));
        }
		// configure storage
        _config.assets = storage(_config.assets);

		// configure languages
		_config.languages = languages(_config);

		this._config = _config;
	} catch (e) {
		console.error('Error in loading config.'+ e.message);
	}
}
{'fraction_non_alphanumeric': 0.17182721712538226, 'fraction_numerical': 0.0, 'mean_word_length': 4.056038647342995, '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': '1748543', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1620, 'n_words': 329}