@ -137,14 +137,15 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdupgrade(sender: any, name: string) {
|
cmdupgrade(sender: any, name: string, confirm: boolean) {
|
||||||
if (!name) { return this.i18n(sender, 'upgrade.confirm') }
|
if (name == "system") {
|
||||||
if (name == "comfirm") {
|
if (!confirm) { return this.i18n(sender, 'upgrade.confirm') }
|
||||||
let enginePath = fs.path(fs.file(fs.concat(root, 'node_modules', '@ccms')))
|
let enginePath = fs.path(fs.file(root, 'node_modules'))
|
||||||
if (enginePath.startsWith(root)) {
|
if (enginePath.startsWith(root)) {
|
||||||
base.delete(enginePath)
|
base.delete(enginePath)
|
||||||
this.cmdrestart(sender)
|
this.cmdrestart(sender)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if (this.checkPlugin(sender, name)) {
|
if (this.checkPlugin(sender, name)) {
|
||||||
this.update(sender, name)
|
this.update(sender, name)
|
||||||
@ -241,7 +242,7 @@ return '§a返回结果: §r'+ eval(${JSON.stringify(code)});`)
|
|||||||
name,
|
name,
|
||||||
author: plugin.description.author,
|
author: plugin.description.author,
|
||||||
version: plugin.description.version,
|
version: plugin.description.version,
|
||||||
source: base.read(plugin.description.source.toString())
|
source: base.read((plugin.description.source || plugin.description.loadMetadata.file).toString())
|
||||||
})
|
})
|
||||||
this.i18n(sender, result.code == 200 ? 'deploy.success' : 'deploy.fail', { name, msg: result.msg })
|
this.i18n(sender, result.code == 200 ? 'deploy.success' : 'deploy.fail', { name, msg: result.msg })
|
||||||
}
|
}
|
||||||
@ -263,8 +264,11 @@ return '§a返回结果: §r'+ eval(${JSON.stringify(code)});`)
|
|||||||
return ["install", "cloud"]
|
return ["install", "cloud"]
|
||||||
case "install":
|
case "install":
|
||||||
return this.packageNameCache
|
return this.packageNameCache
|
||||||
case "update":
|
|
||||||
case "upgrade":
|
case "upgrade":
|
||||||
|
if (args.length == 2) return ["system", ...this.pluginManager.getPlugins().keys()]
|
||||||
|
if (args.length == 3 && args[1] == "system") return ["confirm"]
|
||||||
|
return []
|
||||||
|
case "update":
|
||||||
case "load":
|
case "load":
|
||||||
case "unload":
|
case "unload":
|
||||||
case "reload":
|
case "reload":
|
||||||
|
@ -5,12 +5,47 @@ import { constants, database, plugin, web } from "@ccms/api"
|
|||||||
import { inject, ContainerInstance, Container, JSClass, postConstruct } from "@ccms/container"
|
import { inject, ContainerInstance, Container, JSClass, postConstruct } from "@ccms/container"
|
||||||
import { JSPlugin, interfaces, cmd } from "@ccms/plugin"
|
import { JSPlugin, interfaces, cmd } from "@ccms/plugin"
|
||||||
import { DataBase, DataBaseManager } from '@ccms/database'
|
import { DataBase, DataBaseManager } from '@ccms/database'
|
||||||
import { Server, Context, RequestHandler, Controller, Get, Post, Param, Body } from '@ccms/web'
|
import { Server, Context, RequestHandler, Controllers, Controller, Get, Post, Param, Body } from '@ccms/web'
|
||||||
|
|
||||||
import * as fs from '@ccms/common/dist/fs'
|
import * as fs from '@ccms/common/dist/fs'
|
||||||
import * as reflect from '@ccms/common/dist/reflect'
|
import * as reflect from '@ccms/common/dist/reflect'
|
||||||
|
|
||||||
@JSPlugin({ name: 'MiaoSpring', prefix: 'MSpring', version: '1.0.1', author: 'MiaoWoo', servers: [constants.ServerType.Spring], source: __filename })
|
@Controller()
|
||||||
|
class PluginController {
|
||||||
|
@inject(plugin.PluginManager)
|
||||||
|
private pluginManager: plugin.PluginManager
|
||||||
|
@inject(database.DataBaseManager)
|
||||||
|
private databaseManager: DataBaseManager
|
||||||
|
|
||||||
|
private mainDB: DataBase
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
initialize() {
|
||||||
|
this.mainDB = this.databaseManager.getMainDatabase()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
list(@Param('install') install: boolean) {
|
||||||
|
if (install) {
|
||||||
|
return { status: 200, data: [...this.pluginManager.getPlugins().values()].map((plugin) => plugin.description), msg: '插件列表获取成功!' }
|
||||||
|
} else {
|
||||||
|
return { status: 200, data: this.mainDB.query<Plugin>("SELECT name FROM plugins WHERE deleted = 0") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Post()
|
||||||
|
deploy(@Body() info: Plugin) {
|
||||||
|
let plugin = this.mainDB.query<Plugin>("SELECT name FROM plugins WHERE name = ?", info.name)
|
||||||
|
if (plugin.length == 0) {
|
||||||
|
this.mainDB.update("INSERT INTO `plugins`(`name`, `source`) VALUES (?, ?)", info.name, info.source)
|
||||||
|
return { status: 200, msg: `插件 ${info.name} 新增成功!` }
|
||||||
|
} else {
|
||||||
|
this.mainDB.update("UPDATE `plugins` SET `source` = ? WHERE id = ?", info.source, plugin[0].id)
|
||||||
|
return { status: 200, msg: `插件 ${info.name} 更新成功!` }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JSPlugin({ author: 'MiaoWoo', servers: [constants.ServerType.Spring], source: __filename })
|
||||||
export class MiaoSpring extends interfaces.Plugin {
|
export class MiaoSpring extends interfaces.Plugin {
|
||||||
@inject(ContainerInstance)
|
@inject(ContainerInstance)
|
||||||
private container: Container
|
private container: Container
|
||||||
@ -40,6 +75,7 @@ export class MiaoSpring extends interfaces.Plugin {
|
|||||||
this.mappings = new Set()
|
this.mappings = new Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Controllers(PluginController)
|
||||||
enable() {
|
enable() {
|
||||||
this.registryDefault()
|
this.registryDefault()
|
||||||
this.registryPages()
|
this.registryPages()
|
||||||
@ -173,6 +209,7 @@ export class MiaoSpring extends interfaces.Plugin {
|
|||||||
'pluginManager'
|
'pluginManager'
|
||||||
]
|
]
|
||||||
let params = [
|
let params = [
|
||||||
|
base.getInstance().getAutowireCapableBeanFactory(),
|
||||||
this.mainDatabase,
|
this.mainDatabase,
|
||||||
reflect,
|
reflect,
|
||||||
this.container,
|
this.container,
|
||||||
@ -187,6 +224,8 @@ return eval(${JSON.stringify(code)});`)
|
|||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
Object.keys(this.mappings).forEach((r) => this.webServer.unregistryMapping(r))
|
Object.keys(this.mappings).forEach((r) => this.webServer.unregistryMapping(r))
|
||||||
|
this.webServer.unregistryInterceptor({ name: 'RedirectHandle' })
|
||||||
|
this.webServer.unregistryInterceptor({ name: 'StaticHandle' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,38 +234,3 @@ class Plugin {
|
|||||||
name: string
|
name: string
|
||||||
source: string
|
source: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@Controller()
|
|
||||||
class PluginController {
|
|
||||||
@inject(plugin.PluginManager)
|
|
||||||
private pluginManager: plugin.PluginManager
|
|
||||||
@inject(database.DataBaseManager)
|
|
||||||
private databaseManager: DataBaseManager
|
|
||||||
|
|
||||||
private mainDB: DataBase
|
|
||||||
|
|
||||||
@postConstruct()
|
|
||||||
initialize() {
|
|
||||||
this.mainDB = this.databaseManager.getMainDatabase()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
list(@Param('install') install: boolean) {
|
|
||||||
if (install) {
|
|
||||||
return { status: 200, data: [...this.pluginManager.getPlugins().values()].map((plugin) => plugin.description), msg: '插件列表获取成功!' }
|
|
||||||
} else {
|
|
||||||
return { status: 200, data: this.mainDB.query<Plugin>("SELECT name FROM plugins WHERE deleted = 0") }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Post()
|
|
||||||
deploy(@Body() info: Plugin) {
|
|
||||||
let plugin = this.mainDB.query<Plugin>("SELECT name FROM plugins WHERE name = ?", info.name)
|
|
||||||
if (plugin.length == 0) {
|
|
||||||
this.mainDB.update("INSERT INTO `plugins`(`name`, `source`) VALUES (?, ?)", info.name, info.source)
|
|
||||||
return { status: 200, msg: `插件 ${info.name} 新增成功!` }
|
|
||||||
} else {
|
|
||||||
this.mainDB.update("UPDATE `plugins` SET `source` = ? WHERE id = ?", info.source, plugin[0].id)
|
|
||||||
return { status: 200, msg: `插件 ${info.name} 更新成功!` }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,21 +1,6 @@
|
|||||||
import { constants, web } from "@ccms/api"
|
import { constants } from "@ccms/api"
|
||||||
import { inject } from "@ccms/container"
|
|
||||||
import { plugin, interfaces } from "@ccms/plugin"
|
import { plugin, interfaces } from "@ccms/plugin"
|
||||||
import { Controller, Get, Server, Body, Post, Cookie, Header, Param } from "@ccms/web"
|
import { Controllers, Controller, Get, Body, Post, Cookie, Header, Param } from "@ccms/web"
|
||||||
|
|
||||||
@plugin({ name: 'MiaoWeb', version: '1.0.0', author: 'MiaoWoo', servers: [constants.ServerType.Spring], source: __filename })
|
|
||||||
export class MiaoWeb extends interfaces.Plugin {
|
|
||||||
@inject(web.Server)
|
|
||||||
private webServer: Server
|
|
||||||
|
|
||||||
enable() {
|
|
||||||
this.webServer.registryController(TestController)
|
|
||||||
}
|
|
||||||
|
|
||||||
disable() {
|
|
||||||
this.webServer.unregistryController(TestController)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class TestController {
|
export class TestController {
|
||||||
@ -37,3 +22,10 @@ export class TestController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@plugin({ author: 'MiaoWoo', servers: [constants.ServerType.Spring], source: __filename })
|
||||||
|
export class MiaoWeb extends interfaces.Plugin {
|
||||||
|
@Controllers(TestController)
|
||||||
|
enable() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user