feat: update to 0.6.0 rename scope to ccms

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-05-03 00:31:59 +08:00
parent 351183ab3c
commit d0de120867
5 changed files with 41 additions and 24 deletions

View File

@ -1,9 +1,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>MiaoScript</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
<developers>
<developer>
<id>502647092</id>
@ -54,6 +53,7 @@
<properties>
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
<update.changes>
§620-05-02 §afeat: 调整 scope 为 @ccms;
§620-04-10 §afeat: 默认从 classpath 加载内建的js模块;
§620-04-07 §afeat: 默认初始化 内建 nodejs 模块;
§620-04-03 §afeat: 优化 框架卸载逻辑;

View File

@ -1,17 +1,15 @@
'use strict';
var log;
var boot;
var engineDisable;
var global = this;
/**
* Init MiaoScriptEngine Runtime
*/
(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;
@ -30,7 +28,7 @@ var global = this;
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()
};

View File

@ -16,7 +16,7 @@
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')
}
)

View File

@ -25,24 +25,33 @@
* 暂不支持 4. 如果 xx/index.msm 是一个文件 则使用MScript解析器解析 并停止执行
*/
// @ts-check
/// <reference types="@ms/nashorn" />
(
/**
* @param {any} 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;
}