esa-cli 0.0.2-beta.2 → 0.0.2-beta.21

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 (80) hide show
  1. package/dist/commands/commit/index.js +45 -117
  2. package/dist/commands/commit/prodBuild.js +2 -3
  3. package/dist/commands/common/constant.js +0 -19
  4. package/dist/commands/common/utils.js +419 -0
  5. package/dist/commands/config.js +1 -1
  6. package/dist/commands/deploy/helper.js +51 -72
  7. package/dist/commands/deploy/index.js +48 -187
  8. package/dist/commands/deployments/delete.js +32 -22
  9. package/dist/commands/deployments/index.js +3 -3
  10. package/dist/commands/deployments/list.js +22 -38
  11. package/dist/commands/dev/build.js +3 -3
  12. package/dist/commands/dev/doProcess.js +5 -5
  13. package/dist/commands/dev/ew2/cacheService.js +33 -0
  14. package/dist/commands/dev/ew2/devEntry.js +2 -1
  15. package/dist/commands/dev/ew2/devPack.js +30 -34
  16. package/dist/commands/dev/ew2/kvService.js +46 -0
  17. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  18. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  19. package/dist/commands/dev/ew2/server.js +165 -28
  20. package/dist/commands/dev/index.js +16 -16
  21. package/dist/commands/dev/mockWorker/devPack.js +32 -21
  22. package/dist/commands/dev/mockWorker/server.js +7 -6
  23. package/dist/commands/domain/add.js +3 -3
  24. package/dist/commands/domain/delete.js +7 -7
  25. package/dist/commands/domain/index.js +3 -3
  26. package/dist/commands/domain/list.js +10 -10
  27. package/dist/commands/init/helper.js +761 -0
  28. package/dist/commands/init/index.js +88 -220
  29. package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
  30. package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
  31. package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
  32. package/dist/commands/init/template.jsonc +84 -0
  33. package/dist/commands/init/types.js +1 -0
  34. package/dist/commands/lang.js +2 -2
  35. package/dist/commands/login/index.js +74 -34
  36. package/dist/commands/logout.js +6 -6
  37. package/dist/commands/route/add.js +138 -49
  38. package/dist/commands/route/delete.js +33 -27
  39. package/dist/commands/route/helper.js +124 -0
  40. package/dist/commands/route/index.js +3 -3
  41. package/dist/commands/route/list.js +56 -17
  42. package/dist/commands/routine/delete.js +2 -2
  43. package/dist/commands/routine/index.js +3 -3
  44. package/dist/commands/routine/list.js +9 -21
  45. package/dist/commands/site/index.js +2 -2
  46. package/dist/commands/site/list.js +6 -7
  47. package/dist/commands/utils.js +55 -19
  48. package/dist/components/descriptionInput.js +1 -1
  49. package/dist/components/mutiLevelSelect.js +43 -55
  50. package/dist/components/mutiSelectTable.js +1 -1
  51. package/dist/components/selectInput.js +2 -3
  52. package/dist/components/selectItem.js +1 -1
  53. package/dist/docs/Commands_en.md +142 -131
  54. package/dist/docs/Commands_zh_CN.md +139 -127
  55. package/dist/i18n/index.js +2 -2
  56. package/dist/i18n/locales.json +401 -21
  57. package/dist/index.js +27 -20
  58. package/dist/libs/api.js +32 -9
  59. package/dist/libs/apiService.js +262 -84
  60. package/dist/libs/git/index.js +86 -9
  61. package/dist/libs/interface.js +0 -1
  62. package/dist/libs/logger.js +162 -10
  63. package/dist/libs/service.js +2 -2
  64. package/dist/libs/templates/index.js +3 -2
  65. package/dist/utils/checkAssetsExist.js +80 -0
  66. package/dist/utils/checkDevPort.js +3 -17
  67. package/dist/utils/checkEntryFileExist.js +10 -0
  68. package/dist/utils/checkIsRoutineCreated.js +27 -26
  69. package/dist/utils/checkVersion.js +119 -1
  70. package/dist/utils/command.js +149 -0
  71. package/dist/utils/compress.js +136 -0
  72. package/dist/utils/download.js +182 -0
  73. package/dist/utils/fileMd5.js +1 -1
  74. package/dist/utils/fileUtils/base.js +1 -1
  75. package/dist/utils/fileUtils/index.js +69 -28
  76. package/dist/utils/installDeno.js +8 -8
  77. package/dist/utils/installEw2.js +7 -7
  78. package/dist/utils/openInBrowser.js +1 -1
  79. package/dist/utils/prompt.js +97 -0
  80. package/package.json +20 -12
