feat: complate deploy feature
This commit is contained in:
		@@ -27,7 +27,7 @@ function request(config: RequestConfig) {
 | 
				
			|||||||
    for (const header in config.headers) {
 | 
					    for (const header in config.headers) {
 | 
				
			||||||
        xhr.setRequestHeader(header, config.headers[header]);
 | 
					        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) {
 | 
					    if ((xhr.getResponseHeader("Content-Type") + '').indexOf('application/json') != -1) {
 | 
				
			||||||
        xhr.responseType = "json"
 | 
					        xhr.responseType = "json"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -151,6 +151,8 @@ export class XMLHttpRequest {
 | 
				
			|||||||
        this._mimeType = mimeType;
 | 
					        this._mimeType = mimeType;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    open(method: RequestMethod, url: string, async: boolean = true, user?: string, password?: string) {
 | 
					    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._method = method;
 | 
				
			||||||
        this._url = url;
 | 
					        this._url = url;
 | 
				
			||||||
        this._async = async;
 | 
					        this._async = async;
 | 
				
			||||||
@@ -195,7 +197,7 @@ export class XMLHttpRequest {
 | 
				
			|||||||
            this.onloadstart();
 | 
					            this.onloadstart();
 | 
				
			||||||
            if (body) {
 | 
					            if (body) {
 | 
				
			||||||
                let bodyType = Object.prototype.toString.call(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();
 | 
					                var out = this._connection.getOutputStream();
 | 
				
			||||||
                out.write(new JavaString(body).getBytes(UTF_8));
 | 
					                out.write(new JavaString(body).getBytes(UTF_8));
 | 
				
			||||||
                out.flush();
 | 
					                out.flush();
 | 
				
			||||||
@@ -204,7 +206,6 @@ export class XMLHttpRequest {
 | 
				
			|||||||
            this.setReadyState(ReadyState.LOADING);
 | 
					            this.setReadyState(ReadyState.LOADING);
 | 
				
			||||||
            this._status = this._connection.getResponseCode();
 | 
					            this._status = this._connection.getResponseCode();
 | 
				
			||||||
            this._statusText = this._connection.getResponseMessage();
 | 
					            this._statusText = this._connection.getResponseMessage();
 | 
				
			||||||
            this.setResponseHeaders(this._connection.getHeaderFields());
 | 
					 | 
				
			||||||
            if (this._status >= 0 && this._status < 300) {
 | 
					            if (this._status >= 0 && this._status < 300) {
 | 
				
			||||||
                this._response = this.readOutput(this._connection.getInputStream());
 | 
					                this._response = this.readOutput(this._connection.getInputStream());
 | 
				
			||||||
            } else if (this._status >= 300 && this._status < 400) {
 | 
					            } else if (this._status >= 300 && this._status < 400) {
 | 
				
			||||||
@@ -212,6 +213,7 @@ export class XMLHttpRequest {
 | 
				
			|||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                this._response = this.readOutput(this._connection.getErrorStream());
 | 
					                this._response = this.readOutput(this._connection.getErrorStream());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            this.setResponseHeaders(this._connection.getHeaderFields());
 | 
				
			||||||
            this.onloadend();
 | 
					            this.onloadend();
 | 
				
			||||||
        } catch (ex) {
 | 
					        } catch (ex) {
 | 
				
			||||||
            if (ex instanceof SocketTimeoutException && this.ontimeout) {
 | 
					            if (ex instanceof SocketTimeoutException && this.ontimeout) {
 | 
				
			||||||
@@ -227,7 +229,6 @@ export class XMLHttpRequest {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private setResponseHeaders(header: any) {
 | 
					    private setResponseHeaders(header: any) {
 | 
				
			||||||
        this._responseHeaders = {};
 | 
					 | 
				
			||||||
        header.forEach((key: string | number, value: string | any[]) => {
 | 
					        header.forEach((key: string | number, value: string | any[]) => {
 | 
				
			||||||
            this._responseHeaders[key] = value[value.length - 1]
 | 
					            this._responseHeaders[key] = value[value.length - 1]
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,9 +21,10 @@ let help = [
 | 
				
			|||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let langMap = {
 | 
					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.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.not.exists': '§6插件 §b{name} §c不存在!',
 | 
				
			||||||
    'plugin.unload.finish': '§6插件 §b{name} §a已卸载!',
 | 
					    'plugin.unload.finish': '§6插件 §b{name} §a已卸载!',
 | 
				
			||||||
    'plugin.reload.finish': '§6插件 §b{name} §a重载完成!',
 | 
					    'plugin.reload.finish': '§6插件 §b{name} §a重载完成!',
 | 
				
			||||||
@@ -35,6 +36,8 @@ let langMap = {
 | 
				
			|||||||
    'download.finish': '§6插件 §b{name} §a下载完毕 开始加载 ...',
 | 
					    'download.finish': '§6插件 §b{name} §a下载完毕 开始加载 ...',
 | 
				
			||||||
    'install.finish': '§6插件 §b{name} §a安装成功!',
 | 
					    'install.finish': '§6插件 §b{name} §a安装成功!',
 | 
				
			||||||
    'update.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
 | 
					let fallbackMap = langMap
 | 
				
			||||||
@@ -57,8 +60,6 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private translate: Translate;
 | 
					    private translate: Translate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private subCommnadNameCache: string[];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    load() {
 | 
					    load() {
 | 
				
			||||||
        this.translate = new Translate({
 | 
					        this.translate = new Translate({
 | 
				
			||||||
            langMap,
 | 
					            langMap,
 | 
				
			||||||
@@ -88,9 +89,9 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    cmdlist(sender: any, type: string = 'cloud') {
 | 
					    cmdlist(sender: any, type: string = 'cloud') {
 | 
				
			||||||
        if (type == "install") {
 | 
					        if (type == "install") {
 | 
				
			||||||
            this.i18n(sender, 'list.header.install')
 | 
					            this.i18n(sender, 'list.install.header')
 | 
				
			||||||
            this.pluginManager.getPlugins().forEach((plugin) => {
 | 
					            this.pluginManager.getPlugins().forEach((plugin) => {
 | 
				
			||||||
                this.i18n(sender, 'list.body', plugin.description);
 | 
					                this.i18n(sender, 'list.install.body', plugin.description);
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            this.i18n(sender, 'list.header')
 | 
					            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) {
 | 
					    cmdunload(sender: any, name: string) {
 | 
				
			||||||
        if (this.checkPlugin(sender, name)) {
 | 
					        if (this.checkPlugin(sender, name)) {
 | 
				
			||||||
            this.pluginManager.disable(name)
 | 
					            this.pluginManager.disable(name)
 | 
				
			||||||
@@ -174,9 +189,9 @@ export class MiaoScriptPackageManager extends interfaces.Plugin {
 | 
				
			|||||||
                    name,
 | 
					                    name,
 | 
				
			||||||
                    author: plugin.description.author,
 | 
					                    author: plugin.description.author,
 | 
				
			||||||
                    version: plugin.description.version,
 | 
					                    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()
 | 
					        }).async().submit()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user