esa-cli 0.0.5 → 1.0.1

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.
Files changed (85) hide show
  1. package/README.md +34 -145
  2. package/dist/commands/commit/index.js +49 -104
  3. package/dist/commands/commit/prodBuild.js +2 -3
  4. package/dist/commands/common/constant.js +4 -4
  5. package/dist/commands/common/utils.js +419 -0
  6. package/dist/commands/config.js +2 -2
  7. package/dist/commands/deploy/helper.js +43 -49
  8. package/dist/commands/deploy/index.js +51 -174
  9. package/dist/commands/deployments/delete.js +32 -22
  10. package/dist/commands/deployments/index.js +4 -4
  11. package/dist/commands/deployments/list.js +21 -34
  12. package/dist/commands/dev/build.js +3 -3
  13. package/dist/commands/dev/doProcess.js +5 -5
  14. package/dist/commands/dev/ew2/cacheService.js +33 -0
  15. package/dist/commands/dev/ew2/devEntry.js +2 -1
  16. package/dist/commands/dev/ew2/devPack.js +31 -20
  17. package/dist/commands/dev/ew2/kvService.js +50 -0
  18. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  19. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  20. package/dist/commands/dev/ew2/server.js +163 -28
  21. package/dist/commands/dev/index.js +17 -18
  22. package/dist/commands/dev/mockWorker/devPack.js +19 -10
  23. package/dist/commands/dev/mockWorker/server.js +7 -6
  24. package/dist/commands/domain/add.js +4 -4
  25. package/dist/commands/domain/delete.js +3 -3
  26. package/dist/commands/domain/index.js +4 -4
  27. package/dist/commands/domain/list.js +7 -7
  28. package/dist/commands/init/helper.js +654 -21
  29. package/dist/commands/init/index.js +88 -152
  30. package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
  31. package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
  32. package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
  33. package/dist/commands/init/template.jsonc +84 -0
  34. package/dist/commands/init/types.js +1 -0
  35. package/dist/commands/lang.js +2 -2
  36. package/dist/commands/login/index.js +74 -34
  37. package/dist/commands/logout.js +6 -6
  38. package/dist/commands/route/add.js +101 -43
  39. package/dist/commands/route/delete.js +6 -6
  40. package/dist/commands/route/helper.js +9 -10
  41. package/dist/commands/route/index.js +4 -4
  42. package/dist/commands/route/list.js +4 -4
  43. package/dist/commands/routine/delete.js +9 -8
  44. package/dist/commands/routine/index.js +6 -5
  45. package/dist/commands/routine/list.js +45 -39
  46. package/dist/commands/site/index.js +3 -3
  47. package/dist/commands/site/list.js +6 -7
  48. package/dist/commands/utils.js +61 -25
  49. package/dist/components/descriptionInput.js +1 -1
  50. package/dist/components/filterSelector.js +1 -1
  51. package/dist/components/mutiLevelSelect.js +19 -20
  52. package/dist/components/mutiSelectTable.js +1 -1
  53. package/dist/components/routeBuilder.js +68 -0
  54. package/dist/components/selectInput.js +2 -3
  55. package/dist/components/selectItem.js +1 -1
  56. package/dist/docs/Commands_en.md +164 -117
  57. package/dist/docs/Commands_zh_CN.md +155 -107
  58. package/dist/docs/Config_en.md +70 -0
  59. package/dist/docs/Config_zh_CN.md +68 -0
  60. package/dist/i18n/index.js +2 -2
  61. package/dist/i18n/locales.json +418 -82
  62. package/dist/index.js +28 -13
  63. package/dist/libs/api.js +3 -6
  64. package/dist/libs/apiService.js +201 -70
  65. package/dist/libs/git/index.js +86 -9
  66. package/dist/libs/interface.js +0 -1
  67. package/dist/libs/logger.js +162 -10
  68. package/dist/libs/service.js +2 -2
  69. package/dist/libs/templates/index.js +1 -1
  70. package/dist/utils/checkAssetsExist.js +80 -0
  71. package/dist/utils/checkDevPort.js +5 -19
  72. package/dist/utils/checkEntryFileExist.js +10 -0
  73. package/dist/utils/checkIsRoutineCreated.js +27 -21
  74. package/dist/utils/checkVersion.js +119 -1
  75. package/dist/utils/command.js +149 -0
  76. package/dist/utils/compress.js +142 -0
  77. package/dist/utils/download.js +8 -8
  78. package/dist/utils/fileMd5.js +1 -1
  79. package/dist/utils/fileUtils/index.js +136 -45
  80. package/dist/utils/installDeno.js +4 -4
  81. package/dist/utils/installEw2.js +9 -9
  82. package/dist/utils/openInBrowser.js +1 -1
  83. package/dist/utils/prompt.js +97 -0
  84. package/package.json +23 -12
  85. package/zh_CN.md +31 -150
