/**
 * @file Node env
 * @author treelite(c.xinle@gmail.com)
 */

var extend = require('saber-lang').extend;
var Resolver = require('saber-promise');
var configMgr = require('./lib/config');

var Presenter = require('./lib/Presenter');

/**
 * 字符串判断
 *
 * @inner
 * @param {*} value 变量
 * @return {boolean}
 */
function isString(value) {
    return Object.prototype.toString.call(value)
        === '[object String]';
}

/**
 * 全局配置
 *
 * @param {Object} options 配置信息
 * @param {string|Array.<string>=} options.template 公共模版
 * @param {Object=} options.templateConfig 模版配置信息
 * @param {Object=} options.templateData 公共静态模版数据
 * @param {Object=} options.router 路由器
 * @param {string=} options.basePath 动态加载Presenter的根路径
 */
exports.config = function (options) {
    configMgr.set(options);
};

/**
 * 创建Presenter
 *
 * @inner
 * @param {Object|string} config 配置信息
 * @return {Promise}
 */
exports.create = function (config) {
    // 动态加载Presenter配置
    if (isString(config)) {
        var path = require('path');
        var base = configMgr.get('basePath') || process.cwd();
        config = path.resolve(base, config);
        return exports.create(require(config));
    }

    var Constructor;
    config = configMgr.normal(config);

    if (config.constructor !== Object) {
        Constructor = config.constructor;
    }
    else {
        Constructor = Presenter;
    }

    return Resolver.resolved(new Constructor(config));
};

exports.Abstract = require('./lib/Abstract');

exports.Presenter = require('./lib/Presenter');

exports.Model = require('./lib/Model');

exports.View = require('./lib/View');

@@ -63,51 +63,8 @@
 */%0A%0A
-var extend = require('saber-lang').extend;%0A
 var 
@@ -100,16 +100,16 @@
 mise');%0A
+
 var conf
@@ -140,16 +140,44 @@
 onfig');
+%0Avar path = require('path');
 %0A%0Avar Pr
@@ -399,16 +399,463 @@
 g%5D';%0A%7D%0A%0A
+/**%0A * Presenter %E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E7%BC%93%E5%AD%98%0A *%0A * @type %7BObject%7D%0A */%0Avar configCaches = %7B%7D;%0A%0A/**%0A * %E5%8A%A0%E8%BD%BD Presenter %E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%0A *%0A * @param %7Bstring%7D name %E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%9C%B0%E5%9D%80%0A * @return %7BObject%7D%0A */%0Afunction loadConfig(name) %7B%0A    var config = configCaches%5Bname%5D;%0A%0A    if (!config) %7B%0A        var base = configMgr.get('basePath') %7C%7C process.cwd();%0A        var file = path.resolve(base, name);%0A        config = require(file);%0A        configCaches%5Bname%5D = config;%0A    %7D%0A%0A    return config;%0A%7D%0A%0A
 /**%0A * %E5%85%A8
@@ -1405,152 +1405,8 @@
 ) %7B%0A
-        var path = require('path');%0A        var base = configMgr.get('basePath') %7C%7C process.cwd();%0A        config = path.resolve(base, config);%0A
     
@@ -1431,23 +1431,26 @@
 .create(
-require
+loadConfig
 (config)

Add caches for loading Presenter config