feat: use classpath load core js
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
		
							
								
								
									
										7
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								pom.xml
									
									
									
									
									
								
							@@ -3,7 +3,7 @@
 | 
				
			|||||||
    <modelVersion>4.0.0</modelVersion>
 | 
					    <modelVersion>4.0.0</modelVersion>
 | 
				
			||||||
    <groupId>pw.yumc</groupId>
 | 
					    <groupId>pw.yumc</groupId>
 | 
				
			||||||
    <artifactId>MiaoScript</artifactId>
 | 
					    <artifactId>MiaoScript</artifactId>
 | 
				
			||||||
    <version>0.4.2</version>
 | 
					    <version>0.5.0</version>
 | 
				
			||||||
    <developers>
 | 
					    <developers>
 | 
				
			||||||
        <developer>
 | 
					        <developer>
 | 
				
			||||||
            <id>502647092</id>
 | 
					            <id>502647092</id>
 | 
				
			||||||
@@ -54,6 +54,7 @@
 | 
				
			|||||||
    <properties>
 | 
					    <properties>
 | 
				
			||||||
        <env.GIT_COMMIT>DEV</env.GIT_COMMIT>
 | 
					        <env.GIT_COMMIT>DEV</env.GIT_COMMIT>
 | 
				
			||||||
        <update.changes>
 | 
					        <update.changes>
 | 
				
			||||||
 | 
					            §620-04-10 §afeat: 默认从 classpath 加载内建的js模块;
 | 
				
			||||||
            §620-04-07 §afeat: 默认初始化 内建 nodejs 模块;
 | 
					            §620-04-07 §afeat: 默认初始化 内建 nodejs 模块;
 | 
				
			||||||
            §620-04-03 §afeat: 优化 框架卸载逻辑;
 | 
					            §620-04-03 §afeat: 优化 框架卸载逻辑;
 | 
				
			||||||
            §620-03-31 §afeat: require 新增 内建 nodejs 模块;
 | 
					            §620-03-31 §afeat: require 新增 内建 nodejs 模块;
 | 
				
			||||||
@@ -178,7 +179,7 @@
 | 
				
			|||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
            <groupId>org.spigotmc</groupId>
 | 
					            <groupId>org.spigotmc</groupId>
 | 
				
			||||||
            <artifactId>spigot-api</artifactId>
 | 
					            <artifactId>spigot-api</artifactId>
 | 
				
			||||||
            <version>1.14.4-R0.1-SNAPSHOT</version>
 | 
					            <version>1.15.2-R0.1-SNAPSHOT</version>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
            <groupId>org.spongepowered</groupId>
 | 
					            <groupId>org.spongepowered</groupId>
 | 
				
			||||||
