2017-07-04 16:43:07 +08:00
|
|
|
|
import path from 'path'
|
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
|
import prdConfig from './config.json'
|
|
|
|
|
import devConfig from './config.dev.json'
|
|
|
|
|
let args = process.argv.splice(2);
|
|
|
|
|
let isDev = args[0] === 'dev' ? true : false;
|
2017-07-05 16:52:48 +08:00
|
|
|
|
var insts = new Map();
|
2017-07-04 16:43:07 +08:00
|
|
|
|
const config = isDev ? devConfig : prdConfig;
|
|
|
|
|
|
2017-07-05 17:59:53 +08:00
|
|
|
|
const WEBROOT = path.resolve(__dirname, '..'); //路径
|
2017-07-04 16:43:07 +08:00
|
|
|
|
const WEBROOT_SERVER = __dirname;
|
|
|
|
|
const WEBROOT_RUNTIME = path.join(WEBROOT, 'runtime');
|
|
|
|
|
const WEBROOT_LOG = path.join(WEBROOT_RUNTIME, 'log');
|
|
|
|
|
const WEBCONFIG = config;
|
|
|
|
|
|
2017-07-05 16:52:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取一个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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 16:43:07 +08:00
|
|
|
|
module.exports = {
|
|
|
|
|
fs: fs,
|
|
|
|
|
path: path,
|
|
|
|
|
WEBROOT: WEBROOT,
|
|
|
|
|
WEBROOT_SERVER: WEBROOT_SERVER,
|
|
|
|
|
WEBROOT_RUNTIME: WEBROOT_RUNTIME,
|
|
|
|
|
WEBROOT_LOG: WEBROOT_LOG,
|
|
|
|
|
WEBCONFIG: WEBCONFIG,
|
2017-07-05 16:52:48 +08:00
|
|
|
|
getInst: getInst,
|
|
|
|
|
delInst: delInst,
|
|
|
|
|
getInsts: insts
|
2017-07-04 16:43:07 +08:00
|
|
|
|
}
|