From d0de120867125a5bcb6a310bedd062de7d7b3370 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sun, 3 May 2020 00:31:59 +0800 Subject: [PATCH] feat: update to 0.6.0 rename scope to ccms Signed-off-by: MiaoWoo --- pom.xml | 6 +++--- src/main/resources/bios.js | 16 +++++++--------- src/main/resources/core/console.js | 4 ++-- src/main/resources/core/ployfill.js | 10 +++++----- src/main/resources/core/require.js | 29 ++++++++++++++++++++++++----- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 0c3ebf1..eb27782 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,8 @@ - + 4.0.0 pw.yumc MiaoScript - 0.5.0 + 0.6.0 502647092 @@ -54,6 +53,7 @@ DEV + §620-05-02 §afeat: 调整 scope 为 @ccms; §620-04-10 §afeat: 默认从 classpath 加载内建的js模块; §620-04-07 §afeat: 默认初始化 内建 nodejs 模块; §620-04-03 §afeat: 优化 框架卸载逻辑; diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index 528bf08..1c6e42b 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -1,17 +1,15 @@ 'use strict'; -var log; -var boot; -var engineDisable; var global = this; /** * Init MiaoScriptEngine Runtime */ -(function() { +(function () { var loader; - boot = function(root, logger) { - log = logger; + global.boot = function (root, logger) { + global.scope = "@ccms"; + global.log = logger; // Development Env Detect - root = root || "src/main/resources"; + global.root = root || "src/main/resources"; if (__FILE__.indexOf('!') === -1) { logger.info('Loading custom BIOS file ' + __FILE__); global.debug = true; @@ -27,10 +25,10 @@ var global = this; // Check Class Loader, Sometimes Server will can't found plugin.yml file loader = checkClassLoader(); // Async Loading MiaoScript Engine - new java.lang.Thread(function() { + new java.lang.Thread(function () { java.lang.Thread.currentThread().contextClassLoader = loader; load('classpath:core/ployfill.js')(root, logger); - engineDisable = require('@ms/core').default || function() { logger.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...') }; + global.engineDisable = require(global.scope + '/core').default || function () { logger.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...') }; }, "MiaoScript thread").start() }; diff --git a/src/main/resources/core/console.js b/src/main/resources/core/console.js index 6fbc862..63fd6a7 100644 --- a/src/main/resources/core/console.js +++ b/src/main/resources/core/console.js @@ -3,7 +3,7 @@ /** * @param {{ info: (arg0: string) => void; }} logger */ - function(logger) { + function (logger) { function log() { logger.info(Array.prototype.join.call(arguments, ' ')) } @@ -11,7 +11,7 @@ * @param {string} prefix */ function _proxy(prefix) { - return function() { + return function () { log('[' + prefix + ']', Array.prototype.join.call(arguments, ' ')) } } diff --git a/src/main/resources/core/ployfill.js b/src/main/resources/core/ployfill.js index 48b7b03..725fe9d 100644 --- a/src/main/resources/core/ployfill.js +++ b/src/main/resources/core/ployfill.js @@ -3,20 +3,20 @@ * @param {string} root * @param {any} logger */ - function(root, logger) { + function (root, logger) { // Init Global Value global.root = root; global.logger = logger; global.NashornEngineStartTime = new Date().getTime() global.engineLoad = load; - global.noop = global.engineDisable = engineDisable = function() { }; + global.noop = global.engineDisable = engineDisable = function () { }; global.load = load = function __PreventGlobalLoadFunction__() { throw new Error('Internal engine system not allow use `load` function!'); } - global.setGlobal = function(key, value) { global[key] = value; }; + global.setGlobal = function (key, value) { global[key] = value; }; // Init console and require global.console = engineLoad('classpath:core/console.js')(logger); console.log("Loading Engine at Thread", java.lang.Thread.currentThread().name) global.require = engineLoad('classpath:core/require.js')(root); - require('@ms/ployfill') - require('@ms/nodejs') + require(global.scope + '/ployfill') + require(global.scope + '/nodejs') } ) diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js index c47d1fd..bae9a97 100644 --- a/src/main/resources/core/require.js +++ b/src/main/resources/core/require.js @@ -25,24 +25,33 @@ * 暂不支持 4. 如果 xx/index.msm 是一个文件 则使用MScript解析器解析 并停止执行 */ // @ts-check -/// ( /** * @param {any} parent */ - function(parent) { + function (parent) { 'use strict'; + // @ts-ignore var File = Java.type('java.io.File'); + // @ts-ignore var Paths = Java.type('java.nio.file.Paths'); + // @ts-ignore var Files = Java.type('java.nio.file.Files'); + // @ts-ignore var StandardCopyOption = Java.type('java.nio.file.StandardCopyOption'); + // @ts-ignore var FileNotFoundException = Java.type('java.io.FileNotFoundException'); + // @ts-ignore var TarInputStream = Java.type('org.kamranzafar.jtar.TarInputStream'); + // @ts-ignore var GZIPInputStream = Java.type('java.util.zip.GZIPInputStream'); + // @ts-ignore var BufferedInputStream = Java.type('java.io.BufferedInputStream'); + // @ts-ignore var URL = Java.type('java.net.URL') + // @ts-ignore var JavaString = Java.type('java.lang.String') var separatorChar = File.separatorChar; @@ -258,9 +267,10 @@ * @param {string} name 包名称 */ function download(name) { - // handle name es6-map/implement => es6-map @ms/common/dist/reflect => @ms/common + // handle name es6-map/implement => es6-map @ccms/common/dist/reflect => @ccms/common var name_arr = name.split('/'); var module_name = name.startsWith('@') ? name_arr[0] + '/' + name_arr[1] : name_arr[0]; + // @ts-ignore var target = root + separatorChar + 'node_modules' + separatorChar + module_name; var _package = new File(target, 'package.json'); if (_package.exists()) { return } @@ -279,6 +289,9 @@ return name; } + /** + * @param {string} module_name + */ function fetchPackageInfo(module_name) { var tempFile = Files.createTempFile(module_name.replace('/', '_'), '.json'); try { @@ -291,17 +304,23 @@ return JSON.parse(new JavaString(Files.readAllBytes(tempFile), 'UTF-8')); } + var lastModule = '' /** * 检查核心模块 * @param {string} name */ function checkCoreModule(name, path) { + if (name.startsWith('@ms') && lastModule.endsWith('.js')) { + console.warn(lastModule + ' load deprecated module ' + name + ' auto replace to ' + name.replace('@ms', '@ccms') + '...') + } else { + lastModule = name + } if (CoreModules.indexOf(name) != -1) { - var newName = '@ms/nodejs/dist/' + name + var newName = '@ccms/nodejs/dist/' + name if (resolve(newName, path) !== undefined) { return newName; } - throw new Error("Can't load nodejs core module " + name + " . maybe later will auto replace to @ms/nodejs/" + name + ' to compatible...') + throw new Error("Can't load nodejs core module " + name + " . maybe later will auto replace to @ccms/nodejs/" + name + ' to compatible...') } return name; }