更新
This commit is contained in:
+38
-8
@@ -11,12 +11,25 @@ module.exports = class Bamboo extends Koa {
|
||||
/*初始化业务目录*/
|
||||
constructor(extend_directory, root) {
|
||||
super();
|
||||
//全局配置
|
||||
this.config = {}
|
||||
//xe-utils工具
|
||||
this.xe = xe
|
||||
//根目录
|
||||
this.root = this.isPath() || root;
|
||||
//插件路径
|
||||
this.extend_directory = extend_directory || `extend/*/index.js`
|
||||
//等待扩展已经加载完成后立即执行的任务列表
|
||||
this.willReadyList = []
|
||||
console.log(`当前根目录${this.root}`);
|
||||
console.log(`当前插件目录${this.extend_directory}`);
|
||||
//全局别名,推荐命名规则,$+全局变量名,如$db
|
||||
this.alias = {
|
||||
"app": this,
|
||||
"$": this,
|
||||
}
|
||||
//等待启动完成后立即执行的任务列表
|
||||
this.fullList = []
|
||||
// console.log(`当前根目录${this.root}`);
|
||||
// console.log(`当前插件目录${this.extend_directory}`);
|
||||
this.loadEvent()
|
||||
}
|
||||
|
||||
@@ -26,17 +39,33 @@ module.exports = class Bamboo extends Koa {
|
||||
for (let listElement of list) {
|
||||
await listElement.res(this)
|
||||
}
|
||||
this.willReadyList.push(() => {
|
||||
this.startServer()
|
||||
})
|
||||
await this.loadAlias()
|
||||
await this.willReady()
|
||||
}
|
||||
|
||||
/*加载别名到全局变量,注意只有完成加载扩展后才能使用*/
|
||||
async loadAlias() {
|
||||
for (let key of Object.keys(this.alias)) {
|
||||
global[key] = this.alias[key]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*扩展已经加载完成触发*/
|
||||
async willReady() {
|
||||
this.willReadyList.push(async () => {
|
||||
await this.startServer()
|
||||
await this.full()
|
||||
})
|
||||
for (let WRL of this.willReadyList) {
|
||||
await WRL()
|
||||
await WRL(this)
|
||||
}
|
||||
}
|
||||
|
||||
/*启动完成*/
|
||||
async full() {
|
||||
for (let ful of this.fullList) {
|
||||
await ful(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +89,7 @@ module.exports = class Bamboo extends Koa {
|
||||
files = files.map(item => {
|
||||
const parse = path.parse(item);
|
||||
parse.father = path.basename(path.resolve(parse.dir, '..'))
|
||||
parse.file_father = path.basename(path.resolve(parse.dir + '/' + parse.name, '..'))
|
||||
return {
|
||||
parse,
|
||||
res: require(path.resolve(path_root + "/" + item))
|
||||
@@ -73,7 +103,7 @@ module.exports = class Bamboo extends Koa {
|
||||
|
||||
/*启动服务*/
|
||||
startServer(prod) {
|
||||
this.listen(prod || 3000)
|
||||
console.log('启动服务:3000');
|
||||
app.server = this.listen(prod || 3000)
|
||||
console.log(`http服务:http://127.0.0.1:${prod || 3000}`);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,4 +1,4 @@
|
||||
//入口文件
|
||||
// 入口文件
|
||||
require('@babel/register')({
|
||||
presets: ['@babel/env'],
|
||||
plugins: [
|
||||
@@ -12,7 +12,8 @@ require('@babel/register')({
|
||||
|
||||
]
|
||||
})
|
||||
require('@babel/polyfill')
|
||||
// require('@babel/polyfill')
|
||||
const bamboo = require('./bamboo/index')
|
||||
const app = new bamboo();
|
||||
// app.listen(3000);
|
||||
module.exports = app
|
||||
|
||||
Reference in New Issue
Block a user