From f79acd43c580a57da4cd6b364a5508e500b92a6d Mon Sep 17 00:00:00 2001 From: coding Date: Sun, 13 May 2018 16:18:14 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0API=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/api/msp.js | 3 ++- src/main/resources/api/plugin.js | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/resources/api/msp.js b/src/main/resources/api/msp.js index bc5cd39..61542f4 100644 --- a/src/main/resources/api/msp.js +++ b/src/main/resources/api/msp.js @@ -9,5 +9,6 @@ exports = module.exports = { permission: impl('permission'), server: impl('server'), task: impl('task'), - item: impl('item') + item: impl('item'), + chat: impl('chat') }; \ No newline at end of file diff --git a/src/main/resources/api/plugin.js b/src/main/resources/api/plugin.js index bcab1c4..15ee171 100644 --- a/src/main/resources/api/plugin.js +++ b/src/main/resources/api/plugin.js @@ -50,14 +50,15 @@ function createUpdate(path) { * @param files */ function loadZipPlugins(files) { - // // TODO ZIP类型插件加载 - // files.filter(function (file) { - // return file.name.endsWith(".zip"); - // }).forEach(function (file) { - // zip.unzip(fs.file(plugins_dir, file)); - // var dir = new File(plugins_dir, file.name.split(".")[0]); - // // TODO 添加文件夹类型的插件兼容 - // }); + files.filter(function (file) { + return file.name.endsWith(".zip"); + }).forEach(function (file) { + // console.log(file); + // console.log(fs.file(file,"!package.json")) + // zip.unzip(fs.file(plugins_dir, file)); + // var dir = new File(plugins_dir, file.name.split(".")[0]); + // TODO 添加文件夹类型的插件兼容 + }); } /** @@ -117,9 +118,9 @@ function beforeLoadHook(origin) { // 处理 event 为了不影响 正常逻辑 event 还是手动require吧 // result = result + 'var event = {}; module.exports.event = event;'; // 注入 console 对象 // 给插件注入单独的 console - result = result + '\nvar console = new Console(); module.exports.console = console;'; + result += '\nvar console = new Console(); module.exports.console = console;'; // 插件注入 self 对象 - result = result + '\nvar self = {}; module.exports.self = self;'; + result += '\nvar self = {}; module.exports.self = self;'; return result; } @@ -189,9 +190,13 @@ function initPluginConfig(plugin) { * @constructor (file, content) */ plugin.saveConfig = function () { + // 判断插件目录是否存在 并且不为文件 否则删除重建 + if (!plugin.configFile.parentFile.isDirectory()) { + fs.del(plugin.configFile.parentFile); + } + plugin.configFile.parentFile.mkdirs(); switch (arguments.length) { case 0: - plugin.configFile.parentFile.mkdirs(); fs.save(plugin.configFile, yaml.safeDump(plugin.config)); break; case 2: @@ -216,10 +221,11 @@ function checkAndGet(args) { if (name && name.description) { return [name]; } - if (!exports.plugins[name]) { + var plugin = exports.plugins[name]; + if (!plugin) { throw new Error("插件 " + name + " 不存在!"); } - return [exports.plugins[name]]; + return [plugin]; } function checkAndRun(args, name, ext) {