feat: remove global initialize

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2022-04-04 05:13:24 +08:00
parent 16ab108186
commit a5cb084767
2 changed files with 41 additions and 25 deletions

View File

@ -1,14 +1,13 @@
function upgradeModules(core) {
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
var Paths = Java.type('java.nio.file.Paths')
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
console.info('@ccms/core found new version ' + core['dist-tags']['latest'] + ' will upgrade after reboot!')
}
}
function exit() {
var http = require('@ccms/common/dist/http').default
function upgradeModules(core) {
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
var Paths = Java.type('java.nio.file.Paths')
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
console.info('@ccms/core found new version ' + core['dist-tags']['latest'] + ' will upgrade after reboot!')
}
}
upgradeModules(http.get('https://registry.npmmirror.com/@ccms/core'))
console.debug('exit finish!')
}
exit()

View File

@ -1,22 +1,34 @@
var fs = require('@ccms/common/dist/fs')
function updateJar() {
if (!base.version) {
var pluginFolder = fs.file(fs.concat(root, '..'))
var updateFolder = fs.concat(pluginFolder, 'update')
}
}
function upgradeModules(core) {
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
var Paths = Java.type('java.nio.file.Paths')
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
console.info('@ccms/core found new version ' + core['dist-tags']['latest'] + ' will upgrade after reboot!')
}
}
function initialize() {
global.initialize = function () {
var mspmc = 'https://ms.yumc.pw/api/plugin/download/name/'
var artifact = 'https://ci.yumc.pw/job/Minecraft/job/MiaoScript/lastSuccessfulBuild/artifact'
var fs = require('@ccms/common/dist/fs')
var http = require('@ccms/common/dist/http').default
function updateJar() {
var DocumentBuilderFactory = Java.type('javax.xml.parsers.DocumentBuilderFactory')
var URLDecoder = Java.type('java.net.URLDecoder')
var pom = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(artifact + "/pom.xml")
var latestVersion = pom.getElementsByTagName("version").item(0).getTextContent()
if (base.version != latestVersion) {
var pluginFolder = fs.file(fs.concat(root, '..'))
var updateFolder = fs.concat(pluginFolder, 'update')
fs.mkdirs(updateFolder)
var filePath = base.getInstance().class.classLoader.getURLs()[0]
var pluginFile = fs.file(URLDecoder.decode(filePath.getFile(), "UTF-8"))
var updateFile = fs.file(updateFolder, pluginFile.getName())
http.download(artifact + "/target/MiaoScript.jar", updateFile.getAbsolutePath())
console.info('MiaoScript found new version ' + latestVersion + ' will upgrade after reboot!')
}
}
function upgradeModules(core) {
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
var Paths = Java.type('java.nio.file.Paths')
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
console.info('@ccms/core found new version ' + core['dist-tags']['latest'] + ' will upgrade after reboot!')
}
}
var pluginFolder = fs.concat(root, 'plugins')
var updateFolder = fs.concat(pluginFolder, 'update')
var pluginFile = fs.concat(pluginFolder, 'MiaoScriptPackageManager.js')
@ -43,9 +55,14 @@ function initialize() {
try {
Java.type("org.bukkit.Bukkit")
updateJar()
} catch (ignore) {
} catch (error) {
console.debug(error)
if (global.debug) {
console.ex(error)
}
}
upgradeModules(http.get('https://registry.npmmirror.com/@ccms/core'))
console.debug('initialize finish!')
}
initialize()
global.initialize()
delete global.initialize