esa-cli 0.0.1-beta.9 → 0.0.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/bin/enter.cjs +0 -1
- package/dist/README.md +4 -6
- package/dist/bin/enter.cjs +0 -1
- package/dist/commands/commit/index.js +2 -2
- package/dist/commands/deploy/index.js +4 -2
- package/dist/commands/deployments/list.js +2 -1
- package/dist/commands/dev/build.js +57 -0
- package/dist/commands/dev/doProcess.js +10 -2
- package/dist/commands/dev/ew2/devEntry.js +9 -0
- package/dist/commands/dev/ew2/devPack.js +185 -0
- package/dist/commands/dev/ew2/mock/cache.js +32 -0
- package/dist/commands/dev/ew2/mock/kv.js +45 -0
- package/dist/commands/dev/ew2/server.js +234 -0
- package/dist/commands/dev/index.js +111 -49
- package/dist/commands/dev/{config → mockWorker}/devEntry.js +3 -2
- package/dist/commands/dev/{devPack.js → mockWorker/devPack.js} +10 -8
- package/dist/commands/dev/{server.js → mockWorker/server.js} +43 -37
- package/dist/commands/init/index.js +117 -42
- package/dist/commands/login/index.js +2 -2
- package/dist/commands/logout.js +0 -4
- package/dist/commands/route/list.js +2 -1
- package/dist/commands/routine/list.js +6 -4
- package/dist/components/mutiLevelSelect.js +69 -0
- package/dist/i18n/locales.json +120 -4
- package/dist/index.js +8 -0
- package/dist/libs/api.js +155 -0
- package/dist/libs/logger.js +42 -31
- package/dist/libs/service.js +178 -0
- package/dist/package.json +13 -5
- package/dist/utils/checkDevPort.js +19 -14
- package/dist/utils/checkOS.js +32 -0
- package/dist/utils/fileMd5.js +18 -0
- package/dist/utils/fileUtils/index.js +1 -1
- package/dist/utils/install/installEw2.sh +33 -0
- package/dist/utils/{installRuntime.js → installDeno.js} +15 -15
- package/dist/utils/installEw2.js +127 -0
- package/dist/utils/stepsRunner.js +33 -0
- package/dist/zh_CN.md +4 -5
- package/package.json +13 -5
- package/dist/commands/dev/config/devBuild.js +0 -26
- package/dist/libs/request.js +0 -98
- /package/dist/commands/dev/{config → mockWorker}/mock/cache.js +0 -0
- /package/dist/commands/dev/{config → mockWorker}/mock/kv.js +0 -0
package/dist/i18n/locales.json
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"zh_CN": "代码上传成功。"
|
|
29
29
|
},
|
|
30
30
|
"commit_success": {
|
|
31
|
-
"en": "
|
|
31
|
+
"en": "Generate code version success!",
|
|
32
32
|
"zh_CN": "代码版本提交成功。"
|
|
33
33
|
},
|
|
34
34
|
"commit_fail": {
|
|
@@ -481,7 +481,7 @@
|
|
|
481
481
|
},
|
|
482
482
|
"install_runtime_tip": {
|
|
483
483
|
"en": "🔔 Runtime must be installed to use esa dev. Installing...",
|
|
484
|
-
"zh_CN": "
|
|
484
|
+
"zh_CN": "必须安装Runtime才能使用 esa dev。正在安装..."
|
|
485
485
|
},
|
|
486
486
|
"install_runtime_success": {
|
|
487
487
|
"en": "Runtime installed.",
|
|
@@ -604,7 +604,7 @@
|
|
|
604
604
|
"zh_CN": "然后就可以用新的端口在Chrome inspect中调试了😉"
|
|
605
605
|
},
|
|
606
606
|
"dev_port_used": {
|
|
607
|
-
"en": "Port ${
|
|
607
|
+
"en": "Port ${stringPort} already in use.",
|
|
608
608
|
"zh_CN": "端口 ${stringDenoPort} 被占用"
|
|
609
609
|
},
|
|
610
610
|
"dev_port_used_ask": {
|
|
@@ -628,7 +628,7 @@
|
|
|
628
628
|
"zh_CN": "可以使用 ${option} 指定另外的端口"
|
|
629
629
|
},
|
|
630
630
|
"dev_inspect_port_used": {
|
|
631
|
-
"en": "Inspect port ${stringInspectPort} already in use",
|
|
631
|
+
"en": "Inspect port ${stringInspectPort} already in use.",
|
|
632
632
|
"zh_CN": "Inspect 端口 ${stringInspectPort} 已被占用"
|
|
633
633
|
},
|
|
634
634
|
"dev_inspect_port_used_ask": {
|
|
@@ -778,5 +778,121 @@
|
|
|
778
778
|
"init_build_project_success": {
|
|
779
779
|
"en": "Project built successfully.",
|
|
780
780
|
"zh_CN": "项目构建成功。"
|
|
781
|
+
},
|
|
782
|
+
"dev_server_start": {
|
|
783
|
+
"en": "Dev server starting...",
|
|
784
|
+
"zh_CN": "Dev 服务启动中..."
|
|
785
|
+
},
|
|
786
|
+
"dev_server_started": {
|
|
787
|
+
"en": "Dev server started successfully",
|
|
788
|
+
"zh_CN": "Dev 服务已启动"
|
|
789
|
+
},
|
|
790
|
+
"dev_checking_runtime": {
|
|
791
|
+
"en": "Checking runtime",
|
|
792
|
+
"zh_CN": "检查运行时环境"
|
|
793
|
+
},
|
|
794
|
+
"dev_process_fail": {
|
|
795
|
+
"en": "Dev server start failed.",
|
|
796
|
+
"zh_CN": "Dev 服务启动失败"
|
|
797
|
+
},
|
|
798
|
+
"dev_worker_timeout": {
|
|
799
|
+
"en": "Worker start timeout",
|
|
800
|
+
"zh_CN": "Worker 启动超时"
|
|
801
|
+
},
|
|
802
|
+
"upload_code_failed": {
|
|
803
|
+
"en": "An error occurred while trying to upload the code.",
|
|
804
|
+
"zh_CN": "上传代码时发生错误。"
|
|
805
|
+
},
|
|
806
|
+
"oss_config_not_found": {
|
|
807
|
+
"en": "Failed to retrieve OSS configuration information.",
|
|
808
|
+
"zh_CN": "无法获取OSS配置信息。"
|
|
809
|
+
},
|
|
810
|
+
"oss_upload_failed": {
|
|
811
|
+
"en": "Failed to upload to OSS",
|
|
812
|
+
"zh_CN": "上传到OSS失败"
|
|
813
|
+
},
|
|
814
|
+
"publish_success": {
|
|
815
|
+
"en": "Publish success!",
|
|
816
|
+
"zh_CN": "发布成功!"
|
|
817
|
+
},
|
|
818
|
+
"start_quick_deploy": {
|
|
819
|
+
"en": "Starting quick deploy...",
|
|
820
|
+
"zh_CN": "开始快速部署..."
|
|
821
|
+
},
|
|
822
|
+
"upload_oss_success": {
|
|
823
|
+
"en": "Upload code success!",
|
|
824
|
+
"zh_CN": "上传代码成功!"
|
|
825
|
+
},
|
|
826
|
+
"upload_code": {
|
|
827
|
+
"en": "Uploading code...",
|
|
828
|
+
"zh_CN": "正在上传代码..."
|
|
829
|
+
},
|
|
830
|
+
"commit_code": {
|
|
831
|
+
"en": "Generating code version...",
|
|
832
|
+
"zh_CN": "生成代码版本..."
|
|
833
|
+
},
|
|
834
|
+
"publish_code": {
|
|
835
|
+
"en": "Publishing code to production environment...",
|
|
836
|
+
"zh_CN": "正在将代码发布到生产环境..."
|
|
837
|
+
},
|
|
838
|
+
"init_update_info": {
|
|
839
|
+
"en": "Updating template...",
|
|
840
|
+
"zh_CN": "模版更新中..."
|
|
841
|
+
},
|
|
842
|
+
"init_update_success": {
|
|
843
|
+
"en": "Template update complete.",
|
|
844
|
+
"zh_CN": "模版更新完成"
|
|
845
|
+
},
|
|
846
|
+
"exit_select_init_template": {
|
|
847
|
+
"en": "Exit",
|
|
848
|
+
"zh_CN": "退出"
|
|
849
|
+
},
|
|
850
|
+
"return_select_init_template": {
|
|
851
|
+
"en": "Return",
|
|
852
|
+
"zh_CN": "返回"
|
|
853
|
+
},
|
|
854
|
+
"display_current_esa_template_version": {
|
|
855
|
+
"en": "Current esa-template version:",
|
|
856
|
+
"zh_CN": "当前esa-template版本:"
|
|
857
|
+
},
|
|
858
|
+
"display_latest_esa_template_version": {
|
|
859
|
+
"en": "Latest esa-template version:",
|
|
860
|
+
"zh_CN": "最新esa-template版本:"
|
|
861
|
+
},
|
|
862
|
+
"is_update_to_latest_version": {
|
|
863
|
+
"en": "Do you want to update templates to latest version?",
|
|
864
|
+
"zh_CN": "是否更新模版到最新版本?"
|
|
865
|
+
},
|
|
866
|
+
"updating_esa_template_to_latest_version": {
|
|
867
|
+
"en": "Updating ${packageName} to the latest version...",
|
|
868
|
+
"zh_CN": "更新 ${packageName} 到最新版本..."
|
|
869
|
+
},
|
|
870
|
+
"updated_esa_template_to_latest_version": {
|
|
871
|
+
"en": "${packageName} updated successfully",
|
|
872
|
+
"zh_CN": "${packageName} 更新完成!"
|
|
873
|
+
},
|
|
874
|
+
"esa_template_is_latest_version": {
|
|
875
|
+
"en": "${packageName} is latest.",
|
|
876
|
+
"zh_CN": "${packageName} 已是最新版本."
|
|
877
|
+
},
|
|
878
|
+
"not_login_auto_deploy": {
|
|
879
|
+
"en": "You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.",
|
|
880
|
+
"zh_CN": "因为您未登陆,不能自动部署。请稍后登陆后,手动进行部署"
|
|
881
|
+
},
|
|
882
|
+
"dev_option_debugger": {
|
|
883
|
+
"en": "Output debug logs",
|
|
884
|
+
"zh_CN": "输出debug日志"
|
|
885
|
+
},
|
|
886
|
+
"install_runtime_update_tip": {
|
|
887
|
+
"en": "🔔 Runtime must be update to use esa dev. Installing...",
|
|
888
|
+
"zh_CN": "必须更新Runtime才能使用 esa dev。正在安装..."
|
|
889
|
+
},
|
|
890
|
+
"dev_ip_not_allowed": {
|
|
891
|
+
"en": "Direct access to IP addresses is not allowed when setting local-upstream: ${url}",
|
|
892
|
+
"zh_CN": "不允许直接设置 local-upstream 为 IP 地址:${url}"
|
|
893
|
+
},
|
|
894
|
+
"dev_url_invalid": {
|
|
895
|
+
"en": "Invalid URL: ${url}. Please enter a valid URL.",
|
|
896
|
+
"zh_CN": "不是正确的URL: ${url}. 请输入正确的URL."
|
|
781
897
|
}
|
|
782
898
|
}
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import { getCliConfig } from './utils/fileUtils/index.js';
|
|
|
26
26
|
import { handleCheckVersion } from './utils/checkVersion.js';
|
|
27
27
|
import t from './i18n/index.js';
|
|
28
28
|
import site from './commands/site/index.js';
|
|
29
|
+
import { quickDeployRoutine } from './libs/service.js';
|
|
29
30
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
31
|
const argv = hideBin(process.argv);
|
|
31
32
|
const cliConfig = getCliConfig();
|
|
@@ -73,6 +74,13 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
73
74
|
esa.command(logout);
|
|
74
75
|
esa.command(config);
|
|
75
76
|
esa.command(lang);
|
|
77
|
+
esa.command('t', false, () => { }, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
const res = yield quickDeployRoutine({
|
|
79
|
+
name: 'test',
|
|
80
|
+
code: 'test'
|
|
81
|
+
});
|
|
82
|
+
// console.log(res);
|
|
83
|
+
}));
|
|
76
84
|
esa.group(['help', 'version'], 'Options:');
|
|
77
85
|
esa.parse();
|
|
78
86
|
});
|
package/dist/libs/api.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import ESA, * as $ESA from '@alicloud/esa20240910';
|
|
11
|
+
import * as $OpenApi from '@alicloud/openapi-client';
|
|
12
|
+
import * as $Util from '@alicloud/tea-util';
|
|
13
|
+
import { getApiConfig } from '../utils/fileUtils/index.js';
|
|
14
|
+
import logger from './logger.js';
|
|
15
|
+
class Client {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.callApi = (action, request) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
logger.info(`Called api ${action.name}, Request: ${request ? JSON.stringify(request) : 'no request'}`);
|
|
20
|
+
const runtime = new $Util.RuntimeOptions({
|
|
21
|
+
connectTimeout: 10000,
|
|
22
|
+
readTimeout: 10000,
|
|
23
|
+
autoretry: true,
|
|
24
|
+
maxAttempts: 3
|
|
25
|
+
});
|
|
26
|
+
const response = request
|
|
27
|
+
? yield action(request, runtime)
|
|
28
|
+
: yield action(runtime);
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const err = error;
|
|
33
|
+
logger.error(`Code: ${err.code}, Message: ${err.message}}`);
|
|
34
|
+
logger.debug(`Data: ${JSON.stringify(err.data)}`);
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
this.callOpenApi = (apiName, requestParams) => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
logger.info(`Called api ${apiName} with openApi, Request: ${requestParams ? JSON.stringify(requestParams) : 'no request'}`);
|
|
40
|
+
try {
|
|
41
|
+
let params = {
|
|
42
|
+
action: apiName,
|
|
43
|
+
version: '2024-09-10',
|
|
44
|
+
protocol: 'https',
|
|
45
|
+
method: 'GET',
|
|
46
|
+
authType: 'AK',
|
|
47
|
+
bodyType: 'json',
|
|
48
|
+
reqBodyType: 'json',
|
|
49
|
+
style: 'RPC',
|
|
50
|
+
pathname: '/',
|
|
51
|
+
toMap: function () {
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const request = new $OpenApi.OpenApiRequest(requestParams);
|
|
56
|
+
const runtime = new $Util.RuntimeOptions({
|
|
57
|
+
connectTimeout: 10000,
|
|
58
|
+
readTimeout: 10000,
|
|
59
|
+
autoretry: true,
|
|
60
|
+
maxAttempts: 3
|
|
61
|
+
});
|
|
62
|
+
const response = yield this.client.callApi(params, request, runtime);
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const err = error;
|
|
67
|
+
logger.error(`Code: ${err.code}, Message: ${err.message}}`);
|
|
68
|
+
logger.debug(`Data: ${JSON.stringify(err.data)}`);
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const config = getApiConfig();
|
|
73
|
+
this.client = Client.createClient(config);
|
|
74
|
+
}
|
|
75
|
+
static createClient(config) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
const apiConfig = new $OpenApi.Config({
|
|
78
|
+
accessKeyId: (_a = config.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
79
|
+
accessKeySecret: (_b = config.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
|
|
80
|
+
endpoint: config.endpoint
|
|
81
|
+
});
|
|
82
|
+
return new ESA.default(apiConfig);
|
|
83
|
+
}
|
|
84
|
+
updateConfig(config) {
|
|
85
|
+
this.client = Client.createClient(config);
|
|
86
|
+
}
|
|
87
|
+
getErService() {
|
|
88
|
+
const request = new $ESA.GetErServiceRequest({});
|
|
89
|
+
return this.callApi(this.client.getErServiceWithOptions.bind(this.client), request);
|
|
90
|
+
}
|
|
91
|
+
getRoutineStagingCodeUploadInfo(params) {
|
|
92
|
+
const request = new $ESA.GetRoutineStagingCodeUploadInfoRequest(params);
|
|
93
|
+
return this.callApi(this.client.getRoutineStagingCodeUploadInfoWithOptions.bind(this.client), request);
|
|
94
|
+
}
|
|
95
|
+
commitRoutineStagingCode(params) {
|
|
96
|
+
const request = new $ESA.CommitRoutineStagingCodeRequest(params);
|
|
97
|
+
return this.callApi(this.client.commitRoutineStagingCodeWithOptions.bind(this.client), request);
|
|
98
|
+
}
|
|
99
|
+
publishRoutineCodeVersion(params) {
|
|
100
|
+
const request = new $ESA.PublishRoutineCodeVersionRequest(params);
|
|
101
|
+
return this.callApi(this.client.publishRoutineCodeVersionWithOptions.bind(this.client), request);
|
|
102
|
+
}
|
|
103
|
+
getMatchSite(params) {
|
|
104
|
+
return this.callOpenApi('getMatchSite', params);
|
|
105
|
+
}
|
|
106
|
+
listRoutineCanaryAreas() {
|
|
107
|
+
return this.callApi(this.client.listRoutineCanaryAreasWithOptions.bind(this.client));
|
|
108
|
+
}
|
|
109
|
+
getRoutineUserInfo() {
|
|
110
|
+
return this.callApi(this.client.getRoutineUserInfoWithOptions.bind(this.client));
|
|
111
|
+
}
|
|
112
|
+
deleteRoutine(params) {
|
|
113
|
+
const request = new $ESA.DeleteRoutineRequest(params);
|
|
114
|
+
return this.callApi(this.client.deleteRoutineWithOptions.bind(this.client), request);
|
|
115
|
+
}
|
|
116
|
+
deleteRoutineCodeVersion(params) {
|
|
117
|
+
const request = new $ESA.DeleteRoutineCodeVersionRequest(params);
|
|
118
|
+
return this.callApi(this.client.deleteRoutineCodeVersionWithOptions.bind(this.client), request);
|
|
119
|
+
}
|
|
120
|
+
createRoutineRelatedRoute(params) {
|
|
121
|
+
const request = new $ESA.CreateRoutineRelatedRouteRequest(params);
|
|
122
|
+
return this.callApi(this.client.createRoutineRelatedRouteWithOptions.bind(this.client), request);
|
|
123
|
+
}
|
|
124
|
+
deleteRoutineRelatedRoute(params) {
|
|
125
|
+
const request = new $ESA.DeleteRoutineRelatedRouteRequest(params);
|
|
126
|
+
return this.callApi(this.client.deleteRoutineRelatedRouteWithOptions.bind(this.client), request);
|
|
127
|
+
}
|
|
128
|
+
listSites(params) {
|
|
129
|
+
const request = new $ESA.ListSitesRequest(params);
|
|
130
|
+
return this.callApi(this.client.listSitesWithOptions.bind(this.client), request);
|
|
131
|
+
}
|
|
132
|
+
getRoutineStagingEnvIp() {
|
|
133
|
+
return this.callApi(this.client.getRoutineStagingEnvIpWithOptions.bind(this.client));
|
|
134
|
+
}
|
|
135
|
+
getRoutine(params) {
|
|
136
|
+
const request = new $ESA.GetRoutineRequest(params);
|
|
137
|
+
return this.callApi(this.client.getRoutineWithOptions.bind(this.client), request);
|
|
138
|
+
}
|
|
139
|
+
createRoutine(params) {
|
|
140
|
+
const request = new $ESA.CreateRoutineRequest(params);
|
|
141
|
+
return this.callApi(this.client.createRoutineWithOptions.bind(this.client), request);
|
|
142
|
+
}
|
|
143
|
+
listRoutineOptionalSpecs() {
|
|
144
|
+
return this.callApi(this.client.listRoutineOptionalSpecsWithOptions.bind(this.client));
|
|
145
|
+
}
|
|
146
|
+
createRoutineRelatedRecord(params) {
|
|
147
|
+
const request = new $ESA.CreateRoutineRelatedRecordRequest(params);
|
|
148
|
+
return this.callApi(this.client.createRoutineRelatedRecordWithOptions.bind(this.client), request);
|
|
149
|
+
}
|
|
150
|
+
deleteRoutineRelatedRecord(params) {
|
|
151
|
+
const request = new $ESA.DeleteRoutineRelatedRecordRequest(params);
|
|
152
|
+
return this.callApi(this.client.deleteRoutineRelatedRecordWithOptions.bind(this.client), request);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export default new Client();
|
package/dist/libs/logger.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { format, createLogger
|
|
2
|
+
import { format, createLogger } from 'winston';
|
|
3
|
+
import DailyRotateFile from 'winston-daily-rotate-file';
|
|
3
4
|
import Table from 'cli-table3';
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import os from 'os';
|
|
6
7
|
import ora from 'ora';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
8
|
import t from '../i18n/index.js';
|
|
9
|
-
|
|
9
|
+
import { getProjectConfig } from '../utils/fileUtils/index.js';
|
|
10
|
+
const transport = new DailyRotateFile({
|
|
11
|
+
filename: path.join(os.homedir(), '.esa-logs/esa-debug-%DATE%.log'),
|
|
12
|
+
level: 'info',
|
|
13
|
+
datePattern: 'YYYY-MM-DD-HH:mm:ss',
|
|
14
|
+
zippedArchive: true,
|
|
15
|
+
maxSize: '10m',
|
|
16
|
+
maxFiles: '7d'
|
|
17
|
+
});
|
|
10
18
|
class Logger {
|
|
11
19
|
constructor() {
|
|
12
20
|
const { combine, timestamp, label, printf } = format;
|
|
13
21
|
const customFormat = printf(({ level, message, label: printLabel, timestamp: printTimestamp }) => {
|
|
22
|
+
var _a;
|
|
14
23
|
let colorizedLevel;
|
|
24
|
+
const projName = ((_a = getProjectConfig()) === null || _a === void 0 ? void 0 : _a.name) || 'Outside';
|
|
15
25
|
switch (level) {
|
|
26
|
+
case 'warn':
|
|
27
|
+
colorizedLevel = chalk.yellow(level);
|
|
28
|
+
break;
|
|
29
|
+
case 'info':
|
|
30
|
+
colorizedLevel = chalk.green(level);
|
|
31
|
+
break;
|
|
16
32
|
case 'error':
|
|
17
|
-
colorizedLevel = chalk.
|
|
18
|
-
return `❌ ${colorizedLevel} ${chalk.red(message)}`;
|
|
33
|
+
colorizedLevel = chalk.red(level);
|
|
19
34
|
case 'verbose':
|
|
20
35
|
colorizedLevel = chalk.magenta(level);
|
|
21
36
|
break;
|
|
@@ -28,18 +43,12 @@ class Logger {
|
|
|
28
43
|
default:
|
|
29
44
|
colorizedLevel = level;
|
|
30
45
|
}
|
|
31
|
-
return `${printTimestamp} [${chalk.green(printLabel)}] ${colorizedLevel}: ${message}`;
|
|
46
|
+
return `${printTimestamp} [${chalk.green(printLabel)}] ${colorizedLevel} in ${chalk.italic(projName)}: ${message}`;
|
|
32
47
|
});
|
|
33
48
|
this.logger = createLogger({
|
|
34
49
|
level: 'info',
|
|
35
|
-
format: combine(label({ label: '
|
|
36
|
-
transports: [
|
|
37
|
-
new transports.Console(),
|
|
38
|
-
new transports.File({
|
|
39
|
-
filename: path.join(os.homedir(), '.asea-logs/esa-debug.log'),
|
|
40
|
-
level: 'error'
|
|
41
|
-
})
|
|
42
|
-
]
|
|
50
|
+
format: combine(label({ label: 'ESA' }), timestamp(), customFormat),
|
|
51
|
+
transports: [transport]
|
|
43
52
|
});
|
|
44
53
|
this.spinner = ora('Loading...');
|
|
45
54
|
}
|
|
@@ -63,13 +72,16 @@ class Logger {
|
|
|
63
72
|
console.log(`\t${message}`);
|
|
64
73
|
}
|
|
65
74
|
success(message) {
|
|
66
|
-
console.log(
|
|
75
|
+
console.log(`\n🎉 ${chalk.bgGreen(' SUCCESS ')} ${chalk.green(message)}`);
|
|
67
76
|
}
|
|
68
77
|
debug(message) {
|
|
69
78
|
this.logger.debug(message);
|
|
79
|
+
if (this.logger.level === 'debug') {
|
|
80
|
+
console.log(`${chalk.grey('[DEBUG]')} ${message}`);
|
|
81
|
+
}
|
|
70
82
|
}
|
|
71
83
|
info(message) {
|
|
72
|
-
|
|
84
|
+
this.logger.info(message);
|
|
73
85
|
}
|
|
74
86
|
ask(message) {
|
|
75
87
|
console.log(`❓ ${message}`);
|
|
@@ -78,16 +90,18 @@ class Logger {
|
|
|
78
90
|
console.log(`👉🏻 ${chalk.green(message)}`);
|
|
79
91
|
}
|
|
80
92
|
block() {
|
|
81
|
-
console.log('
|
|
93
|
+
console.log('\n');
|
|
82
94
|
}
|
|
83
95
|
warn(message) {
|
|
84
|
-
|
|
96
|
+
this.logger.warn(message);
|
|
97
|
+
console.log(`\n${chalk.bgYellow(' WARNING ')} ${chalk.yellow(message)}`);
|
|
85
98
|
}
|
|
86
99
|
error(message) {
|
|
87
100
|
this.logger.error(message);
|
|
101
|
+
console.log(`\n❌ ${chalk.bgRed(' ERROR ')} ${chalk.red(message)}`);
|
|
88
102
|
}
|
|
89
103
|
subError(message) {
|
|
90
|
-
console.log(
|
|
104
|
+
console.log(`\n${chalk.red(message)}`);
|
|
91
105
|
}
|
|
92
106
|
http(message) {
|
|
93
107
|
this.logger.http(message);
|
|
@@ -107,7 +121,7 @@ class Logger {
|
|
|
107
121
|
}
|
|
108
122
|
notInProject() {
|
|
109
123
|
const initCommand = chalk.green('esa init');
|
|
110
|
-
this.
|
|
124
|
+
this.error(t('common_not_edge_project', { initCommand }).d(`You are not in an esa project, Please run ${initCommand} to initialize a project, or enter an esa project.`));
|
|
111
125
|
}
|
|
112
126
|
pathEacces(localPath) {
|
|
113
127
|
this.block();
|
|
@@ -119,9 +133,10 @@ class Logger {
|
|
|
119
133
|
this.block();
|
|
120
134
|
this.log(chalk.green(`$ sudo chmod -R 777 ${localPath}`));
|
|
121
135
|
}
|
|
122
|
-
table(head, data) {
|
|
136
|
+
table(head, data, width = []) {
|
|
123
137
|
const table = new Table({
|
|
124
|
-
head
|
|
138
|
+
head,
|
|
139
|
+
colWidths: width
|
|
125
140
|
});
|
|
126
141
|
table.push(...data);
|
|
127
142
|
this.log(table.toString());
|
|
@@ -130,19 +145,15 @@ class Logger {
|
|
|
130
145
|
tree(messages) {
|
|
131
146
|
if (messages.length === 0)
|
|
132
147
|
return;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
console.log(`╭─ ${messages[0]}`);
|
|
148
|
+
const lines = [];
|
|
149
|
+
lines.push(`╭─ ${messages[0]}`);
|
|
138
150
|
for (let i = 1; i < messages.length - 1; i++) {
|
|
139
|
-
|
|
140
|
-
console.log(`├─ ${messages[i]}`);
|
|
151
|
+
lines.push(`│ ${messages[i]}`);
|
|
141
152
|
}
|
|
142
153
|
if (messages.length > 1) {
|
|
143
|
-
|
|
144
|
-
console.log(`╰─ ${messages[messages.length - 1]}`);
|
|
154
|
+
lines.push(`╰─ ${messages[messages.length - 1]}`);
|
|
145
155
|
}
|
|
156
|
+
console.log(lines.join('\n'));
|
|
146
157
|
}
|
|
147
158
|
}
|
|
148
159
|
const logger = Logger.getInstance();
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import ora from 'ora';
|
|
11
|
+
import chain from 'lodash';
|
|
12
|
+
import FormData from 'form-data';
|
|
13
|
+
import fetch from 'node-fetch';
|
|
14
|
+
import t from '../i18n/index.js';
|
|
15
|
+
import api from './api.js';
|
|
16
|
+
import { Environment } from './interface.js';
|
|
17
|
+
import logger from './logger.js';
|
|
18
|
+
export const checkLogin = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const result = new ServiceOutput();
|
|
20
|
+
try {
|
|
21
|
+
const response = yield api.getErService();
|
|
22
|
+
if (response.statusCode === 200) {
|
|
23
|
+
result.success = true;
|
|
24
|
+
result.message = t('login_success').d('Login success!');
|
|
25
|
+
}
|
|
26
|
+
else if (response.statusCode === 403) {
|
|
27
|
+
result.message = t('login_permission_denied').d('Permission denied: Access key or secret is incorrect, or does not have the necessary permissions.');
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
result.message = `${t('common_error_occurred').d('An error occurred')}: ${response.statusCode}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
result.message = t('login_failed').d('An error occurred while trying to log in.');
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
});
|
|
38
|
+
const commonUploadCodeError = t('upload_code_failed').d('An error occurred while trying to upload the code.');
|
|
39
|
+
export const getRoutineStagingCodeUploadInfo = (edgeRoutine) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const result = new ServiceOutput();
|
|
41
|
+
let ossConfig;
|
|
42
|
+
try {
|
|
43
|
+
const uploadResult = yield api.getRoutineStagingCodeUploadInfo({
|
|
44
|
+
name: edgeRoutine.name
|
|
45
|
+
});
|
|
46
|
+
ossConfig = chain(uploadResult).get('body.OssPostConfig');
|
|
47
|
+
if (!ossConfig) {
|
|
48
|
+
result.message = t('oss_config_not_found').d('Failed to retrieve OSS configuration information.');
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
result.message = commonUploadCodeError;
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const { OSSAccessKeyId, Signature, callback, Url, key, policy } = ossConfig;
|
|
58
|
+
const formData = new FormData();
|
|
59
|
+
formData.append('OSSAccessKeyId', OSSAccessKeyId);
|
|
60
|
+
formData.append('Signature', Signature);
|
|
61
|
+
formData.append('callback', callback);
|
|
62
|
+
formData.append('x:codeDescription', ossConfig['x:codeDescription']);
|
|
63
|
+
formData.append('policy', policy);
|
|
64
|
+
formData.append('key', key);
|
|
65
|
+
formData.append('file', edgeRoutine.code);
|
|
66
|
+
const ossRes = yield fetch(Url, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
body: formData,
|
|
69
|
+
headers: formData.getHeaders()
|
|
70
|
+
});
|
|
71
|
+
if (ossRes && ossRes.status === 200) {
|
|
72
|
+
result.success = true;
|
|
73
|
+
result.message = t('upload_oss_success').d('Upload code success!');
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
logger.error(`${t('oss_upload_failed').d('Failed to upload to OSS')}: ${ossRes.status}, ${ossRes.statusText}}`);
|
|
77
|
+
result.message = commonUploadCodeError;
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const err = error;
|
|
83
|
+
logger.error(err.message);
|
|
84
|
+
result.message = commonUploadCodeError;
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
export const commitRoutineStagingCode = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const result = new ServiceOutput();
|
|
90
|
+
try {
|
|
91
|
+
const res = yield api.commitRoutineStagingCode(params);
|
|
92
|
+
if (res.statusCode === 200 && res.body) {
|
|
93
|
+
result.success = true;
|
|
94
|
+
result.message = t('commit_success').d('Generate code version success!');
|
|
95
|
+
result.data = {
|
|
96
|
+
code: res.statusCode,
|
|
97
|
+
data: {
|
|
98
|
+
RequestId: res.body.RequestId,
|
|
99
|
+
CodeVersion: res.body.CodeVersion
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
result.message = commonUploadCodeError;
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const publishRoutineCodeVersion = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const result = new ServiceOutput();
|
|
112
|
+
try {
|
|
113
|
+
const res = yield api.publishRoutineCodeVersion(params);
|
|
114
|
+
if (res.statusCode === 200 && res.body) {
|
|
115
|
+
result.success = true;
|
|
116
|
+
result.message = t('publish_success').d('Publish success!');
|
|
117
|
+
result.data = {
|
|
118
|
+
code: res.statusCode,
|
|
119
|
+
data: {
|
|
120
|
+
CodeVersion: res.body.CodeVersion,
|
|
121
|
+
RequestId: res.body.RequestId
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
result.message = commonUploadCodeError;
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
export const quickDeployRoutine = (edgeRoutineProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const result = new ServiceOutput();
|
|
134
|
+
result.success = true;
|
|
135
|
+
const steps = [
|
|
136
|
+
{
|
|
137
|
+
action: () => getRoutineStagingCodeUploadInfo(edgeRoutineProps),
|
|
138
|
+
message: t('upload_code').d('Uploading code...')
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
action: () => commitRoutineStagingCode({
|
|
142
|
+
name: edgeRoutineProps.name,
|
|
143
|
+
codeDescription: edgeRoutineProps.description
|
|
144
|
+
}),
|
|
145
|
+
message: t('commit_code').d('Generating code version...')
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
action: () => publishRoutineCodeVersion({
|
|
149
|
+
Name: edgeRoutineProps.name,
|
|
150
|
+
CodeVersion: '',
|
|
151
|
+
Env: Environment.Staging
|
|
152
|
+
}),
|
|
153
|
+
message: t('publish_code').d('Publishing code to production environment...')
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
const spinner = ora(t('start_quick_deploy').d('Starting quick deploy...')).start();
|
|
157
|
+
for (const step of steps) {
|
|
158
|
+
spinner.text = step.message;
|
|
159
|
+
const stepRes = yield step.action();
|
|
160
|
+
if (stepRes.success) {
|
|
161
|
+
spinner.succeed(stepRes.message);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
result.success = false;
|
|
165
|
+
spinner.fail('Error: ' + stepRes.message);
|
|
166
|
+
result.message = stepRes.message;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
});
|
|
172
|
+
export class ServiceOutput {
|
|
173
|
+
constructor() {
|
|
174
|
+
this.success = false;
|
|
175
|
+
this.message = '';
|
|
176
|
+
this.data = {};
|
|
177
|
+
}
|
|
178
|
+
}
|