yapi/server_dist/yapi.js
2017-07-27 11:50:15 +08:00

79 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
var _map = require('babel-runtime/core-js/map');
var _map2 = _interopRequireDefault(_map);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _fsExtra = require('fs-extra');
var _fsExtra2 = _interopRequireDefault(_fsExtra);
var _nodemailer = require('nodemailer');
var _nodemailer2 = _interopRequireDefault(_nodemailer);
var _config = require('../runtime/config.json');
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var insts = new _map2.default();
var mail = void 0;
var WEBROOT = _path2.default.resolve(__dirname, '..'); //路径
var WEBROOT_SERVER = __dirname;
var WEBROOT_RUNTIME = _config2.default.runtime_path;
var WEBROOT_LOG = _path2.default.join(WEBROOT_RUNTIME, 'log');
var WEBCONFIG = _config2.default;
_fsExtra2.default.ensureDirSync(WEBROOT_RUNTIME);
_fsExtra2.default.ensureDirSync(WEBROOT_LOG);
if (WEBCONFIG.mail) {
mail = _nodemailer2.default.createTransport(WEBCONFIG.mail);
}
/**
* 获取一个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);
}
}
var r = {
fs: _fsExtra2.default,
path: _path2.default,
WEBROOT: WEBROOT,
WEBROOT_SERVER: WEBROOT_SERVER,
WEBROOT_RUNTIME: WEBROOT_RUNTIME,
WEBROOT_LOG: WEBROOT_LOG,
WEBCONFIG: WEBCONFIG,
getInst: getInst,
delInst: delInst,
getInsts: insts
};
if (mail) r.mail = mail;
module.exports = r;