Ai
3 Star 25 Fork 11

yapi-pro/yapi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
yapi.js 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
suxiaoxin 提交于 2018-01-14 20:26 +08:00 . fix: yapi resolve
const path = require('path');
const fs = require('fs-extra');
const nodemailer = require('nodemailer');
const config = require('../../config.json');
let insts = new Map();
let mail;
const WEBROOT = path.resolve(__dirname, '..'); //路径
const WEBROOT_SERVER = __dirname;
const WEBROOT_RUNTIME = path.resolve(__dirname, '../..');
const WEBROOT_LOG = path.join(WEBROOT_RUNTIME, 'log');
const WEBCONFIG = config;
fs.ensureDirSync(WEBROOT_LOG);
if (WEBCONFIG.mail && WEBCONFIG.mail.enable) {
mail = nodemailer.createTransport(WEBCONFIG.mail);
}
/**
* 获取一个model实例,如果不存在则创建一个新的返回
* @param {*} m class
* @example
* yapi.getInst(groupModel, arg1, arg2)
*/
function getInst(m, ...args) {
if (!insts.get(m)) {
insts.set(m, new m(args));
}
return insts.get(m);
}
function delInst(m) {
try {
insts.delete(m);
} catch (err) {
console.error(err); // eslint-disable-line
}
}
let r = {
fs: fs,
path: path,
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;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/yapi-pro/yapi.git
git@gitee.com:yapi-pro/yapi.git
yapi-pro
yapi
yapi
master

搜索帮助