@@ -7,20 +7,35 @@ 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';
11
- import logger from '../../libs/logger.js';
12
- import { checkDirectory, checkIsLoginSuccess, isValidRouteForDomain } from '../utils.js';
13
- import { getProjectConfig } from '../../utils/fileUtils/index.js';
14
- import { ApiService } from '../../libs/apiService.js';
10
+ import inquirer from 'inquirer';
15
11
  import t from '../../i18n/index.js';
16
- import { descriptionInput } from '../../components/descriptionInput.js';
17
- import { promptFilterSelector } from '../../components/filterSelector.js';
12
+ import { ApiService } from '../../libs/apiService.js';
13
+ import logger from '../../libs/logger.js';
18
14
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
15
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
16
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
17
+ import { transferRouteToRuleString } from './helper.js';
19
18
  const addRoute = {
20
19
  command: 'add [route] [site]',
21
- describe: `📥 ${t('route_add_describe').d('Bind a Route to a routine')}`,
20
+ describe: `🚄 ${t('route_add_describe').d('Bind a Route to a routine')}`,
22
21
  builder: (yargs) => {
23
- return yargs.fail((msg, err, yargsIns) => {
22
+ return yargs
23
+ .option('route', {
24
+ describe: t('route_add_route_value_option').d('The route value. For example: example.com/*'),
25
+ alias: 'r',
26
+ type: 'string'
27
+ })
28
+ .option('site', {
29
+ describe: t('route_add_site_describe').d('The site to bind the route to. For example: example.com'),
30
+ alias: 's',
31
+ type: 'string'
32
+ })
33
+ .option('alias', {
34
+ alias: 'a',
35
+ describe: t('route_add_route_name_option').d('Route name (aliases)'),
36
+ type: 'string'
37
+ })
38
+ .fail((msg, err, yargsIns) => {
24
39
  if (err)
25
40
  throw err;
26
41
  if (msg) {
@@ -36,7 +51,7 @@ const addRoute = {
36
51
  };
37
52
  export function handlerAddRoute(argv) {
38
53
  return __awaiter(this, void 0, void 0, function* () {
39
- var _a, _b, _c;
54
+ var _a;
40
55
  if (!checkDirectory()) {
41
56
  return;
42
57
  }
@@ -47,8 +62,6 @@ export function handlerAddRoute(argv) {
47
62
  if (!isSuccess)
48
63
  return;
49
64
  yield validRoutine(projectConfig.name);
50
- // input route and site
51
- const { route, site } = argv;
52
65
  const listSitesReq = {
53
66
  SiteSearchType: 'fuzzy',
54
67
  Status: 'active',
@@ -57,58 +70,134 @@ export function handlerAddRoute(argv) {
57
70
  };
58
71
  const server = yield ApiService.getInstance();
59
72
  const ListSitesRes = yield server.listSites(listSitesReq);
60
- const siteList = ((ListSitesRes === null || ListSitesRes === void 0 ? void 0 : ListSitesRes.data.Sites) || []).map((i) => ({
61
- label: i.SiteName,
73
+ if (!((_a = ListSitesRes === null || ListSitesRes === void 0 ? void 0 : ListSitesRes.data) === null || _a === void 0 ? void 0 : _a.Sites) || ListSitesRes.data.Sites.length === 0) {
74
+ logger.error(t('no_active_sites').d('No active sites found in your account'));
75
+ return;
76
+ }
77
+ const siteList = ListSitesRes.data.Sites.map((i) => ({
78
+ name: i.SiteName,
62
79
  value: i.SiteId
63
80
  }));
64
- if (route && site) {
65
- const siteId = (_a = siteList.find((item) => item.label === site)) === null || _a === void 0 ? void 0 : _a.value;
66
- const req = {
67
- Name: projectConfig.name,
68
- SiteId: Number(siteId),
69
- SiteName: String(site),
70
- Route: String(route)
71
- };
72
- const res = yield server.createRoutineRelatedRoute(req);
73
- const addSuccess = ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.Status) === 'OK';
74
- if (addSuccess) {
75
- logger.success(t('route_add_success').d('Add route success!'));
81
+ // 获取路由名称,支持直接通过参数传入
82
+ let routeName = argv.alias;
83
+ if (!routeName) {
84
+ const response = yield inquirer.prompt([
85
+ {
86
+ type: 'input',
87
+ name: 'routeName',
88
+ message: t('create_route_route_name').d('Enter a Route Name (Aliases):'),
89
+ validate: (input) => {
90
+ if (!input) {
91
+ return t('route_name_input_required').d('Route name is required');
92
+ }
93
+ return true;
94
+ }
95
+ }
96
+ ]);
97
+ routeName = response.routeName;
98
+ }
99
+ let siteName = argv.site;
100
+ let siteId;
101
+ if (!siteName) {
102
+ if (argv._.length > 2) {
103
+ siteName = argv._[2];
104
+ }
105
+ // 如果仍未提供站点名称,则提示选择
106
+ if (!siteName) {
107
+ const response = yield inquirer.prompt([
108
+ {
109
+ type: 'list',
110
+ name: 'routeSite',
111
+ message: t('create_route_site').d('Select a site that is active in your account:'),
112
+ choices: siteList
113
+ }
114
+ ]);
115
+ siteId = response.routeSite;
76
116
  }
77
117
  else {
78
- logger.error(t('route_add_fail').d('Add route fail!'));
118
+ // 根据站点名称查找对应的站点ID
119
+ const matchedSite = siteList.find((site) => site.name === siteName);
120
+ if (matchedSite) {
121
+ siteId = matchedSite.value;
122
+ }
123
+ else {
124
+ logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
125
+ return;
126
+ }
127
+ }
128
+ }
129
+ else {
130
+ // 根据站点名称查找对应的站点ID
131
+ const matchedSite = siteList.find((site) => site.name === siteName);
132
+ if (matchedSite) {
133
+ siteId = matchedSite.value;
134
+ }
135
+ else {
136
+ logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
137
+ return;
79
138
  }
80
- return;
81
139
  }
82
- logger.warn(t('interactive_mode').d('Interactive mode'));
83
- // not input route and site, enter interactive mode
84
- logger.log(`🖊️ ${t('domain_input').d('Enter the name of domain (Support fuzzy matching on tab press):')}`);
85
- const domain = yield promptFilterSelector(siteList);
86
- const inputRoute = yield descriptionInput(`🖊️ ${t('route_input').d('Enter a Route:')} (${chalk.green(t('route_validate').d('You can add an asterisk (*) as the prefix or suffix to match more URLs, such as "*.example.com/*".'))})`, true);
87
- const ROUTE_PATTERN = /^(?:\*\.)?([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,})(\/\*|\/[^?#]*)?$/;
88
- if (!ROUTE_PATTERN.test(inputRoute)) {
89
- return logger.error(t('route_add_invalid_route').d('Invalid route'));
140
+ // 获取路由值,支持直接通过参数传入
141
+ let inputRoute = argv.route;
142
+ if (!inputRoute) {
143
+ // 如果参数中提供了路由值,使用它
144
+ if (argv._.length > 1) {
145
+ inputRoute = argv._[1];
146
+ }
147
+ // 如果仍未提供路由值,则提示输入
148
+ if (!inputRoute) {
149
+ const response = yield inquirer.prompt([
150
+ {
151
+ type: 'input',
152
+ name: 'inputRoute',
153
+ message: t('create_route_route').d('Enter a Route (e.g., example.com/*):'),
154
+ validate: (input) => {
155
+ if (!input) {
156
+ return t('route_input_required').d('Route is required');
157
+ }
158
+ if (!input.includes('*') && !input.includes('/')) {
159
+ return t('route_format_invalid').d('Route format is invalid. Please include wildcard (*) or path (/)');
160
+ }
161
+ return true;
162
+ }
163
+ }
164
+ ]);
165
+ inputRoute = response.inputRoute;
166
+ }
90
167
  }
91
- if (!isValidRouteForDomain(inputRoute, domain.label)) {
92
- return logger.error(t('route_site_not_match').d('The route does not correspond to the domain.'));
168
+ const rule = transferRouteToRuleString(inputRoute);
169
+ if (!rule) {
170
+ logger.error(t('route_format_invalid').d('Invalid route format'));
171
+ return;
93
172
  }
94
- if (domain.value !== '') {
95
- const req = {
96
- Name: projectConfig.name,
97
- SiteId: Number(domain.value),
98
- SiteName: domain.label,
99
- Route: inputRoute
100
- };
101
- const res = yield server.createRoutineRelatedRoute(req);
102
- const addSuccess = ((_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.Status) === 'OK';
173
+ // 获取站点名称用于显示
174
+ const selectedSite = siteList.find((site) => site.value === siteId);
175
+ const displaySiteName = selectedSite ? selectedSite.name : siteName;
176
+ const req = {
177
+ RoutineName: projectConfig.name,
178
+ RouteName: routeName,
179
+ SiteId: siteId,
180
+ RouteEnable: 'on',
181
+ Bypass: 'off',
182
+ Rule: rule
183
+ };
184
+ try {
185
+ logger.info(t('creating_route').d('Creating route...'));
186
+ const res = yield server.createRoutineRoute(req);
187
+ const addSuccess = (res === null || res === void 0 ? void 0 : res.code) === 200;
103
188
  if (addSuccess) {
104
189
  logger.success(t('route_add_success').d('Add route success!'));
190
+ logger.info(`Route "${routeName}" has been successfully added to routine "${projectConfig.name}" for site "${displaySiteName}"`);
105
191
  }
106
192
  else {
107
193
  logger.error(t('route_add_fail').d('Add route fail!'));
108
194
  }
109
195
  }
110
- else {
111
- logger.error(t('invalid_domain').d('Input domain is invalid'));
196
+ catch (error) {
197
+ logger.error(t('route_add_fail').d('Add route fail!'));
198
+ if (error instanceof Error) {
199
+ logger.error(`Error: ${error.message}`);
200
+ }
112
201
  }
113
202
  });
114
203
  }
@@ -7,20 +7,30 @@ 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 { getProjectConfig } from '../../utils/fileUtils/index.js';
11
- import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
12
- import { ApiService } from '../../libs/apiService.js';
13
- import logger from '../../libs/logger.js';
14
10
  import t from '../../i18n/index.js';
11
+ import api from '../../libs/api.js';
12
+ import logger from '../../libs/logger.js';
15
13
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
14
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
15
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
16
16
  const deleteRoute = {
17
- command: 'delete <route>',
17
+ command: 'delete <routeName>',
18
18
  describe: `🗑 ${t('route_delete_describe').d('Delete a related route')}`,
19
19
  builder: (yargs) => {
20
- return yargs.positional('route', {
20
+ return yargs
21
+ .positional('routeName', {
21
22
  describe: t('route_delete_positional_describe').d('The name of the routes to delete'),
22
23
  type: 'string',
23
24
  demandOption: true
25
+ })
26
+ .fail((msg, err, yargsIns) => {
27
+ console.log(msg, err);
28
+ if (err)
29
+ throw err;
30
+ if (msg) {
31
+ yargsIns.showHelp('log');
32
+ }
33
+ process.exit(1);
24
34
  });
25
35
  },
26
36
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
@@ -30,7 +40,7 @@ const deleteRoute = {
30
40
  export default deleteRoute;
31
41
  export function handleDeleteRoute(argv) {
32
42
  return __awaiter(this, void 0, void 0, function* () {
33
- var _a, _b;
43
+ var _a;
34
44
  if (!checkDirectory()) {
35
45
  return;
36
46
  }
@@ -41,29 +51,25 @@ export function handleDeleteRoute(argv) {
41
51
  if (!isSuccess)
42
52
  return;
43
53
  yield validRoutine(projectConfig.name);
44
- const server = yield ApiService.getInstance();
45
- const req = { Name: projectConfig.name };
46
- const routineDetail = yield server.getRoutine(req);
47
- if (!routineDetail)
48
- return;
49
- const relatedRoutes = (_b = (_a = routineDetail.data) === null || _a === void 0 ? void 0 : _a.RelatedRoutes) !== null && _b !== void 0 ? _b : [];
50
- const deleteDomain = argv.route;
51
- const matchedSite = relatedRoutes.find((item) => {
52
- return String(item.Route) === deleteDomain;
53
- });
54
- if (matchedSite === undefined) {
55
- logger.error(t('route_not_exist').d('Route not exist!'));
54
+ const req = {
55
+ routineName: projectConfig.name
56
+ };
57
+ const res = yield api.listRoutineRoutes(req);
58
+ const configs = ((_a = res.body) === null || _a === void 0 ? void 0 : _a.configs) || [];
59
+ const deleteRouteName = argv.routeName;
60
+ const matchedRoute = configs.find((config) => config.routeName === deleteRouteName);
61
+ if (!matchedRoute) {
62
+ logger.error(t('no_route_found').d('No route found! Please check the route name.'));
56
63
  return;
57
64
  }
58
- const request = {
59
- Name: projectConfig.name,
60
- SiteId: matchedSite.SiteId,
61
- SiteName: matchedSite.SiteName,
62
- Route: matchedSite.Route,
63
- RouteId: matchedSite.RouteId
65
+ const siteId = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.siteId;
66
+ const configId = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.configId;
67
+ const deleteRouteReq = {
68
+ siteId: siteId,
69
+ configId: configId
64
70
  };
65
- const res = yield server.deleteRoutineRelatedRoute(request);
66
- const isDeleteSuccess = (res === null || res === void 0 ? void 0 : res.data.Status) === 'OK';
71
+ const deleteRouteRes = yield api.deleteRoutineRoute(deleteRouteReq);
72
+ const isDeleteSuccess = deleteRouteRes.statusCode === 200;
67
73
  if (isDeleteSuccess) {
68
74
  logger.success(t('route_delete_success').d('Delete route success!'));
69
75
  }
@@ -0,0 +1,124 @@
1
+ /* 操作符号枚举 */
2
+ export var OPERATOR_ENUM;
3
+ (function (OPERATOR_ENUM) {
4
+ OPERATOR_ENUM["Eq"] = "eq";
5
+ OPERATOR_ENUM["Ne"] = "ne";
6
+ OPERATOR_ENUM["Contains"] = "contains";
7
+ OPERATOR_ENUM["Negate_Contains"] = "negate_contains";
8
+ OPERATOR_ENUM["StartsWith"] = "starts_with";
9
+ OPERATOR_ENUM["Negate_StartsWith"] = "negate_starts_with";
10
+ OPERATOR_ENUM["EndsWith"] = "ends_with";
11
+ OPERATOR_ENUM["Negate_EndsWith"] = "negate_ends_with";
12
+ OPERATOR_ENUM["Matches"] = "matches";
13
+ OPERATOR_ENUM["Negate_Matches"] = "negate_matches";
14
+ OPERATOR_ENUM["In"] = "in";
15
+ OPERATOR_ENUM["Negate_In"] = "negate_in";
16
+ OPERATOR_ENUM["Gt"] = "gt";
17
+ OPERATOR_ENUM["Lt"] = "lt";
18
+ OPERATOR_ENUM["Ge"] = "ge";
19
+ OPERATOR_ENUM["Le"] = "le";
20
+ OPERATOR_ENUM["InList"] = "in_list";
21
+ OPERATOR_ENUM["Negate_InList"] = "negate_in_list";
22
+ })(OPERATOR_ENUM || (OPERATOR_ENUM = {}));
23
+ const RuleMatchTypeHost = 'http.host';
24
+ const RuleMatchTypeUriPath = 'http.request.uri.path';
25
+ const RuleMatchOperatorEq = OPERATOR_ENUM.Eq;
26
+ const RuleMatchOperatorStartsWith = OPERATOR_ENUM.StartsWith;
27
+ const RuleMatchOperatorEndsWith = OPERATOR_ENUM.EndsWith;
28
+ export const transferRouteToRuleString = (routePath) => {
29
+ if (!routePath) {
30
+ return '';
31
+ }
32
+ const index = routePath.indexOf('/');
33
+ let host = '';
34
+ let uriPath = '';
35
+ if (index < 0) {
36
+ host = routePath;
37
+ uriPath = '/';
38
+ }
39
+ else {
40
+ host = routePath.substring(0, index);
41
+ uriPath = routePath.substring(index);
42
+ }
43
+ let hostOperator = RuleMatchOperatorEq;
44
+ if (host.startsWith('*')) {
45
+ hostOperator = RuleMatchOperatorEndsWith;
46
+ host = host.replace(/\*/g, '');
47
+ }
48
+ let uriPathOperator = RuleMatchOperatorEq;
49
+ if (uriPath.endsWith('*')) {
50
+ uriPathOperator = RuleMatchOperatorStartsWith;
51
+ uriPath = uriPath.replace(/\*$/, '');
52
+ }
53
+ let ruleStr = '';
54
+ if (hostOperator === RuleMatchOperatorEq) {
55
+ if (uriPathOperator === RuleMatchOperatorEq) {
56
+ ruleStr = `(${RuleMatchTypeHost} ${hostOperator} "${host}" and ${RuleMatchTypeUriPath} ${uriPathOperator} "${uriPath}")`;
57
+ }
58
+ else if (uriPathOperator === RuleMatchOperatorStartsWith) {
59
+ ruleStr = `(${RuleMatchTypeHost} ${hostOperator} "${host}" and ${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath}, "${uriPath}"))`;
60
+ }
61
+ }
62
+ else if (hostOperator === RuleMatchOperatorEndsWith) {
63
+ if (uriPathOperator === RuleMatchOperatorEq) {
64
+ ruleStr = `(${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost}, "${host}") and ${RuleMatchTypeUriPath} ${uriPathOperator} "${uriPath}")`;
65
+ }
66
+ else if (uriPathOperator === RuleMatchOperatorStartsWith) {
67
+ ruleStr = `(${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost}, "${host}") and ${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath}, "${uriPath}"))`;
68
+ }
69
+ }
70
+ return ruleStr;
71
+ };
72
+ export const transferRuleStringToRoute = (ruleStr) => {
73
+ if (!ruleStr) {
74
+ return '';
75
+ }
76
+ // 去掉外层括号并按 " and " 分割
77
+ const cleanedRule = ruleStr.replace(/^\(|\)$/g, '');
78
+ const parts = cleanedRule.split(' and ');
79
+ if (parts.length !== 2) {
80
+ return '';
81
+ }
82
+ let host = '';
83
+ let uriPath = '';
84
+ // 处理host部分
85
+ const hostPart = parts[0].trim();
86
+ if (hostPart.startsWith(`${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost},`)) {
87
+ // host匹配eq时的逻辑
88
+ // ends_with(http.host, "value")
89
+ const match = hostPart.match(/ends_with\(http\.host,\s*"([^"]+)"\)/);
90
+ if (match) {
91
+ host = `*${match[1]}`; // 加前缀 *
92
+ }
93
+ }
94
+ else if (hostPart.startsWith(`${RuleMatchTypeHost} ${RuleMatchOperatorEq}`)) {
95
+ // host匹配eq时的逻辑
96
+ // http.host eq "value"
97
+ const match = hostPart.match(/http\.host eq "([^"]+)"/);
98
+ if (match) {
99
+ host = match[1];
100
+ }
101
+ }
102
+ // 处理uriPath 部分
103
+ const uriPathPart = parts[1].trim();
104
+ if (uriPathPart.startsWith(`${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath},`)) {
105
+ // uriPath匹配startsWith时的逻辑
106
+ // starts_with(http.request.uri.path, "value")
107
+ const match = uriPathPart.match(/starts_with\(http\.request\.uri\.path,\s*"([^"]+)"\)/);
108
+ if (match) {
109
+ uriPath = `${match[1]}*`; // 加后缀 *
110
+ }
111
+ }
112
+ else if (uriPathPart.startsWith(`${RuleMatchTypeUriPath} ${RuleMatchOperatorEq}`)) {
113
+ // uriPath匹配eq时的逻辑
114
+ // http.request.uri.path eq "value"
115
+ const match = uriPathPart.match(/http\.request\.uri\.path eq "([^"]+)"/);
116
+ if (match) {
117
+ uriPath = match[1];
118
+ }
119
+ }
120
+ if (!host || !uriPath) {
121
+ return '';
122
+ }
123
+ return `${host}${uriPath}`;
124
+ };
@@ -1,11 +1,11 @@
1
+ import t from '../../i18n/index.js';
2
+ import addRoute from './add.js';
1
3
  import deleteRoute from './delete.js';
2
4
  import listRoute from './list.js';
3
- import addRoute from './add.js';
4
- import t from '../../i18n/index.js';
5
5
  let yargsIns;
6
6
  const routeCommand = {
7
7
  command: 'route [script]',
8
- describe: `🚀 ${t('route_describe').d('Manage the routes bound to your routine')}`,
8
+ describe: `🚄 ${t('route_describe').d('Manage the routes bound to your routine')}`,
9
9
  builder: (yargs) => {
10
10
  yargsIns = yargs;
11
11
  return yargs
@@ -7,13 +7,14 @@ 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 { getProjectConfig } from '../../utils/fileUtils/index.js';
11
10
  import Table from 'cli-table3';
12
- import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
13
- import { ApiService } from '../../libs/apiService.js';
14
- import logger from '../../libs/logger.js';
15
11
  import t from '../../i18n/index.js';
12
+ import api from '../../libs/api.js';
13
+ import logger from '../../libs/logger.js';
16
14
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
15
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
16
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
17
+ import { transferRuleStringToRoute } from './helper.js';
17
18
  const listRoute = {
18
19
  command: 'list',
19
20
  describe: `🔍 ${t('route_list_describe').d('List all related routes')}`,
@@ -24,7 +25,7 @@ const listRoute = {
24
25
  export default listRoute;
25
26
  export function handleListRoutes() {
26
27
  return __awaiter(this, void 0, void 0, function* () {
27
- var _a, _b;
28
+ var _a;
28
29
  if (!checkDirectory()) {
29
30
  return;
30
31
  }
@@ -35,29 +36,67 @@ export function handleListRoutes() {
35
36
  if (!isSuccess)
36
37
  return;
37
38
  yield validRoutine(projectConfig.name);
38
- const server = yield ApiService.getInstance();
39
- const req = { Name: projectConfig.name };
40
- const routineDetail = yield server.getRoutine(req);
41
- if (!routineDetail)
42
- return;
43
- const relatedRoutes = (_b = (_a = routineDetail.data) === null || _a === void 0 ? void 0 : _a.RelatedRoutes) !== null && _b !== void 0 ? _b : [];
44
- if (relatedRoutes.length === 0) {
39
+ const req = {
40
+ routineName: projectConfig.name
41
+ };
42
+ const res = yield api.listRoutineRoutes(req);
43
+ const configs = ((_a = res.body) === null || _a === void 0 ? void 0 : _a.configs) || [];
44
+ if (configs.length === 0) {
45
45
  logger.warn(`🙅 ${t('route_list_empty').d('No related routes found')}`);
46
46
  return;
47
47
  }
48
- logger.log(`📃 ${t('route_list_title').d('Related routes')}:`);
49
- displayRelatedRouteList(relatedRoutes);
48
+ const simpleRoutes = configs
49
+ .filter((item) => item.mode !== 'custom')
50
+ .map((config) => {
51
+ var _a, _b, _c;
52
+ return {
53
+ RouteName: (_a = config.routeName) !== null && _a !== void 0 ? _a : '',
54
+ Route: transferRuleStringToRoute((_b = config.rule) !== null && _b !== void 0 ? _b : ''),
55
+ SiteName: (_c = config.siteName) !== null && _c !== void 0 ? _c : ''
56
+ };
57
+ });
58
+ if (simpleRoutes.length > 0) {
59
+ logger.log(`📃 ${t('route_list_simple_title').d('Related simple mode routes')}:`);
60
+ displayRelatedRouteList(simpleRoutes);
61
+ }
62
+ const customRoutes = configs
63
+ .filter((item) => item.mode === 'custom')
64
+ .map((config) => {
65
+ var _a, _b, _c;
66
+ return {
67
+ RouteName: (_a = config.routeName) !== null && _a !== void 0 ? _a : '',
68
+ Route: (_b = config.rule) !== null && _b !== void 0 ? _b : '',
69
+ SiteName: (_c = config.siteName) !== null && _c !== void 0 ? _c : ''
70
+ };
71
+ });
72
+ if (customRoutes.length > 0) {
73
+ logger.log(`📃 ${t('route_list_custom_title').d('Related custom mode routes')}:`);
74
+ displayRelatedRouteRuleList(customRoutes);
75
+ }
50
76
  });
51
77
  }
52
78
  export function displayRelatedRouteList(routeList) {
53
79
  return __awaiter(this, void 0, void 0, function* () {
54
80
  const table = new Table({
55
- head: ['Route', 'Site'],
56
- colWidths: [30, 30]
81
+ head: ['Route Name', 'Route', 'Site'],
82
+ colWidths: [20]
83
+ });
84
+ for (let i = 0; i < routeList.length; i++) {
85
+ const route = routeList[i];
86
+ table.push([route.RouteName, route.Route, route.SiteName]);
87
+ }
88
+ console.log(table.toString());
89
+ });
90
+ }
91
+ export function displayRelatedRouteRuleList(routeList) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const table = new Table({
94
+ head: ['Route Name', 'Rule', 'Site'],
95
+ colWidths: [20]
57
96
  });
58
97
  for (let i = 0; i < routeList.length; i++) {
59
98
  const route = routeList[i];
60
- table.push([route.Route, route.SiteName]);
99
+ table.push([route.RouteName, route.Route, route.SiteName]);
61
100
  }
62
101
  console.log(table.toString());
63
102
  });
@@ -7,10 +7,10 @@ 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 { checkIsLoginSuccess } from '../utils.js';
11
- import { ApiService } from '../../libs/apiService.js';
12
10
  import t from '../../i18n/index.js';
11
+ import { ApiService } from '../../libs/apiService.js';
13
12
  import logger from '../../libs/logger.js';
13
+ import { checkIsLoginSuccess } from '../utils.js';
14
14
  const deleteCommand = {
15
15
  command: 'delete <routineName>',
16
16
  describe: `🗑 ${t('delete_describe').d('Delete a routine')}`,
@@ -1,10 +1,10 @@
1
- import routineList from './list.js';
2
- import routineDelete from './delete.js';
3
1
  import t from '../../i18n/index.js';
2
+ import routineDelete from './delete.js';
3
+ import routineList from './list.js';
4
4
  let yargsIns;
5
5
  const routineCommand = {
6
6
  command: 'routine [script]',
7
- describe: `🚀 ${t('routine_describe').d('Manage your routine')}`,
7
+ describe: `🧭 ${t('routine_describe').d('Manage your routine')}`,
8
8
  builder: (yargs) => {
9
9
  yargsIns = yargs;
10
10
  return yargs