feat: complate deploy feature

This commit is contained in:
MiaoWoo 2020-05-08 00:50:30 +08:00
parent 1931391cba
commit 7d63a57991
3 changed files with 28 additions and 12 deletions

View File

@ -27,7 +27,7 @@ function request(config: RequestConfig) {
for (const header in config.headers) {
xhr.setRequestHeader(header, config.headers[header]);
}
xhr.send(config.data);
xhr.send(typeof config.data === "string" ? config.data : JSON.stringify(config.data));
if ((xhr.getResponseHeader("Content-Type") + '').indexOf('application/json') != -1) {
xhr.responseType = "json"
}

View File

@ -151,6 +151,8 @@ export class XMLHttpRequest {
this._mimeType = mimeType;
}
open(method: RequestMethod, url: string, async: boolean = true, user?: string, password?: string) {
if (this._readyState !== ReadyState.UNSENT) { throw new Error(`Error Status ${this._readyState}!`) }
this._method = method;
this._url = url;
this._async = async;
@ -195,7 +197,7 @@ export class XMLHttpRequest {
this.onloadstart();
if (body) {
let bodyType = Object.prototype.toString.call(body);
if (bodyType !== '[object String]') { throw new Error(`body(${bodyType}) must be string!`) }
if (typeof body !== "string") { throw new Error(`body(${bodyType}) must be string!`) }
var out = this._connection.getOutputStream();
out.write(new JavaString(body).getBytes(UTF_8));
out.flush();
@ -204,7 +206,6 @@ export class XMLHttpRequest {
this.setReadyState(ReadyState.LOADING);
this._status = this._connection.getResponseCode();
this._statusText = this._connection.getResponseMessage();
this.setResponseHeaders(this._connection.getHeaderFields());
if (this._status >= 0 && this._status < 300) {
this._response = this.readOutput(this._connection.getInputStream());
} else if (this._status >= 300 && this._status < 400) {
@ -212,6 +213,7 @@ export class XMLHttpRequest {
} else {
this._response = this.readOutput(this._connection.getErrorStream());
}
this.setResponseHeaders(this._connection.getHeaderFields());
this.onloadend();
} catch (ex) {
if (ex instanceof SocketTimeoutException && this.ontimeout) {
@ -227,7 +229,6 @@ export class XMLHttpRequest {
}
private setResponseHeaders(header: any) {
this._responseHeaders = {};
header.forEach((key: string | number, value: string | any[]) => {
this._responseHeaders[key] = value[value.length - 1]
});

View File

@ -21,9 +21,10 @@ let help = [
];
let langMap = {
'list.header.install': '§6当前 §bMiaoScript §6已安装下列插件:',
'list.install.header': '§6当前 §bMiaoScript §6已安装下列插件:',
'list.install.body': '§6插件名称: §b{name} §6版本: §a{version} §6作者: §3{author}',
'list.header': '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:',
'list.body': '§6插件名称: §b{name} §6版本: §a{version} §6作者: §3{author}',
'list.body': '§6插件名称: §b{name} §6版本: §a{version} §6作者: §3{author} §6更新时间: §9{updated_at}',
'plugin.not.exists': '§6插件 §b{name} §c不存在!',
'plugin.unload.finish': '§6插件 §b{name} §a已卸载!',
'plugin.reload.finish': '§6插件 §b{name} §a重载完成!',
@ -35,6 +36,8 @@ let langMap = {
'download.finish': '§6插件 §b{name} §a下载完毕 开始加载 ...',
'install.finish': '§6插件 §b{name} §a安装成功!',
'update.finish': '§6插件 §b{name} §a更新成功!',
'deploy.success': '§6插件 §b{name} §a发布成功! §6服务器返回: §a{msg}',
'deploy.fail': '§6插件 §b{name} §c发布失败! §6服务器返回: §c{msg}',
}
let fallbackMap = langMap
@ -57,8 +60,6 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
private translate: Translate;
private subCommnadNameCache: string[];
load() {
this.translate = new Translate({
langMap,
@ -88,9 +89,9 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
cmdlist(sender: any, type: string = 'cloud') {
if (type == "install") {
this.i18n(sender, 'list.header.install')
this.i18n(sender, 'list.install.header')
this.pluginManager.getPlugins().forEach((plugin) => {
this.i18n(sender, 'list.body', plugin.description);
this.i18n(sender, 'list.install.body', plugin.description);
})
} else {
this.i18n(sender, 'list.header')
@ -113,6 +114,20 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
}
}
cmdupgrade(sender: any, name: string) {
if (name == "system") {
let enginePath = fs.path(fs.file(fs.concat(root, 'node_modules', '@ccms')))
if (enginePath.startsWith(root)) {
base.delete(enginePath);
this.cmdrestart(sender);
}
}
if (this.checkPlugin(sender, name)) {
this.update(sender, name);
this.pluginManager.reload(name);
}
}
cmdunload(sender: any, name: string) {
if (this.checkPlugin(sender, name)) {
this.pluginManager.disable(name)
@ -174,9 +189,9 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
name,
author: plugin.description.author,
version: plugin.description.version,
source: base.read(plugin.description.source + '')
source: base.read(plugin.description.source.toString())
})
this.logger.sender(sender, result);
this.i18n(sender, result.code == 200 ? 'deploy.success' : 'deploy.fail', { name, msg: result.msg })
}
}).async().submit()
}