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

View File

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

View File

@ -2,49 +2,66 @@
var global = this; var global = this;
/*global base*/ /*global base*/
// noinspection JSUnusedLocalSymbols (function (global) {
function init(root) { // noinspection JSUnusedLocalSymbols
global.init = function init(root) {
global.root = root; global.root = root;
global.noop = function () {}; global.noop = function () {};
loadCore(); loadCore();
loadRequire(); loadRequire();
loadPatch(); try{
loadExt();
loadServerLib(); loadServerLib();
loadPlugins(); loadPlugins();
} } catch (ex) {
console.console("§4初始化插件基础系统库错误:§c", ex);
console.ex(ex);
}
}
/** /**
* 初始化核心 * 初始化核心
*/ */
function loadCore() { function loadCore() {
// 加载基础模块 // 加载基础模块
load(root + '/core/ext.js'); load(root + '/core/ext.js');
// 探测服务器类型 // 探测服务器类型
load(root + '/core/detect.js'); load(root + '/core/detect.js');
// 加载Console // 加载Console
load(root + '/core/console.js'); load(root + '/core/console.js');
} }
/** /**
* 初始化模块 * 初始化模块
*/ */
function loadRequire() { function loadRequire() {
// 初始化加载器 // 初始化加载器
global.require = load(root + '/core/require.js')(root); global.require = load(root + '/core/require.js')(root);
} }
/** /**
* 加载补丁 * 加载补丁
*/ */
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');
}
/** /**
* 加载Bukkit的类库 * 加载Bukkit的类库
*/ */
function loadServerLib() { function loadServerLib() {
var task = require('api/task'); var task = require('api/task');
global.setTimeout = function (func, time, _async) { global.setTimeout = function (func, time, _async) {
return _async ? task.laterAsync(func, time) : task.later(func, time); return _async ? task.laterAsync(func, time) : task.later(func, time);
@ -58,30 +75,31 @@ function loadServerLib() {
global.clearInterval = function (task) { global.clearInterval = function (task) {
task.cancel(); task.cancel();
}; };
} }
/** /**
* 加载JS插件 * 加载JS插件
*/ */
function loadPlugins() { function loadPlugins() {
// 初始化本体插件 // 初始化本体插件
global.manager = require('api/plugin'); global.manager = require('api/plugin');
if (manager) { if (global.manager) {
manager.init('plugins'); global.manager.init('plugins');
// 只有当在正式环境运行的时候才加载 // 只有当在正式环境运行的时候才加载
manager.load(); global.manager.load();
manager.enable(); global.manager.enable();
} else { } else {
console.console('§4当前服务器不支持使用MiaoScript插件系统!'); console.console('§4当前服务器不支持使用MiaoScript插件系统!');
} }
} }
// noinspection JSUnusedLocalSymbols // noinspection JSUnusedLocalSymbols
/** /**
* 关闭插件Hook * 关闭插件Hook
*/ */
function disablePlugins() { global.disable = function disable() {
if (manager && manager.$) { if (global.manager && global.manager.$) {
manager.disable(); global.manager.disable();
} }
} }
})(global);