package/dist/index.js CHANGED
@@ -7,25 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import chalk from 'chalk';
10
11
  import yargs from 'yargs';
11
12
  import { hideBin } from 'yargs/helpers';
12
- import chalk from 'chalk';
13
- import login from './commands/login/index.js';
13
+ import commit from './commands/commit/index.js';
14
14
  import config from './commands/config.js';
15
- import dev from './commands/dev/index.js';
16
- import init from './commands/init/index.js';
17
- import routine from './commands/routine/index.js';
18
15
  import deploy from './commands/deploy/index.js';
19
- import commit from './commands/commit/index.js';
20
16
  import deployments from './commands/deployments/index.js';
17
+ import dev from './commands/dev/index.js';
21
18
  import domainCommand from './commands/domain/index.js';
22
- import routeCommand from './commands/route/index.js';
23
- import logout from './commands/logout.js';
19
+ import init from './commands/init/index.js';
24
20
  import lang from './commands/lang.js';
25
- import { getCliConfig } from './utils/fileUtils/index.js';
26
- import { handleCheckVersion } from './utils/checkVersion.js';
27
- import t from './i18n/index.js';
21
+ import login from './commands/login/index.js';
22
+ import logout from './commands/logout.js';
23
+ import routeCommand from './commands/route/index.js';
24
+ import routine from './commands/routine/index.js';
28
25
  import site from './commands/site/index.js';
