esa-cli 0.0.2-beta.1 → 0.0.2-beta.12
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/dist/commands/commit/index.js +34 -25
- package/dist/commands/common/constant.js +0 -19
- package/dist/commands/deploy/helper.js +10 -26
- package/dist/commands/deploy/index.js +49 -60
- package/dist/commands/deployments/delete.js +1 -16
- package/dist/commands/deployments/index.js +1 -1
- package/dist/commands/deployments/list.js +8 -15
- package/dist/commands/dev/ew2/cacheService.js +33 -0
- package/dist/commands/dev/ew2/devEntry.js +2 -1
- package/dist/commands/dev/ew2/devPack.js +13 -26
- package/dist/commands/dev/ew2/kvService.js +27 -0
- package/dist/commands/dev/ew2/mock/cache.js +99 -15
- package/dist/commands/dev/ew2/mock/kv.js +142 -21
- package/dist/commands/dev/ew2/server.js +152 -19
- package/dist/commands/dev/index.js +4 -4
- package/dist/commands/dev/mockWorker/devPack.js +16 -14
- package/dist/commands/domain/add.js +1 -1
- package/dist/commands/domain/delete.js +4 -4
- package/dist/commands/domain/index.js +1 -1
- package/dist/commands/domain/list.js +3 -3
- package/dist/commands/init/helper.js +137 -0
- package/dist/commands/init/index.js +183 -187
- package/dist/commands/login/index.js +49 -3
- package/dist/commands/logout.js +1 -1
- package/dist/commands/route/add.js +50 -52
- package/dist/commands/route/delete.js +29 -23
- package/dist/commands/route/helper.js +124 -0
- package/dist/commands/route/index.js +1 -1
- package/dist/commands/route/list.js +53 -14
- package/dist/commands/routine/index.js +1 -1
- package/dist/commands/routine/list.js +4 -5
- package/dist/commands/site/index.js +1 -1
- package/dist/commands/utils.js +5 -5
- package/dist/components/mutiLevelSelect.js +44 -55
- package/dist/docs/Commands_en.md +27 -13
- package/dist/docs/Commands_zh_CN.md +14 -0
- package/dist/docs/Dev_en.md +0 -0
- package/dist/docs/Dev_zh_CN.md +0 -0
- package/dist/i18n/locales.json +144 -12
- package/dist/index.js +6 -9
- package/dist/libs/api.js +32 -9
- package/dist/libs/apiService.js +88 -78
- package/dist/libs/interface.js +0 -1
- package/dist/libs/logger.js +1 -1
- package/dist/libs/templates/index.js +2 -1
- package/dist/utils/checkIsRoutineCreated.js +7 -12
- package/dist/utils/checkVersion.js +1 -1
- package/dist/utils/download.js +182 -0
- package/dist/utils/fileUtils/base.js +1 -1
- package/dist/utils/installDeno.js +7 -7
- package/package.json +5 -5
package/dist/libs/apiService.js
CHANGED
|
@@ -12,7 +12,6 @@ import FormData from 'form-data';
|
|
|
12
12
|
import fetch from 'node-fetch';
|
|
13
13
|
import { Environment } from './interface.js';
|
|
14
14
|
import { getApiConfig } from '../utils/fileUtils/index.js';
|
|
15
|
-
import chain from 'lodash';
|
|
16
15
|
import t from '../i18n/index.js';
|
|
17
16
|
export class ApiService {
|
|
18
17
|
constructor(cliConfig) {
|
|
@@ -130,7 +129,6 @@ export class ApiService {
|
|
|
130
129
|
}
|
|
131
130
|
publishRoutineCodeVersion(requestParams) {
|
|
132
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
var _a;
|
|
134
132
|
try {
|
|
135
133
|
let params = {
|
|
136
134
|
action: 'PublishRoutineCodeVersion',
|
|
@@ -146,15 +144,11 @@ export class ApiService {
|
|
|
146
144
|
return this;
|
|
147
145
|
}
|
|
148
146
|
};
|
|
149
|
-
const CanaryAreaList = (_a = requestParams.CanaryAreaList) !== null && _a !== void 0 ? _a : [];
|
|
150
|
-
const CanaryAreaListString = JSON.stringify(CanaryAreaList);
|
|
151
147
|
let request = new $OpenApi.OpenApiRequest({
|
|
152
148
|
query: {
|
|
153
149
|
Env: requestParams.Env,
|
|
154
150
|
Name: requestParams.Name,
|
|
155
|
-
CodeVersion: requestParams.CodeVersion
|
|
156
|
-
CanaryCodeVersion: requestParams.CanaryCodeVersion,
|
|
157
|
-
CanaryAreaList: CanaryAreaListString
|
|
151
|
+
CodeVersion: requestParams.CodeVersion
|
|
158
152
|
}
|
|
159
153
|
});
|
|
160
154
|
let runtime = {
|
|
@@ -225,48 +219,11 @@ export class ApiService {
|
|
|
225
219
|
return null;
|
|
226
220
|
});
|
|
227
221
|
}
|
|
228
|
-
|
|
229
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
-
try {
|
|
231
|
-
let params = {
|
|
232
|
-
action: 'ListRoutineCanaryAreas',
|
|
233
|
-
version: '2024-09-10',
|
|
234
|
-
protocol: 'https',
|
|
235
|
-
method: 'GET',
|
|
236
|
-
authType: 'AK',
|
|
237
|
-
bodyType: 'json',
|
|
238
|
-
reqBodyType: 'json',
|
|
239
|
-
style: 'RPC',
|
|
240
|
-
pathname: '/',
|
|
241
|
-
toMap: function () {
|
|
242
|
-
return this;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
let request = new $OpenApi.OpenApiRequest();
|
|
246
|
-
let runtime = {
|
|
247
|
-
toMap: function () {
|
|
248
|
-
return this;
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
const res = yield this.client.callApi(params, request, runtime);
|
|
252
|
-
if (res.statusCode === 200 && res.body) {
|
|
253
|
-
const ret = {
|
|
254
|
-
CanaryAreas: res.body.CanaryAreas
|
|
255
|
-
};
|
|
256
|
-
return ret;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
catch (error) {
|
|
260
|
-
console.log(error);
|
|
261
|
-
}
|
|
262
|
-
return null;
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
getRoutineUserInfo() {
|
|
222
|
+
listUserRoutines() {
|
|
266
223
|
return __awaiter(this, void 0, void 0, function* () {
|
|
267
224
|
try {
|
|
268
225
|
let params = {
|
|
269
|
-
action: '
|
|
226
|
+
action: 'ListUserRoutines',
|
|
270
227
|
version: '2024-09-10',
|
|
271
228
|
protocol: 'https',
|
|
272
229
|
method: 'GET',
|
|
@@ -287,11 +244,7 @@ export class ApiService {
|
|
|
287
244
|
};
|
|
288
245
|
const res = yield this.client.callApi(params, request, runtime);
|
|
289
246
|
if (res.statusCode === 200 && res.body) {
|
|
290
|
-
|
|
291
|
-
Subdomains: res.body.RoutineName,
|
|
292
|
-
Routines: res.body.Routines
|
|
293
|
-
};
|
|
294
|
-
return ret;
|
|
247
|
+
return res;
|
|
295
248
|
}
|
|
296
249
|
}
|
|
297
250
|
catch (error) {
|
|
@@ -569,7 +522,7 @@ export class ApiService {
|
|
|
569
522
|
}
|
|
570
523
|
getRoutine(requestParams_1) {
|
|
571
524
|
return __awaiter(this, arguments, void 0, function* (requestParams, isShowError = true) {
|
|
572
|
-
var _a, _b, _c, _d, _e, _f
|
|
525
|
+
var _a, _b, _c, _d, _e, _f;
|
|
573
526
|
try {
|
|
574
527
|
let params = {
|
|
575
528
|
action: 'GetRoutine',
|
|
@@ -602,12 +555,10 @@ export class ApiService {
|
|
|
602
555
|
data: {
|
|
603
556
|
RequestId: (_a = res.body) === null || _a === void 0 ? void 0 : _a.RequestId,
|
|
604
557
|
CodeVersions: ((_b = res.body) === null || _b === void 0 ? void 0 : _b.CodeVersions) || [],
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
RelatedRoutes: ((_g = res.body) === null || _g === void 0 ? void 0 : _g.RelatedRoutes) || [],
|
|
610
|
-
DefaultRelatedRecord: (_h = res.body) === null || _h === void 0 ? void 0 : _h.DefaultRelatedRecord
|
|
558
|
+
Envs: ((_c = res.body) === null || _c === void 0 ? void 0 : _c.Envs) || [],
|
|
559
|
+
CreateTime: (_d = res.body) === null || _d === void 0 ? void 0 : _d.CreateTime,
|
|
560
|
+
Description: (_e = res.body) === null || _e === void 0 ? void 0 : _e.Description,
|
|
561
|
+
DefaultRelatedRecord: (_f = res.body) === null || _f === void 0 ? void 0 : _f.DefaultRelatedRecord
|
|
611
562
|
}
|
|
612
563
|
};
|
|
613
564
|
return routineResponse;
|
|
@@ -640,8 +591,7 @@ export class ApiService {
|
|
|
640
591
|
let request = new $OpenApi.OpenApiRequest({
|
|
641
592
|
query: {
|
|
642
593
|
Name: edgeRoutine.name,
|
|
643
|
-
Description: edgeRoutine.description
|
|
644
|
-
SpecName: edgeRoutine.specName
|
|
594
|
+
Description: edgeRoutine.description
|
|
645
595
|
}
|
|
646
596
|
});
|
|
647
597
|
let runtime = {
|
|
@@ -696,7 +646,7 @@ export class ApiService {
|
|
|
696
646
|
}
|
|
697
647
|
};
|
|
698
648
|
const uploadResult = yield this.client.callApi(params, request, runtime);
|
|
699
|
-
const ossConfig =
|
|
649
|
+
const ossConfig = uploadResult.body.OssPostConfig;
|
|
700
650
|
if (uploadResult.statusCode !== 200 || !ossConfig) {
|
|
701
651
|
return false;
|
|
702
652
|
}
|
|
@@ -709,12 +659,12 @@ export class ApiService {
|
|
|
709
659
|
formData.append('policy', policy);
|
|
710
660
|
formData.append('key', key);
|
|
711
661
|
formData.append('file', edgeRoutine.code);
|
|
712
|
-
// TODO: 检查oss结果;
|
|
713
662
|
const ossRes = yield fetch(Url, {
|
|
714
663
|
method: 'POST',
|
|
715
664
|
body: formData,
|
|
716
665
|
headers: formData.getHeaders()
|
|
717
666
|
});
|
|
667
|
+
// console.log('oss result', oss);
|
|
718
668
|
if (ossRes && ossRes.status === 200) {
|
|
719
669
|
return true;
|
|
720
670
|
}
|
|
@@ -772,11 +722,11 @@ export class ApiService {
|
|
|
772
722
|
return null;
|
|
773
723
|
});
|
|
774
724
|
}
|
|
775
|
-
|
|
725
|
+
createRoutineRelatedRecord(requestParams) {
|
|
776
726
|
return __awaiter(this, void 0, void 0, function* () {
|
|
777
727
|
try {
|
|
778
728
|
let params = {
|
|
779
|
-
action: '
|
|
729
|
+
action: 'CreateRoutineRelatedRecord',
|
|
780
730
|
version: '2024-09-10',
|
|
781
731
|
protocol: 'https',
|
|
782
732
|
method: 'GET',
|
|
@@ -789,7 +739,14 @@ export class ApiService {
|
|
|
789
739
|
return this;
|
|
790
740
|
}
|
|
791
741
|
};
|
|
792
|
-
let request = new $OpenApi.OpenApiRequest(
|
|
742
|
+
let request = new $OpenApi.OpenApiRequest({
|
|
743
|
+
query: {
|
|
744
|
+
RecordName: requestParams.RecordName,
|
|
745
|
+
SiteId: requestParams.SiteId,
|
|
746
|
+
SiteName: requestParams.SiteName,
|
|
747
|
+
Name: requestParams.Name
|
|
748
|
+
}
|
|
749
|
+
});
|
|
793
750
|
let runtime = {
|
|
794
751
|
toMap: function () {
|
|
795
752
|
return this;
|
|
@@ -800,8 +757,8 @@ export class ApiService {
|
|
|
800
757
|
const ret = {
|
|
801
758
|
code: res.statusCode,
|
|
802
759
|
data: {
|
|
803
|
-
|
|
804
|
-
|
|
760
|
+
Status: res.body.Status,
|
|
761
|
+
RequestId: res.body.RequestId
|
|
805
762
|
}
|
|
806
763
|
};
|
|
807
764
|
return ret;
|
|
@@ -813,11 +770,11 @@ export class ApiService {
|
|
|
813
770
|
return null;
|
|
814
771
|
});
|
|
815
772
|
}
|
|
816
|
-
|
|
773
|
+
deleteRoutineRelatedRecord(requestParams) {
|
|
817
774
|
return __awaiter(this, void 0, void 0, function* () {
|
|
818
775
|
try {
|
|
819
776
|
let params = {
|
|
820
|
-
action: '
|
|
777
|
+
action: 'DeleteRoutineRelatedRecord',
|
|
821
778
|
version: '2024-09-10',
|
|
822
779
|
protocol: 'https',
|
|
823
780
|
method: 'GET',
|
|
@@ -835,7 +792,8 @@ export class ApiService {
|
|
|
835
792
|
RecordName: requestParams.RecordName,
|
|
836
793
|
SiteId: requestParams.SiteId,
|
|
837
794
|
SiteName: requestParams.SiteName,
|
|
838
|
-
Name: requestParams.Name
|
|
795
|
+
Name: requestParams.Name,
|
|
796
|
+
RecordId: requestParams.RecordId
|
|
839
797
|
}
|
|
840
798
|
});
|
|
841
799
|
let runtime = {
|
|
@@ -861,11 +819,11 @@ export class ApiService {
|
|
|
861
819
|
return null;
|
|
862
820
|
});
|
|
863
821
|
}
|
|
864
|
-
|
|
822
|
+
listRoutineRelatedRecords(requestParams) {
|
|
865
823
|
return __awaiter(this, void 0, void 0, function* () {
|
|
866
824
|
try {
|
|
867
825
|
let params = {
|
|
868
|
-
action: '
|
|
826
|
+
action: 'ListRoutineRelatedRecords',
|
|
869
827
|
version: '2024-09-10',
|
|
870
828
|
protocol: 'https',
|
|
871
829
|
method: 'GET',
|
|
@@ -880,11 +838,10 @@ export class ApiService {
|
|
|
880
838
|
};
|
|
881
839
|
let request = new $OpenApi.OpenApiRequest({
|
|
882
840
|
query: {
|
|
883
|
-
RecordName: requestParams.RecordName,
|
|
884
|
-
SiteId: requestParams.SiteId,
|
|
885
|
-
SiteName: requestParams.SiteName,
|
|
886
841
|
Name: requestParams.Name,
|
|
887
|
-
|
|
842
|
+
PageNumber: requestParams.PageNumber,
|
|
843
|
+
PageSize: requestParams.PageSize,
|
|
844
|
+
SearchKeyWord: requestParams.SearchKeyWord
|
|
888
845
|
}
|
|
889
846
|
});
|
|
890
847
|
let runtime = {
|
|
@@ -897,8 +854,61 @@ export class ApiService {
|
|
|
897
854
|
const ret = {
|
|
898
855
|
code: res.statusCode,
|
|
899
856
|
data: {
|
|
900
|
-
|
|
901
|
-
|
|
857
|
+
PageNumber: res.body.PageNumber,
|
|
858
|
+
PageSize: res.body.PageSize,
|
|
859
|
+
TotalCount: res.body.TotalCount,
|
|
860
|
+
RelatedRecords: res.body.RelatedRecords
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
return ret;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
catch (error) {
|
|
867
|
+
console.log(error);
|
|
868
|
+
}
|
|
869
|
+
return null;
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
createRoutineRoute(requestParams) {
|
|
873
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
874
|
+
try {
|
|
875
|
+
let params = {
|
|
876
|
+
action: 'CreateRoutineRoute',
|
|
877
|
+
version: '2024-09-10',
|
|
878
|
+
protocol: 'https',
|
|
879
|
+
method: 'POST',
|
|
880
|
+
authType: 'AK',
|
|
881
|
+
bodyType: 'json',
|
|
882
|
+
reqBodyType: 'json',
|
|
883
|
+
style: 'RPC',
|
|
884
|
+
pathname: '/',
|
|
885
|
+
toMap: function () {
|
|
886
|
+
return this;
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
let request = new $OpenApi.OpenApiRequest({
|
|
890
|
+
query: {
|
|
891
|
+
SiteId: requestParams.SiteId,
|
|
892
|
+
RoutineName: requestParams.RoutineName,
|
|
893
|
+
RouteName: requestParams.RouteName,
|
|
894
|
+
RouteEnable: 'on',
|
|
895
|
+
Rule: requestParams.Rule,
|
|
896
|
+
Bypass: requestParams.Bypass,
|
|
897
|
+
Mode: 'simple'
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
let runtime = {
|
|
901
|
+
toMap: function () {
|
|
902
|
+
return this;
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
const res = yield this.client.callApi(params, request, runtime);
|
|
906
|
+
if (res.statusCode === 200 && res.body) {
|
|
907
|
+
const ret = {
|
|
908
|
+
code: res.statusCode,
|
|
909
|
+
data: {
|
|
910
|
+
RequestId: res.body.RequestId,
|
|
911
|
+
ConfigId: res.body.ConfigId
|
|
902
912
|
}
|
|
903
913
|
};
|
|
904
914
|
return ret;
|
package/dist/libs/interface.js
CHANGED
package/dist/libs/logger.js
CHANGED
|
@@ -10,7 +10,7 @@ import { getProjectConfig } from '../utils/fileUtils/index.js';
|
|
|
10
10
|
const transport = new DailyRotateFile({
|
|
11
11
|
filename: path.join(os.homedir(), '.esa-logs/esa-debug-%DATE%.log'),
|
|
12
12
|
level: 'info',
|
|
13
|
-
datePattern: 'YYYY-MM-DD-HH
|
|
13
|
+
datePattern: 'YYYY-MM-DD-HH',
|
|
14
14
|
zippedArchive: true,
|
|
15
15
|
maxSize: '10m',
|
|
16
16
|
maxFiles: '7d'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getSummary } from '../../commands/common/constant.js';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
+
import logger from '../logger.js';
|
|
3
4
|
export default class Template {
|
|
4
5
|
constructor(path, title) {
|
|
5
6
|
this.path = path;
|
|
@@ -10,7 +11,7 @@ export default class Template {
|
|
|
10
11
|
list.forEach((summary) => {
|
|
11
12
|
const title = chalk.bold(summary.title);
|
|
12
13
|
const command = chalk.green(summary.command);
|
|
13
|
-
|
|
14
|
+
logger.log(`${title}: ${command}`);
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import path from 'path';
|
|
11
11
|
import { createEdgeRoutine } from '../commands/commit/index.js';
|
|
12
|
-
import { displaySelectSpec } from '../commands/deploy/index.js';
|
|
13
12
|
import { ApiService } from '../libs/apiService.js';
|
|
14
13
|
import { readEdgeRoutineFile } from './fileUtils/index.js';
|
|
15
14
|
import logger from '../libs/logger.js';
|
|
@@ -36,26 +35,22 @@ export function validRoutine(name) {
|
|
|
36
35
|
}
|
|
37
36
|
export function checkRoutineExist(name, entry) {
|
|
38
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
var _a, _b;
|
|
40
38
|
const isCreatedRoutine = yield isRoutineExist(name);
|
|
41
39
|
if (!isCreatedRoutine) {
|
|
42
40
|
logger.log(t('first_deploy').d('This is the first time to deploy, we will create a new routine for you.'));
|
|
43
41
|
const entryFile = path.resolve(entry !== null && entry !== void 0 ? entry : '', 'src/index.js');
|
|
44
42
|
yield prodBuild(false, entryFile, entry);
|
|
45
43
|
const code = readEdgeRoutineFile(entry) || '';
|
|
46
|
-
const
|
|
47
|
-
const specList = ((_b = (_a = (yield server.ListRoutineOptionalSpecs())) === null || _a === void 0 ? void 0 : _a.data.Specs) !== null && _b !== void 0 ? _b : []).reduce((acc, item) => {
|
|
48
|
-
if (item.IsAvailable) {
|
|
49
|
-
acc.push(item.SpecName);
|
|
50
|
-
}
|
|
51
|
-
return acc;
|
|
52
|
-
}, []);
|
|
53
|
-
const spec = yield displaySelectSpec(specList);
|
|
54
|
-
yield createEdgeRoutine({
|
|
44
|
+
const res = yield createEdgeRoutine({
|
|
55
45
|
name: name,
|
|
56
|
-
specName: spec,
|
|
57
46
|
code: code
|
|
58
47
|
});
|
|
48
|
+
if (res) {
|
|
49
|
+
logger.success(t('routine_create_success').d('Routine created successfully.'));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
logger.error(t('routine_create_fail').d('Routine created failed.'));
|
|
53
|
+
}
|
|
59
54
|
}
|
|
60
55
|
});
|
|
61
56
|
}
|
|
@@ -13,7 +13,7 @@ import path from 'path';
|
|
|
13
13
|
export function handleCheckVersion() {
|
|
14
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
15
|
const __dirname = getDirName(import.meta.url);
|
|
16
|
-
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
16
|
+
const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
|
|
17
17
|
try {
|
|
18
18
|
const jsonString = yield fs.readFile(packageJsonPath, 'utf-8');
|
|
19
19
|
const packageJson = JSON.parse(jsonString);
|
|
@@ -0,0 +1,182 @@
|
|
|
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 fetch from 'node-fetch';
|
|
11
|
+
import * as fs from 'fs/promises';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import os from 'os';
|
|
14
|
+
import AdmZip from 'adm-zip';
|
|
15
|
+
import { exec } from 'child_process';
|
|
16
|
+
import { promisify } from 'util';
|
|
17
|
+
import t from '../i18n/index.js';
|
|
18
|
+
import logger from '../libs/logger.js';
|
|
19
|
+
import chalk from 'chalk';
|
|
20
|
+
const execAsync = promisify(exec);
|
|
21
|
+
function getBinDir() {
|
|
22
|
+
const home = os.homedir();
|
|
23
|
+
return path.join(home || '', '.deno', 'bin');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 下载文件
|
|
27
|
+
* @param url 远程文件URL
|
|
28
|
+
* @param dest 本地保存路径
|
|
29
|
+
*/
|
|
30
|
+
export function downloadFile(url, dest) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const response = yield fetch(url);
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new Error(`Error downloading file: ${response.status} ${response.statusText}`);
|
|
35
|
+
}
|
|
36
|
+
const fileStream = yield fs.open(dest, 'w');
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
(_a = response.body) === null || _a === void 0 ? void 0 : _a.pipe(fileStream.createWriteStream());
|
|
40
|
+
(_b = response.body) === null || _b === void 0 ? void 0 : _b.on('error', (err) => {
|
|
41
|
+
fileStream.close();
|
|
42
|
+
reject(err);
|
|
43
|
+
});
|
|
44
|
+
fileStream.createWriteStream().on('finish', () => {
|
|
45
|
+
fileStream.close();
|
|
46
|
+
resolve();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 解压Zip文件 adm 是同步的
|
|
53
|
+
* @param zipPath Zip文件路径
|
|
54
|
+
* @param extractPath 解压目标目录
|
|
55
|
+
*/
|
|
56
|
+
export function unzipFile(zipPath, extractPath) {
|
|
57
|
+
const zip = new AdmZip(zipPath);
|
|
58
|
+
zip.extractAllTo(extractPath, true);
|
|
59
|
+
logger.info(`UnzipFile success: from ${zipPath} to ${extractPath}`);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 获取用户的 PATH 环境变量(win下专用)
|
|
63
|
+
* @returns 用户 PATH
|
|
64
|
+
*/
|
|
65
|
+
function getUserPath() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const { stdout } = yield execAsync('reg query "HKCU\\Environment" /v Path');
|
|
68
|
+
const match = stdout.match(/Path\s+REG_EXPAND_SZ\s+(.*)/i);
|
|
69
|
+
if (match && match[1]) {
|
|
70
|
+
return match[1].trim();
|
|
71
|
+
}
|
|
72
|
+
return '';
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 检查 BinDir 是否在用户的 PATH 中(win下专用)
|
|
77
|
+
* @param binDir BinDir 路径
|
|
78
|
+
* @returns 是否包含
|
|
79
|
+
*/
|
|
80
|
+
function isBinDirInPath(binDir) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const userPath = yield getUserPath();
|
|
83
|
+
return userPath
|
|
84
|
+
.split(';')
|
|
85
|
+
.map((p) => p.toLowerCase())
|
|
86
|
+
.includes(binDir.toLowerCase());
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 将 BinDir 添加到用户的 PATH 环境变量(win下专用)
|
|
91
|
+
* @param binDir BinDir 路径
|
|
92
|
+
*/
|
|
93
|
+
function addBinDirToPath(binDir) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
// 使用 setx 添加到 PATH
|
|
96
|
+
// setx 对 PATH 的长度有2047字符的限制
|
|
97
|
+
const command = `setx Path "%Path%;${binDir}"`;
|
|
98
|
+
try {
|
|
99
|
+
yield execAsync(command);
|
|
100
|
+
logger.info(`Path add success: ${binDir}`);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new Error(`Add BinDir to Path failed: ${error}`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export function downloadRuntimeAndUnzipForWindows() {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
try {
|
|
110
|
+
const BinDir = getBinDir();
|
|
111
|
+
const DenoZip = path.join(BinDir, 'deno.zip');
|
|
112
|
+
const Target = 'x86_64-pc-windows-msvc';
|
|
113
|
+
const DownloadUrl = `http://esa-runtime.myalicdn.com/runtime/deno-${Target}.zip`;
|
|
114
|
+
logger.ora.start('Downloading...');
|
|
115
|
+
try {
|
|
116
|
+
yield fs.mkdir(BinDir, { recursive: true });
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
const err = error;
|
|
120
|
+
logger.ora.fail();
|
|
121
|
+
logger.error(`mkdir error ${BinDir}: ${err.message}`);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
yield downloadFile(DownloadUrl, DenoZip);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
const err = error;
|
|
129
|
+
logger.ora.fail();
|
|
130
|
+
logger.error(`${t('deno_download_failed').d('Download failed')}: ${err.message}`);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
logger.info(`Unzip file to: ${BinDir}`);
|
|
134
|
+
try {
|
|
135
|
+
logger.ora.text = 'Unzip...';
|
|
136
|
+
unzipFile(DenoZip, BinDir);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
const err = error;
|
|
140
|
+
logger.ora.fail();
|
|
141
|
+
logger.error(`${t('deno_unzip_failed').d('Unzip failed')}: ${err.message}`);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
logger.ora.text = 'Deleting temp file...';
|
|
146
|
+
yield fs.unlink(DenoZip);
|
|
147
|
+
logger.ora.succeed('Download success');
|
|
148
|
+
logger.info(`Delete temp file: ${DenoZip}`);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
logger.warn(`Delete temp file ${DenoZip} failed: ${error}`);
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
logger.ora.text = 'Adding Bin dir to PATH...';
|
|
155
|
+
const inPath = yield isBinDirInPath(BinDir);
|
|
156
|
+
if (!inPath) {
|
|
157
|
+
logger.info(`${BinDir} not in PATH`);
|
|
158
|
+
yield addBinDirToPath(BinDir);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
logger.info(`${BinDir} in PATH already`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
const err = error;
|
|
166
|
+
logger.ora.fail();
|
|
167
|
+
logger.error(`${t('deno_add_path_failed').d('Add BinDir to Path failed')}: ${err.message}`);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
logger.success(t('deno_install_success').d('Runtime install success!'));
|
|
171
|
+
logger.block();
|
|
172
|
+
const dev = chalk.green('esa dev');
|
|
173
|
+
logger.log(t('deno_install_success_tips', { dev }).d(`Please run ${dev} again`));
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
const err = error;
|
|
177
|
+
logger.ora.fail();
|
|
178
|
+
logger.error(`Download Error: ${err.message}`);
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
@@ -9,16 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { exec, execSync } from 'child_process';
|
|
11
11
|
import os from 'os';
|
|
12
|
-
import { getDirName } from './fileUtils/base.js';
|
|
13
|
-
import logger from '../libs/logger.js';
|
|
14
12
|
import path from 'path';
|
|
13
|
+
import logger from '../libs/logger.js';
|
|
14
|
+
import { getDirName } from './fileUtils/base.js';
|
|
15
|
+
import { downloadRuntimeAndUnzipForWindows } from './download.js';
|
|
15
16
|
import t from '../i18n/index.js';
|
|
16
17
|
export function preCheckDeno() {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
19
|
const command = yield checkDenoInstalled();
|
|
19
20
|
if (!command) {
|
|
20
|
-
logger.error(t('install_runtime_explain').d('
|
|
21
|
-
installDeno();
|
|
21
|
+
logger.error(t('install_runtime_explain').d('Our runtime does not yet support this OS. We are temporarily using Deno as the local development runtime, which needs to be installed first.'));
|
|
22
|
+
yield installDeno();
|
|
22
23
|
return false;
|
|
23
24
|
}
|
|
24
25
|
return command;
|
|
@@ -45,7 +46,6 @@ export function checkDenoInstalled() {
|
|
|
45
46
|
resolve(res);
|
|
46
47
|
})
|
|
47
48
|
.catch((err) => {
|
|
48
|
-
console.log(err);
|
|
49
49
|
resolve(false);
|
|
50
50
|
});
|
|
51
51
|
});
|
|
@@ -57,8 +57,8 @@ export function installDeno() {
|
|
|
57
57
|
const p = path.join(__dirname, './install');
|
|
58
58
|
switch (os.platform()) {
|
|
59
59
|
case 'win32':
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
yield downloadRuntimeAndUnzipForWindows();
|
|
61
|
+
return true;
|
|
62
62
|
case 'darwin':
|
|
63
63
|
case 'linux':
|
|
64
64
|
installCommand = `sh ${p}/install.sh`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esa-cli",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.12",
|
|
4
4
|
"description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
|
|
5
5
|
"main": "bin/enter.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"watch": "tsc --watch",
|
|
19
19
|
"eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
|
|
20
20
|
"lint-staged": "lint-staged",
|
|
21
|
-
"prepare": "npm run build",
|
|
22
21
|
"test": "FORCE_COLOR=0 npx vitest ",
|
|
23
22
|
"coverage": "vitest --coverage"
|
|
24
23
|
},
|
|
@@ -37,6 +36,7 @@
|
|
|
37
36
|
"@testing-library/dom": "^10.4.0",
|
|
38
37
|
"@testing-library/jest-dom": "^6.5.0",
|
|
39
38
|
"@testing-library/react": "^16.0.1",
|
|
39
|
+
"@types/adm-zip": "^0.5.7",
|
|
40
40
|
"@types/babel__generator": "^7.6.8",
|
|
41
41
|
"@types/babel__traverse": "^7.20.6",
|
|
42
42
|
"@types/cli-table": "^0.3.4",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"vitest": "^2.0.4"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@alicloud/esa20240910": "2.
|
|
69
|
+
"@alicloud/esa20240910": "2.25.0",
|
|
70
70
|
"@alicloud/openapi-client": "^0.4.7",
|
|
71
71
|
"@babel/generator": "^7.26.3",
|
|
72
72
|
"@babel/parser": "^7.24.4",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"@iarna/toml": "^2.2.5",
|
|
75
75
|
"@types/inquirer": "^9.0.7",
|
|
76
76
|
"@vitest/coverage-istanbul": "^2.0.4",
|
|
77
|
-
"
|
|
77
|
+
"adm-zip": "^0.5.16",
|
|
78
78
|
"chalk": "^5.3.0",
|
|
79
79
|
"chokidar": "^3.5.3",
|
|
80
80
|
"cli-table3": "^0.6.5",
|
|
81
81
|
"cross-spawn": "^7.0.3",
|
|
82
|
-
"esa-template": "^0.0.
|
|
82
|
+
"esa-template": "^0.0.7",
|
|
83
83
|
"esbuild": "^0.21.1",
|
|
84
84
|
"esbuild-plugin-less": "^1.3.8",
|
|
85
85
|
"form-data": "^4.0.0",
|