diff --git a/src/main/resources/core/fs.js b/src/main/resources/core/fs.js index ae23099..27c2c08 100644 --- a/src/main/resources/core/fs.js +++ b/src/main/resources/core/fs.js @@ -45,19 +45,19 @@ function file() { * 创建目录 * @param file */ -function mkdirs(file) { +function mkdirs(path) { // noinspection JSUnresolvedVariable - file.parentFile.mkdirs(); + fs.file(path).parentFile.mkdirs(); }; /** * 创建文件 * @param file */ -function create(file) { - f = file(file); - if (!f.exists()) { - mkdirs(f); - f.createNewFile(); +function create(path) { + var file = fs.file(path) + if (!file.exists()) { + mkdirs(file); + file.createNewFile(); } }; /** @@ -67,7 +67,7 @@ function create(file) { */ function path(file) { // noinspection JSUnresolvedVariable - return file.canonicalPath; + return fs.file(file).canonicalPath; }; /** * 复制文件 @@ -80,10 +80,10 @@ function copy(inputStream, target, override) { }; /** * 读取文件 - * @param file 文件路径 + * @param path 文件路径 */ -function read(f) { - var file = exports.file(f); +function read(path) { + var file = fs.file(path); if (!file.exists()) { console.warn('读取文件', file, '错误 文件不存在!'); return; @@ -98,9 +98,9 @@ function read(f) { * @param override 是否覆盖 */ function save(path, content, override) { - var f = file(path); - f.getParentFile().mkdirs(); - Files.write(f.toPath(), new java.lang.String(content).getBytes("UTF-8")); + var file = fs.file(path); + file.getParentFile().mkdirs(); + Files.write(file.toPath(), new java.lang.String(content).getBytes("UTF-8")); }; /** * 列出目录文件 @@ -121,12 +121,12 @@ function list(path) { * @param override 是否覆盖 */ function move(src, des, override) { - Files.move(file(src).toPath(), file(des).toPath(), + Files.move(fs.file(src).toPath(), fs.file(des).toPath(), override ? StandardCopyOption['REPLACE_EXISTING'] : StandardCopyOption['ATOMIC_MOVE']) }; function del(file) { - file = exports.file(file); + file = fs.file(file); if (!file.exists()) { return; } if (file.isDirectory()) { Files.list(file.toPath()).collect(Collectors.toList()).forEach(function (f) { del(f); }) @@ -134,17 +134,25 @@ function del(file) { Files.delete(file.toPath()); } -exports = module.exports = { - canonical: path, +function exists(file) { + return fs.file(file).exists() +} + +var fs = {}; + +fs.path = fs.canonical = fs.realpath = path +fs.write = fs.save = save +fs.readdir = fs.list = list +fs.rename = fs.move = move + +Object.assign(fs, { concat: concat, create: create, mkdirs: mkdirs, file: file, - path: path, copy: copy, read: read, - save: save, - list: list, - move: move, del: del -} \ No newline at end of file +}) + +exports = module.exports = fs \ No newline at end of file diff --git a/src/main/resources/core/init.js b/src/main/resources/core/init.js index 3ab460d..949b813 100644 --- a/src/main/resources/core/init.js +++ b/src/main/resources/core/init.js @@ -8,7 +8,7 @@ global.noop = function () { }; loadCore(); - loadExt(); + loadPatch(); loadRequire(); try { loadServerLib(); @@ -49,8 +49,8 @@ /** * 加载补丁 */ - function loadExt() { - java.nio.file.Files.list(new java.io.File(root, 'core/ext').toPath()).forEach(function (path) { + function loadPatch() { + java.nio.file.Files.list(new java.io.File(root, 'core/patch').toPath()).forEach(function (path) { console.log('加载扩展类库', path); try { load(path.toFile()); diff --git a/src/main/resources/core/ext/Array.js b/src/main/resources/core/patch/Array.js similarity index 84% rename from src/main/resources/core/ext/Array.js rename to src/main/resources/core/patch/Array.js index 4e00aa5..0c9f12a 100644 --- a/src/main/resources/core/ext/Array.js +++ b/src/main/resources/core/patch/Array.js @@ -7,7 +7,7 @@ enumerable: false, value: function (token, array) { this.forEach(function (e) { - if (e.startsWith(token)) { + if (e.toLowerCase().startsWith(token.toLowerCase())) { array.push(e) } }) diff --git a/src/main/resources/core/ext/Date.js b/src/main/resources/core/patch/Date.js similarity index 100% rename from src/main/resources/core/ext/Date.js rename to src/main/resources/core/patch/Date.js diff --git a/src/main/resources/core/ext/Object.js b/src/main/resources/core/patch/Object.js similarity index 100% rename from src/main/resources/core/ext/Object.js rename to src/main/resources/core/patch/Object.js diff --git a/src/main/resources/core/ext/String.js b/src/main/resources/core/patch/String.js similarity index 100% rename from src/main/resources/core/ext/String.js rename to src/main/resources/core/patch/String.js