26
+ import t from './i18n/index.js';
27
+ import { handleCheckVersion, checkCLIVersion } from './utils/checkVersion.js';
28
+ import { getCliConfig } from './utils/fileUtils/index.js';
29
29
  const main = () => __awaiter(void 0, void 0, void 0, function* () {
30
30
  const argv = hideBin(process.argv);
31
31
  const cliConfig = getCliConfig();
@@ -34,11 +34,21 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
34
34
  .fail((msg, err) => {
35
35
  console.error(msg, err);
36
36
  })
37
- .scriptName('esa')
37
+ .scriptName('esa-cli')
38
38
  .locale((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) || 'en')
39
39
  .version(false)
40
40
  .wrap(null)
41
- .help(false)
41
+ .help()
42
+ .middleware((argv) => __awaiter(void 0, void 0, void 0, function* () {
43
+ try {
44
+ // Pass current command (first positional) so version check can decide prompting behavior
45
+ yield checkCLIVersion((argv._ && argv._[0] ? String(argv._[0]) : ''));
46
+ }
47
+ catch (e) {
48
+ console.log(e);
49
+ console.log('error');
50
+ }
51
+ }))
42
52
  .epilogue(`${t('main_epilogue').d('For more information, visit ESA')}: ${chalk.underline.blue('https://www.aliyun.com/product/esa')}`)
43
53
  .options('version', {
44
54
  describe: t('main_version_describe').d('Show version'),
@@ -50,11 +60,16 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
50
60
  });
51
61
  esa.command('*', false, () => { }, (args) => {
52
62
  if (args._.length > 0) {
63
+ // Unknown command
64
+ console.error(t('common_sub_command_fail').d('Use esa-cli <command> -h to see help'));
53
65
  }
54
66
  else {
55
67
  if (args.v) {
56
68
  handleCheckVersion();
57
69
  }
70
+ else if (args.h || args.help) {
71
+ esa.showHelp('log');
72
+ }
58
73
  else {
59
74
  esa.showHelp('log');
60
75
  }
package/dist/libs/api.js CHANGED
@@ -103,16 +103,13 @@ class Client {
103
103
  getMatchSite(params) {
104
104
  return this.callOpenApi('getMatchSite', params);
105
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
106
  deleteRoutine(params) {
113
107
  const request = new $ESA.DeleteRoutineRequest(params);
114
108
  return this.callApi(this.client.deleteRoutineWithOptions.bind(this.client), request);
115
109
  }
110
+ listUserRoutines(params) {
111
+ return this.callApi(this.client.listUserRoutinesWithOptions.bind(this.client), new $ESA.ListUserRoutinesRequest(params));
112
+ }
116
113
  deleteRoutineCodeVersion(params) {
117
114
  const request = new $ESA.DeleteRoutineCodeVersionRequest(params);
118
115
  return this.callApi(this.client.deleteRoutineCodeVersionWithOptions.bind(this.client), request);
@@ -10,9 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import * as $OpenApi from '@alicloud/openapi-client';
11
11
  import FormData from 'form-data';
12
12
  import fetch from 'node-fetch';
13
- import { Environment } from './interface.js';
14
- import { getApiConfig } from '../utils/fileUtils/index.js';
15
13
  import t from '../i18n/index.js';
14
+ import { getApiConfig } from '../utils/fileUtils/index.js';
15
+ import { Environment } from './interface.js';
16
16
  export class ApiService {
17
17
  constructor(cliConfig) {
18
18
  var _a, _b;
@@ -48,7 +48,7 @@ export class ApiService {
48
48
  * - message: (Optional) A string providing additional information in case of failure.
49
49
  */
50
50
  checkLogin() {
51
- return __awaiter(this, arguments, void 0, function* (isShowError = true) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
52
  try {
53
53
  let params = {
54
54
  action: 'GetErService',
@@ -74,7 +74,15 @@ export class ApiService {
74
74
  };
75
75
  const response = yield this.client.callApi(params, request, runtime);
76
76
  if (response.statusCode === 200) {
77
- return { success: true };
77
+ if (response.body.Status === 'Running') {
78
+ return { success: true };
79
+ }
80
+ else {
81
+ return {
82
+ success: false,
83
+ message: t('not_active').d('Functions and Pages is not active, please activate it first. Visit: https://esa.console.aliyun.com/edge/pages to activate.')
84
+ };
85
+ }
78
86
  }
79
87
  else if (response.statusCode === 403) {
80
88
  return {
@@ -90,7 +98,6 @@ export class ApiService {
90
98
  }
91
99
  }
92
100
  catch (error) {
93
- isShowError && console.log(error);
94
101
  return {
95
102
  success: false,
96
103
  message: t('login_failed').d('An error occurred while trying to log in.')
@@ -101,15 +108,15 @@ export class ApiService {
101
108
  quickDeployRoutine(edgeRoutine) {
102
109
  return __awaiter(this, void 0, void 0, function* () {
103
110
  try {
104
- // 上传代码到unstable版本
111
+ // Upload code to unstable version
105
112
  const stagingRes = yield this.getRoutineStagingCodeUploadInfo(edgeRoutine);
106
113
  if (stagingRes) {
107
- // 生产版本
114
+ // Production version
108
115
  const commitRes = yield this.commitRoutineStagingCode({
109
116
  Name: edgeRoutine.name,
110
117
  CodeDescription: edgeRoutine.description
111
118
  });
112
- // 发布到生产环境
119
+ // Deploy to production environment
113
120
  if (commitRes) {
114
121
  const deployRes = yield this.publishRoutineCodeVersion({
115
122
  Name: edgeRoutine.name,
@@ -129,7 +136,6 @@ export class ApiService {
129
136
  }
130
137
  publishRoutineCodeVersion(requestParams) {
131
138
  return __awaiter(this, void 0, void 0, function* () {
132
- var _a;
133
139
  try {
134
140
  let params = {
135
141
  action: 'PublishRoutineCodeVersion',
@@ -145,15 +151,11 @@ export class ApiService {
145
151
  return this;
146
152
  }
147
153
  };
148
- const CanaryAreaList = (_a = requestParams.CanaryAreaList) !== null && _a !== void 0 ? _a : [];
149
- const CanaryAreaListString = JSON.stringify(CanaryAreaList);
150
154
  let request = new $OpenApi.OpenApiRequest({
151
155
  query: {
152
156
  Env: requestParams.Env,
153
157
  Name: requestParams.Name,
154
- CodeVersion: requestParams.CodeVersion,
155
- CanaryCodeVersion: requestParams.CanaryCodeVersion,
156
- CanaryAreaList: CanaryAreaListString
158
+ CodeVersion: requestParams.CodeVersion
157
159
  }
158
160
  });
159
161
  let runtime = {
@@ -224,11 +226,11 @@ export class ApiService {
224
226
  return null;
225
227
  });
226
228
  }
227
- listRoutineCanaryAreas() {
229
+ listUserRoutines(requestParams) {
228
230
  return __awaiter(this, void 0, void 0, function* () {
229
231
  try {
230
232
  let params = {
231
- action: 'ListRoutineCanaryAreas',
233
+ action: 'ListUserRoutines',
232
234
  version: '2024-09-10',
233
235
  protocol: 'https',
234
236
  method: 'GET',
@@ -241,44 +243,9 @@ export class ApiService {
241
243
  return this;
242
244
  }
243
245
  };
244
- let request = new $OpenApi.OpenApiRequest();
245
- let runtime = {
246
- toMap: function () {
247
- return this;
248
- }
249
- };
250
- const res = yield this.client.callApi(params, request, runtime);
251
- if (res.statusCode === 200 && res.body) {
252
- const ret = {
253
- CanaryAreas: res.body.CanaryAreas
254
- };
255
- return ret;
256
- }
257
- }
258
- catch (error) {
259
- console.log(error);
260
- }
261
- return null;
262
- });
263
- }
264
- getRoutineUserInfo() {
265
- return __awaiter(this, void 0, void 0, function* () {
266
- try {
267
- let params = {
268
- action: 'GetRoutineUserInfo',
269
- version: '2024-09-10',
270
- protocol: 'https',
271
- method: 'GET',
272
- authType: 'AK',
273
- bodyType: 'json',
274
- reqBodyType: 'json',
275
- style: 'RPC',
276
- pathname: '/',
277
- toMap: function () {
278
- return this;
279
- }
280
- };
281
- let request = new $OpenApi.OpenApiRequest();
246
+ let request = new $OpenApi.OpenApiRequest({
247
+ query: requestParams || {}
248
+ });
282
249
  let runtime = {
283
250
  toMap: function () {
284
251
  return this;
@@ -286,11 +253,7 @@ export class ApiService {
286
253
  };
287
254
  const res = yield this.client.callApi(params, request, runtime);
288
255
  if (res.statusCode === 200 && res.body) {
289
- const ret = {
290
- Subdomains: res.body.RoutineName,
291
- Routines: res.body.Routines
292
- };
293
- return ret;
256
+ return res;
294
257
  }
295
258
  }
296
259
  catch (error) {
@@ -568,7 +531,6 @@ export class ApiService {
568
531
  }
569
532
  getRoutine(requestParams_1) {
570
533
  return __awaiter(this, arguments, void 0, function* (requestParams, isShowError = true) {
571
- var _a, _b, _c, _d, _e, _f;
572
534
  try {
573
535
  let params = {
574
536
  action: 'GetRoutine',
@@ -598,14 +560,7 @@ export class ApiService {
598
560
  if (res.statusCode === 200 && res.body) {
599
561
  const routineResponse = {
600
562
  code: res.statusCode,
601
- data: {
602
- RequestId: (_a = res.body) === null || _a === void 0 ? void 0 : _a.RequestId,
603
- CodeVersions: ((_b = res.body) === null || _b === void 0 ? void 0 : _b.CodeVersions) || [],
604
- Envs: ((_c = res.body) === null || _c === void 0 ? void 0 : _c.Envs) || [],
605
- CreateTime: (_d = res.body) === null || _d === void 0 ? void 0 : _d.CreateTime,
606
- Description: (_e = res.body) === null || _e === void 0 ? void 0 : _e.Description,
607
- DefaultRelatedRecord: (_f = res.body) === null || _f === void 0 ? void 0 : _f.DefaultRelatedRecord
608
- }
563
+ data: res.body
609
564
  };
610
565
  return routineResponse;
611
566
  }
@@ -637,7 +592,8 @@ export class ApiService {
637
592
  let request = new $OpenApi.OpenApiRequest({
638
593
  query: {
639
594
  Name: edgeRoutine.name,
640
- Description: edgeRoutine.description
595
+ Description: edgeRoutine.description,
596
+ HasAssets: edgeRoutine.hasAssets
641
597
  }
642
598
  });
643
599
  let runtime = {
@@ -710,7 +666,6 @@ export class ApiService {
710
666
  body: formData,
711
667
  headers: formData.getHeaders()
712
668
  });
713
- // console.log('oss result', oss);
714
669
  if (ossRes && ossRes.status === 200) {
715
670
  return true;
716
671
  }
@@ -966,5 +921,181 @@ export class ApiService {
966
921
  return null;
967
922
  });
968
923
  }
924
+ /**
925
+ * 调用 CreateRoutineWithAssetsCodeVersion API 获取 OSS 上传配置
926
+ */
927
+ CreateRoutineWithAssetsCodeVersion(requestParams) {
928
+ return __awaiter(this, void 0, void 0, function* () {
929
+ var _a;
930
+ try {
931
+ let params = {
932
+ action: 'CreateRoutineWithAssetsCodeVersion',
933
+ version: '2024-09-10',
934
+ protocol: 'https',
935
+ method: 'POST',
936
+ authType: 'AK',
937
+ bodyType: 'json',
938
+ reqBodyType: 'json',
939
+ style: 'RPC',
940
+ pathname: '/',
941
+ toMap: function () {
942
+ return this;
943
+ }
944
+ };
945
+ let request = new $OpenApi.OpenApiRequest({
946
+ body: {
947
+ Name: requestParams.Name,
948
+ CodeDescription: requestParams.CodeDescription,
949
+ ExtraInfo: requestParams.ExtraInfo,
950
+ ConfOptions: {
951
+ NotFoundStrategy: (_a = requestParams.ConfOptions) === null || _a === void 0 ? void 0 : _a.NotFoundStrategy
952
+ }
953
+ }
954
+ });
955
+ let runtime = {
956
+ toMap: function () {
957
+ return this;
958
+ }
959
+ };
960
+ const result = yield this.client.callApi(params, request, runtime);
961
+ if (result.statusCode === 200 && result.body) {
962
+ return {
963
+ code: result.statusCode.toString(),
964
+ data: {
965
+ RequestId: result.body.RequestId,
966
+ CodeVersion: result.body.CodeVersion,
967
+ Status: result.body.Status,
968
+ OssPostConfig: result.body.OssPostConfig
969
+ }
970
+ };
971
+ }
972
+ return null;
973
+ }
974
+ catch (error) {
975
+ console.error('Error calling CreateRoutineWithAssetsCodeVersion:', error);
976
+ return null;
977
+ }
978
+ });
979
+ }
980
+ /**
981
+ * 上传文件到 OSS
982
+ */
983
+ uploadToOss(ossConfig, zipBuffer) {
984
+ return __awaiter(this, void 0, void 0, function* () {
985
+ try {
986
+ const { OSSAccessKeyId, Signature, Url, Key, Policy, XOssSecurityToken } = ossConfig;
987
+ const formData = new FormData();
988
+ formData.append('OSSAccessKeyId', OSSAccessKeyId);
989
+ formData.append('Signature', Signature);
990
+ formData.append('x-oss-security-token', XOssSecurityToken);
991
+ formData.append('policy', Policy);
992
+ formData.append('key', Key);
993
+ formData.append('file', zipBuffer);
994
+ const ossRes = yield fetch(Url, {
995
+ method: 'POST',
996
+ body: formData,
997
+ headers: formData.getHeaders()
998
+ });
999
+ return ossRes && (ossRes.status === 200 || ossRes.status === 204);
1000
+ }
1001
+ catch (error) {
1002
+ console.error('Error uploading to OSS:', error);
1003
+ return false;
1004
+ }
1005
+ });
1006
+ }
1007
+ createRoutineCodeDeployment(requestParams) {
1008
+ return __awaiter(this, void 0, void 0, function* () {
1009
+ try {
1010
+ let params = {
1011
+ action: 'CreateRoutineCodeDeployment',
1012
+ version: '2024-09-10',
1013
+ protocol: 'https',
1014
+ method: 'POST',
1015
+ authType: 'AK',
1016
+ bodyType: 'json',
1017
+ reqBodyType: 'json',
1018
+ style: 'RPC',
1019
+ pathname: '/',
1020
+ toMap: function () {
1021
+ return this;
1022
+ }
1023
+ };
1024
+ let request = new $OpenApi.OpenApiRequest({
1025
+ query: {
1026
+ Name: requestParams.Name,
1027
+ Env: requestParams.Env,
1028
+ Strategy: requestParams.Strategy,
1029
+ CodeVersions: JSON.stringify(requestParams.CodeVersions)
1030
+ }
1031
+ });
1032
+ let runtime = {
1033
+ toMap: function () {
1034
+ return this;
1035
+ }
1036
+ };
1037
+ const res = yield this.client.callApi(params, request, runtime);
1038
+ if (res.statusCode === 200 && res.body) {
1039
+ const ret = {
1040
+ code: res.statusCode,
1041
+ data: {
1042
+ RequestId: res.body.RequestId,
1043
+ Strategy: res.body.Strategy,
1044
+ DeploymentId: res.body.DeploymentId,
1045
+ CodeVersions: res.body.CodeVersions
1046
+ }
1047
+ };
1048
+ return ret;
1049
+ }
1050
+ }
1051
+ catch (error) {
1052
+ console.log(error);
1053
+ }
1054
+ return null;
1055
+ });
1056
+ }
1057
+ getRoutineCodeVersionInfo(requestParams) {
1058
+ return __awaiter(this, void 0, void 0, function* () {
1059
+ try {
1060
+ let params = {
1061
+ action: 'GetRoutineCodeVersionInfo',
1062
+ version: '2024-09-10',
1063
+ protocol: 'https',
1064
+ method: 'GET',
1065
+ authType: 'AK',
1066
+ bodyType: 'json',
1067
+ reqBodyType: 'json',
1068
+ style: 'RPC',
1069
+ pathname: '/',
1070
+ toMap: function () {
1071
+ return this;
1072
+ }
1073
+ };
1074
+ let request = new $OpenApi.OpenApiRequest({
1075
+ query: {
1076
+ Name: requestParams.Name,
1077
+ CodeVersion: requestParams.CodeVersion
1078
+ }
1079
+ });
1080
+ let runtime = {
1081
+ toMap: function () {
1082
+ return this;
1083
+ }
1084
+ };
1085
+ const res = yield this.client.callApi(params, request, runtime);
1086
+ if (res.statusCode === 200 && res.body) {
1087
+ const ret = {
1088
+ code: res.statusCode,
1089
+ data: res.body
1090
+ };
1091
+ return ret;
1092
+ }
1093
+ }
1094
+ catch (error) {
1095
+ console.log(error);
1096
+ }
1097
+ return null;
1098
+ });
1099
+ }
969
1100
  }
970
1101
  ApiService.instance = null;
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { execSync } from 'child_process';
11
- import { exit } from 'process';
11
+ import logger from '../../libs/logger.js';
12
12
  export function isInstalledGit() {
13
13
  try {
14
14
  execSync('git --version');
@@ -30,23 +30,100 @@ export function isGitConfigured() {
30
30
  }
31
31
  export function cloneRepository(url, path) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
+ if (!isInstalledGit()) {
34
+ logger.error('Git is not installed on your system.');
35
+ logger.info('Please install Git first:');
36
+ logger.info(' • macOS: brew install git');
37
+ logger.info(' • Ubuntu/Debian: sudo apt-get install git');
38
+ logger.info(' • Windows: Download from https://git-scm.com/');
39
+ logger.info(' • Or visit: https://git-scm.com/downloads');
40
+ return false;
41
+ }
33
42
  try {
34
43
  execSync(`git clone ${url} ${path}`, { stdio: 'inherit' });
35
- console.log('Repository cloned successfully.');
44
+ logger.log('Repository cloned successfully.');
45
+ return true;
36
46
  }
37
47
  catch (error) {
38
- console.error('Error occurred while cloning the repository:', error);
39
- exit(0);
48
+ logger.error(`Error occurred while cloning the repository: ${error}`);
49
+ return false;
40
50
  }
41
51
  });
42
52
  }
43
- export function installGit(path) {
53
+ export function installGit(path, debug = false, autoInstall = false) {
54
+ if (!isInstalledGit()) {
55
+ if (autoInstall) {
56
+ logger.info('Git not found. Attempting to auto-install...');
57
+ if (autoInstallGit()) {
58
+ logger.info('Git installed successfully! Now initializing repository...');
59
+ }
60
+ else {
61
+ logger.error('Failed to auto-install Git.');
62
+ logger.info('Please install Git manually:');
63
+ logger.info(' • macOS: brew install git');
64
+ logger.info(' • Ubuntu/Debian: sudo apt-get install git');
65
+ logger.info(' • Windows: Download from https://git-scm.com/');
66
+ logger.info(' • Or visit: https://git-scm.com/downloads');
67
+ return false;
68
+ }
69
+ }
70
+ else {
71
+ logger.error('Git is not installed on your system.');
72
+ logger.info('Please install Git first:');
73
+ logger.info(' • macOS: brew install git');
74
+ logger.info(' • Ubuntu/Debian: sudo apt-get install git');
75
+ logger.info(' • Windows: Download from https://git-scm.com/');
76
+ logger.info(' • Or visit: https://git-scm.com/downloads');
77
+ return false;
78
+ }
79
+ }
80
+ try {
81
+ execSync('git init', { stdio: 'ignore', cwd: path });
82
+ if (debug) {
83
+ logger.log('Git repository initialized successfully.');
84
+ }
85
+ return true;
86
+ }
87
+ catch (error) {
88
+ logger.error(`Error occurred while initializing Git repository: ${error}`);
89
+ return false;
90
+ }
91
+ }
92
+ /**
93
+ * Attempt to automatically install Git on supported platforms
94
+ * @returns true if installation was successful, false otherwise
95
+ */
96
+ export function autoInstallGit() {
44
97
  try {
45
- execSync('git init', { stdio: 'inherit', cwd: path });
46
- console.log('Git has been installed successfully.');
98
+ const platform = process.platform;
99
+ if (platform === 'darwin') {
100
+ // macOS - try using Homebrew
101
+ logger.info('Attempting to install Git using Homebrew...');
102
+ execSync('brew install git', { stdio: 'inherit' });
103
+ logger.success('Git installed successfully via Homebrew!');
104
+ return true;
105
+ }
106
+ else if (platform === 'linux') {
107
+ // Linux - try using apt-get (Ubuntu/Debian)
108
+ logger.info('Attempting to install Git using apt-get...');
109
+ execSync('sudo apt-get update && sudo apt-get install -y git', {
110
+ stdio: 'inherit'
111
+ });
112
+ logger.success('Git installed successfully via apt-get!');
113
+ return true;
114
+ }
115
+ else {
116
+ logger.warn('Auto-installation is not supported on this platform.');
117
+ logger.info('Please install Git manually from: https://git-scm.com/downloads');
118
+ return false;
119
+ }
47
120
  }
48
121
  catch (error) {
49
- console.error('Error occurred during Git installation:', error);
50
- exit(0);
122
+ logger.error(`Failed to auto-install Git: ${error}`);
123
+ logger.info('Please install Git manually:');
124
+ logger.info(' • macOS: brew install git');
125
+ logger.info(' • Ubuntu/Debian: sudo apt-get install git');
126
+ logger.info(' • Windows: Download from https://git-scm.com/');
127
+ return false;
51
128
  }
52
129
  }
@@ -7,7 +7,6 @@ export var PublishType;
7
7
  (function (PublishType) {
8
8
  PublishType["Staging"] = "staging";
9
9
  PublishType["Production"] = "production";
10
- PublishType["Canary"] = "canary";
11
10
  })(PublishType || (PublishType = {}));
12
11
  var BasicType;
13
12
  (function (BasicType) {