@@ -188,7 +189,7 @@
 | 
				
			|||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
            <groupId>net.md-5</groupId>
 | 
					            <groupId>net.md-5</groupId>
 | 
				
			||||||
            <artifactId>bungeecord-api</artifactId>
 | 
					            <artifactId>bungeecord-api</artifactId>
 | 
				
			||||||
            <version>1.12-SNAPSHOT</version>
 | 
					            <version>1.15-SNAPSHOT</version>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
            <groupId>cn.nukkit</groupId>
 | 
					            <groupId>cn.nukkit</groupId>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,7 @@ public class ScriptEngine {
 | 
				
			|||||||
        if (Files.exists(bios)) {
 | 
					        if (Files.exists(bios)) {
 | 
				
			||||||
            this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')");
 | 
					            this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')");
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            this.engine.eval(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bios.js")));
 | 
					            this.engine.eval("load('classpath:bios.js')");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        engine.invokeFunction("boot", root, logger);
 | 
					        engine.invokeFunction("boot", root, logger);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,7 @@ var global = this;
 | 
				
			|||||||
        log = logger;
 | 
					        log = logger;
 | 
				
			||||||
        // Development Env Detect
 | 
					        // Development Env Detect
 | 
				
			||||||
        root = root || "src/main/resources";
 | 
					        root = root || "src/main/resources";
 | 
				
			||||||
        if (__FILE__ !== "<eval>") {
 | 
					        if (__FILE__.indexOf('!') === -1) {
 | 
				
			||||||
            logger.info('Loading custom BIOS file ' + __FILE__);
 | 
					            logger.info('Loading custom BIOS file ' + __FILE__);
 | 
				
			||||||
            global.debug = true;
 | 
					            global.debug = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -24,14 +24,13 @@ var global = this;
 | 
				
			|||||||
            global.level = base.read(java.nio.file.Paths.get(root, "level"))
 | 
					            global.level = base.read(java.nio.file.Paths.get(root, "level"))
 | 
				
			||||||
            logger.info('Set system level to [' + global.level + ']...');
 | 
					            logger.info('Set system level to [' + global.level + ']...');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Check Class Loader, Sometimes Server will can't find plugin.yml file
 | 
					        // Check Class Loader, Sometimes Server will can't found plugin.yml file
 | 
				
			||||||
        loader = checkClassLoader();
 | 
					        loader = checkClassLoader();
 | 
				
			||||||
        // Force decompression core|node_modules to folder when not debug mode
 | 
					 | 
				
			||||||
        release(root, '(core)+/.*', !global.debug);
 | 
					 | 
				
			||||||
        // Async Loading MiaoScript Engine
 | 
					        // Async Loading MiaoScript Engine
 | 
				
			||||||
        new java.lang.Thread(function() {
 | 
					        new java.lang.Thread(function() {
 | 
				
			||||||
            load(root + '/core/ployfill.js')(root, logger);
 | 
					            java.lang.Thread.currentThread().contextClassLoader = loader;
 | 
				
			||||||
            engineDisable = require('@ms/core').default;
 | 
					            load('classpath:core/ployfill.js')(root, logger);
 | 
				
			||||||
 | 
					            engineDisable = require('@ms/core').default || function() { logger.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...') };
 | 
				
			||||||
        }, "MiaoScript thread").start()
 | 
					        }, "MiaoScript thread").start()
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -49,30 +48,4 @@ var global = this;
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return classLoader;
 | 
					        return classLoader;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    function release(root, regex, replace) {
 | 
					 | 
				
			||||||
        var filePath = pluginYml.getFile().substring(pluginYml.getFile().indexOf("/") + 1);
 | 
					 | 
				
			||||||
        var jarPath = java.net.URLDecoder.decode(filePath.substring(0, filePath.indexOf('!')));
 | 
					 | 
				
			||||||
        if (!java.nio.file.Files.exists(java.nio.file.Paths.get(jarPath))) {
 | 
					 | 
				
			||||||
            jarPath = "/" + jarPath;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        var jar = new java.util.jar.JarFile(jarPath);
 | 
					 | 
				
			||||||
        var r = new RegExp(regex);
 | 
					 | 
				
			||||||
        jar.stream().forEach(function(entry) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                if (!entry.isDirectory()) {
 | 
					 | 
				
			||||||
                    if (r.test(entry.name)) {
 | 
					 | 
				
			||||||
                        var path = java.nio.file.Paths.get(root, entry.name);
 | 
					 | 
				
			||||||
                        var parentFile = path.toFile().parentFile;
 | 
					 | 
				
			||||||
                        if (!parentFile.exists()) { parentFile.mkdirs(); }
 | 
					 | 
				
			||||||
                        if (!java.nio.file.Files.exists(path) || replace) {
 | 
					 | 
				
			||||||
                            java.nio.file.Files.copy(loader.getResourceAsStream(entry.name), path, java.nio.file.StandardCopyOption['REPLACE_EXISTING']);
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            } catch (ex) {
 | 
					 | 
				
			||||||
                ex.printStackTrace();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
})();
 | 
					})();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,10 +13,10 @@
 | 
				
			|||||||
        global.load = load = function __PreventGlobalLoadFunction__() { throw new Error('Internal engine system not allow use `load` 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
 | 
					        // Init console and require
 | 
				
			||||||
        global.console = engineLoad(global.root + '/core/console.js')(logger);
 | 
					        global.console = engineLoad('classpath:core/console.js')(logger);
 | 
				
			||||||
        console.log("Loading Engine at Thread", java.lang.Thread.currentThread().name)
 | 
					        console.log("Loading Engine at Thread", java.lang.Thread.currentThread().name)
 | 
				
			||||||
        global.require = engineLoad(global.root + '/core/require.js')(root);
 | 
					        global.require = engineLoad('classpath:core/require.js')(root);
 | 
				
			||||||
        require('@ms/ployfill')
 | 
					        require('@ms/ployfill')
 | 
				
			||||||
        require('@ms/nodejs')
 | 
					        require('@ms/nodejs')
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
);
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -382,6 +382,17 @@
 | 
				
			|||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					            require.disable = function __DynamicDisable__() {
 | 
				
			||||||
 | 
					                for (var cacheModule in cacheModules) {
 | 
				
			||||||
 | 
					                    delete cacheModules[cacheModule]
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                cacheModules = undefined;
 | 
				
			||||||
 | 
					                for (var cacheModule in cacheModuleIds) {
 | 
				
			||||||
 | 
					                    delete cacheModuleIds[cacheModule]
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                cacheModuleIds = undefined;
 | 
				
			||||||
 | 
					                notFoundModules = undefined;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            return require;
 | 
					            return require;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ name: ${project.artifactId}
 | 
				
			|||||||
description: ${project.description}
 | 
					description: ${project.description}
 | 
				
			||||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
 | 
					main: ${project.groupId}.${project.artifactId}.${project.artifactId}
 | 
				
			||||||
version: ${project.version}
 | 
					version: ${project.version}
 | 
				
			||||||
 | 
					api-version: 1.13
 | 
				
			||||||
author: MiaoWoo
 | 
					author: MiaoWoo
 | 
				
			||||||
website: ${ciManagement.url}
 | 
					website: ${ciManagement.url}
 | 
				
			||||||
load: STARTUP
 | 
					load: STARTUP
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user