feat: 调整初始化逻辑 添加core/ext加载路径

This commit is contained in:
coding 2017-11-15 12:55:13 +00:00
parent c28b2f93aa
commit bc51852c46
4 changed files with 103 additions and 88 deletions

View File

@ -17,6 +17,9 @@
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>plugins/**.js</exclude>
</excludes>
<filtering>true</filtering>
</resource>
</resources>
@ -49,7 +52,7 @@
</execution>
</executions>
</plugin>
<!--<plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.13</version>
@ -71,7 +74,7 @@
</configuration>
</execution>
</executions>
</plugin>-->
</plugin>
</plugins>
</build>
<ciManagement>

View File

@ -28,12 +28,6 @@ var disable;
init(root);
} catch (ex) {
ex.printStackTrace();
} finally {
disable = function () {
if (disablePlugins && typeof(disablePlugins) === "function") {
disablePlugins();
}
}
}
};

View File

@ -2,15 +2,21 @@
var global = this;
/*global base*/
(function (global) {
// noinspection JSUnusedLocalSymbols
function init(root) {
global.init = function init(root) {
global.root = root;
global.noop = function () {};
loadCore();
loadRequire();
loadPatch();
try{
loadExt();
loadServerLib();
loadPlugins();
} catch (ex) {
console.console("§4初始化插件基础系统库错误:§c", ex);
console.ex(ex);
}
}
/**
@ -36,9 +42,20 @@ function loadRequire() {
/**
* 加载补丁
*/
function loadPatch() {
function loadExt() {
var fs = require('core/fs');
fs.list(fs.file(root, 'core/ext')).forEach(function (path) {
console.log('加载扩展类库', path);
try{
load(path.toFile());
} catch (ex) {
console.ex(ex);
}
})
// 加载补丁和扩展
load(root + '/core/patch.js');
// load(root + '/core/patch.js');
// 加载underscore类库
// load('https://cdn.bootcss.com/underscore.js/1.8.3/underscore-min.js');
}
/**
@ -66,11 +83,11 @@ function loadServerLib() {
function loadPlugins() {
// 初始化本体插件
global.manager = require('api/plugin');
if (manager) {
manager.init('plugins');
if (global.manager) {
global.manager.init('plugins');
// 只有当在正式环境运行的时候才加载
manager.load();
manager.enable();
global.manager.load();
global.manager.enable();
} else {
console.console('§4当前服务器不支持使用MiaoScript插件系统!');
}
@ -80,8 +97,9 @@ function loadPlugins() {
/**
* 关闭插件Hook
*/
function disablePlugins() {
if (manager && manager.$) {
manager.disable();
global.disable = function disable() {
if (global.manager && global.manager.$) {
global.manager.disable();
}
}
})(global);