2017-07-04 16:43:07 +08:00
|
|
|
|
'use strict';
|
|
|
|
|
|
2017-07-05 16:52:48 +08:00
|
|
|
|
var _map = require('babel-runtime/core-js/map');
|
|
|
|
|
|
|
|
|
|
var _map2 = _interopRequireDefault(_map);
|
|
|
|
|
|
2017-07-04 16:43:07 +08:00
|
|
|
|
var _path = require('path');
|
|
|
|
|
|
|
|
|
|
var _path2 = _interopRequireDefault(_path);
|
|
|
|
|
|
|
|
|
|
var _fsExtra = require('fs-extra');
|
|
|
|
|
|
|
|
|
|
var _fsExtra2 = _interopRequireDefault(_fsExtra);
|
|
|
|
|
|
2017-07-11 16:50:17 +08:00
|
|
|
|
var _nodemailer = require('nodemailer');
|
|
|
|
|
|
|
|
|
|
var _nodemailer2 = _interopRequireDefault(_nodemailer);
|
|
|
|
|
|
|
|
|
|
var _config = require('../runtime/config.json');
|
2017-07-04 16:43:07 +08:00
|
|
|
|
|
|
|
|
|
var _config2 = _interopRequireDefault(_config);
|
|
|
|
|
|
2017-07-11 16:50:17 +08:00
|
|
|
|
var _configDev = require('../runtime/config.dev.json');
|
2017-07-04 16:43:07 +08:00
|
|
|
|
|
|
|
|
|
var _configDev2 = _interopRequireDefault(_configDev);
|
|
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
|
|
|
|
var args = process.argv.splice(2);
|
|
|
|
|
var isDev = args[0] === 'dev' ? true : false;
|
2017-07-05 16:52:48 +08:00
|
|
|
|
var insts = new _map2.default();
|
2017-07-11 16:50:17 +08:00
|
|
|
|
var mail = void 0;
|
2017-07-04 16:43:07 +08:00
|
|
|
|
var config = isDev ? _configDev2.default : _config2.default;
|
|
|
|
|
|
2017-07-05 17:59:53 +08:00
|
|
|
|
var WEBROOT = _path2.default.resolve(__dirname, '..'); //路径
|
2017-07-04 16:43:07 +08:00
|
|
|
|
var WEBROOT_SERVER = __dirname;
|
|
|
|
|
var WEBROOT_RUNTIME = _path2.default.join(WEBROOT, 'runtime');
|
|
|
|
|
var WEBROOT_LOG = _path2.default.join(WEBROOT_RUNTIME, 'log');
|
|
|
|
|
var WEBCONFIG = config;
|
|
|
|
|
|
2017-07-11 16:50:17 +08:00
|
|
|
|
_fsExtra2.default.ensureDirSync(WEBROOT_LOG);
|
|
|
|
|
|
|
|
|
|
if (WEBCONFIG.mail) {
|
|
|
|
|
mail = _nodemailer2.default.createTransport(WEBCONFIG.mail);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-05 16:52:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取一个model实例,如果不存在则创建一个新的返回
|
|
|
|
|
* @param {*} m class
|
|
|
|
|
* @example
|
|
|
|
|
* yapi.getInst(groupModel, arg1, arg2)
|
|
|
|
|
*/
|
|
|
|
|
function getInst(m) {
|
|
|
|
|
if (!insts.get(m)) {
|
|
|
|
|
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
|
|
|
args[_key - 1] = arguments[_key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insts.set(m, new m(args));
|
|
|
|
|
}
|
|
|
|
|
return insts.get(m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delInst(m) {
|
|
|
|
|
try {
|
|
|
|
|
insts.delete(m);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-11 16:50:17 +08:00
|
|
|
|
var r = {
|
2017-07-04 16:43:07 +08:00
|
|
|
|
fs: _fsExtra2.default,
|
|
|
|
|
path: _path2.default,
|
|
|
|
|
WEBROOT: WEBROOT,
|
|
|
|
|
WEBROOT_SERVER: WEBROOT_SERVER,
|
|
|
|
|
WEBROOT_RUNTIME: WEBROOT_RUNTIME,
|
|
|
|
|
WEBROOT_LOG: WEBROOT_LOG,
|
2017-07-05 16:52:48 +08:00
|
|
|
|
WEBCONFIG: WEBCONFIG,
|
|
|
|
|
getInst: getInst,
|
|
|
|
|
delInst: delInst,
|
|
|
|
|
getInsts: insts
|
2017-07-11 16:50:17 +08:00
|
|
|
|
};
|
|
|
|
|
if (mail) r.mail = mail;
|
|
|
|
|
module.exports = r;
|