esa-cli 0.0.2-beta.9 → 1.0.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.
Files changed (85) hide show
  1. package/README.md +32 -149
  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 +51 -54
  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 +165 -29
  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 +7 -7
  26. package/dist/commands/domain/index.js +4 -4
  27. package/dist/commands/domain/list.js +10 -10
  28. package/dist/commands/init/helper.js +654 -20
  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 +105 -49
  39. package/dist/commands/route/delete.js +33 -27
  40. package/dist/commands/route/helper.js +123 -0
  41. package/dist/commands/route/index.js +4 -4
  42. package/dist/commands/route/list.js +56 -17
  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 +447 -71
  62. package/dist/index.js +28 -13
  63. package/dist/libs/api.js +32 -9
  64. package/dist/libs/apiService.js +294 -73
  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 +24 -13
  85. package/zh_CN.md +29 -154
@@ -7,20 +7,36 @@ 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';
11
+ import { routeBuilder } from '../../components/routeBuilder.js';
15
12
  import t from '../../i18n/index.js';
16
- import { descriptionInput } from '../../components/descriptionInput.js';
17
- import { promptFilterSelector } from '../../components/filterSelector.js';
13
+ import { ApiService } from '../../libs/apiService.js';
14
+ import logger from '../../libs/logger.js';
18
15
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
16
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
17
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
18
+ import { transferRouteToRuleString } from './helper.js';
19
19
  const addRoute = {
20
20
  command: 'add [route] [site]',
21
- describe: `📥 ${t('route_add_describe').d('Bind a Route to a routine')}`,
21
+ describe: `🚄 ${t('route_add_describe').d('Bind a Route to a project')}`,
22
22
  builder: (yargs) => {
23
- return yargs.fail((msg, err, yargsIns) => {
23
+ return yargs
24
+ .option('route', {
25
+ describe: t('route_add_route_value_option').d('The route value. For example: example.com/*'),
26
+ alias: 'r',
27
+ type: 'string'
28
+ })
29
+ .option('site', {
30
+ describe: t('route_add_site_describe').d('The site to bind the route to. For example: example.com'),
31
+ alias: 's',
32
+ type: 'string'
33
+ })
34
+ .option('alias', {
35
+ alias: 'a',
36
+ describe: t('route_add_route_name_option').d('Route name (aliases)'),
37
+ type: 'string'
38
+ })
39
+ .fail((msg, err, yargsIns) => {
24
40
  if (err)
25
41
  throw err;
26
42
  if (msg) {
@@ -36,7 +52,7 @@ const addRoute = {
36
52
  };
37
53
  export function handlerAddRoute(argv) {
38
54
  return __awaiter(this, void 0, void 0, function* () {
39
- var _a, _b, _c;
55
+ var _a;
40
56
  if (!checkDirectory()) {
41
57
  return;
42
58
  }
@@ -47,8 +63,6 @@ export function handlerAddRoute(argv) {
47
63
  if (!isSuccess)
48
64
  return;
49
65
  yield validRoutine(projectConfig.name);
50
- // input route and site
51
- const { route, site } = argv;
52
66
  const listSitesReq = {
53
67
  SiteSearchType: 'fuzzy',
54
68
  Status: 'active',
@@ -57,58 +71,100 @@ export function handlerAddRoute(argv) {
57
71
  };
58
72
  const server = yield ApiService.getInstance();
59
73
  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,
74
+ if (!((_a = ListSitesRes === null || ListSitesRes === void 0 ? void 0 : ListSitesRes.data) === null || _a === void 0 ? void 0 : _a.Sites) || ListSitesRes.data.Sites.length === 0) {
75
+ logger.error(t('no_active_sites').d('No active sites found in your account'));
76
+ return;
77
+ }
78
+ const siteList = ListSitesRes.data.Sites.map((i) => ({
79
+ name: i.SiteName,
62
80
  value: i.SiteId
63
81
  }));
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!'));
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
+ const response = yield inquirer.prompt([
103
+ {
104
+ type: 'list',
105
+ name: 'routeSite',
106
+ message: t('create_route_site').d('Select a site that is active in your account:'),
107
+ choices: siteList
108
+ }
109
+ ]);
110
+ siteId = response.routeSite;
111
+ }
112
+ else {
113
+ // Find corresponding site ID by site name
114
+ const matchedSite = siteList.find((site) => site.name === siteName);
115
+ if (matchedSite) {
116
+ siteId = matchedSite.value;
76
117
  }
77
118
  else {
78
- logger.error(t('route_add_fail').d('Add route fail!'));
119
+ logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
120
+ return;
79
121
  }
80
- return;
81
122
  }
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'));
123
+ let inputRoute = argv.route;
124
+ if (!inputRoute) {
125
+ // Get selected site name for route building
126
+ const selectedSite = siteList.find((site) => site.value === siteId);
127
+ const displaySiteName = selectedSite ? selectedSite.name : siteName;
128
+ // Use route builder
129
+ const builtRoute = yield routeBuilder(displaySiteName);
130
+ if (!builtRoute) {
131
+ logger.info(t('route_build_cancelled').d('Route building cancelled'));
132
+ return;
133
+ }
134
+ inputRoute = builtRoute;
90
135
  }
91
- if (!isValidRouteForDomain(inputRoute, domain.label)) {
92
- return logger.error(t('route_site_not_match').d('The route does not correspond to the domain.'));
136
+ const rule = transferRouteToRuleString(inputRoute);
137
+ if (!rule) {
138
+ logger.error(t('route_format_invalid').d('Invalid route format'));
139
+ return;
93
140
  }
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';
141
+ const selectedSite = siteList.find((site) => site.value === siteId);
142
+ const displaySiteName = selectedSite ? selectedSite.name : siteName;
143
+ const req = {
144
+ RoutineName: projectConfig.name,
145
+ RouteName: routeName,
146
+ SiteId: siteId,
147
+ RouteEnable: 'on',
148
+ Bypass: 'off',
149
+ Rule: rule
150
+ };
151
+ try {
152
+ logger.info(t('creating_route').d('Creating route...'));
153
+ const res = yield server.createRoutineRoute(req);
154
+ const addSuccess = (res === null || res === void 0 ? void 0 : res.code) === 200;
103
155
  if (addSuccess) {
104
156
  logger.success(t('route_add_success').d('Add route success!'));
157
+ logger.info(`Route "${routeName}" has been successfully added to routine "${projectConfig.name}" for site "${displaySiteName}"`);
105
158
  }
106
159
  else {
107
160
  logger.error(t('route_add_fail').d('Add route fail!'));
108
161
  }
109
162
  }
110
- else {
111
- logger.error(t('invalid_domain').d('Input domain is invalid'));
163
+ catch (error) {
164
+ logger.error(t('route_add_fail').d('Add route fail!'));
165
+ if (error instanceof Error) {
166
+ logger.error(`Error: ${error.message}`);
167
+ }
112
168
  }
113
169
  });
114
170
  }
@@ -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,123 @@
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
+ } // Remove outer brackets and split by " and "
76
+ const cleanedRule = ruleStr.replace(/^\(|\)$/g, '');
77
+ const parts = cleanedRule.split(' and ');
78
+ if (parts.length !== 2) {
79
+ return '';
80
+ }
81
+ let host = '';
82
+ let uriPath = '';
83
+ // Process host part
84
+ const hostPart = parts[0].trim();
85
+ if (hostPart.startsWith(`${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost},`)) {
86
+ // Logic when host matches eq
87
+ // ends_with(http.host, "value")
88
+ const match = hostPart.match(/ends_with\(http\.host,\s*"([^"]+)"\)/);
89
+ if (match) {
90
+ host = `*${match[1]}`; // Add prefix *
91
+ }
92
+ }
93
+ else if (hostPart.startsWith(`${RuleMatchTypeHost} ${RuleMatchOperatorEq}`)) {
94
+ // Logic when host matches eq
95
+ // http.host eq "value"
96
+ const match = hostPart.match(/http\.host eq "([^"]+)"/);
97
+ if (match) {
98
+ host = match[1];
99
+ }
100
+ }
101
+ // Process uriPath part
102
+ const uriPathPart = parts[1].trim();
103
+ if (uriPathPart.startsWith(`${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath},`)) {
104
+ // Logic when uriPath matches startsWith
105
+ // starts_with(http.request.uri.path, "value")
106
+ const match = uriPathPart.match(/starts_with\(http\.request\.uri\.path,\s*"([^"]+)"\)/);
107
+ if (match) {
108
+ uriPath = `${match[1]}*`; // Add suffix *
109
+ }
110
+ }
111
+ else if (uriPathPart.startsWith(`${RuleMatchTypeUriPath} ${RuleMatchOperatorEq}`)) {
112
+ // Logic when uriPath matches eq
113
+ // http.request.uri.path eq "value"
114
+ const match = uriPathPart.match(/http\.request\.uri\.path eq "([^"]+)"/);
115
+ if (match) {
116
+ uriPath = match[1];
117
+ }
118
+ }
119
+ if (!host || !uriPath) {
120
+ return '';
121
+ }
122
+ return `${host}${uriPath}`;
123
+ };
@@ -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 project')}`,
9
9
  builder: (yargs) => {
10
10
  yargsIns = yargs;
11
11
  return yargs
@@ -18,7 +18,7 @@ const routeCommand = {
18
18
  type: 'boolean',
19
19
  default: false
20
20
  })
21
- .usage(`${t('common_usage').d('Usage')}: esa route <add | list | delete>`);
21
+ .usage(`${t('common_usage').d('Usage')}: esa-cli route <add | list | delete>`);
22
22
  },
23
23
  handler: (argv) => {
24
24
  if (yargsIns && (argv.help || argv._.length < 2)) {
@@ -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,22 +7,23 @@ 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
- command: 'delete <routineName>',
16
- describe: `🗑 ${t('delete_describe').d('Delete a routine')}`,
15
+ command: 'delete <projectName>',
16
+ aliases: ['delete <routineName>'],
17
+ describe: `🗑 ${t('delete_describe').d('Delete a project')}`,
17
18
  builder: (yargs) => {
18
19
  return yargs
19
- .positional('routineName', {
20
- describe: t('delete_routineName_positional_describe').d('The name of the routine to delete'),
20
+ .positional('projectName', {
21
+ describe: t('delete_routineName_positional_describe').d('The name of the project to delete'),
21
22
  type: 'string',
22
23
  array: true,
23
24
  demandOption: true
24
25
  })
25
- .usage(`${t('common_usage').d('Usage')}: $0 delete <routineName>`);
26
+ .usage(`${t('common_usage').d('Usage')}: $0 delete <projectName>`);
26
27
  },
27
28
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
28
29
  handleDelete(argv);
@@ -34,7 +35,7 @@ export function handleDelete(argv) {
34
35
  const isSuccess = yield checkIsLoginSuccess();
35
36
  if (!isSuccess)
36
37
  return;
37
- const routineName = argv.routineName;
38
+ const routineName = argv.projectName || argv.routineName;
38
39
  const req = { Name: routineName };
39
40
  return yield deleteRoutineFromUserAccount(req);
40
41
  });
@@ -1,10 +1,11 @@
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
- command: 'routine [script]',
7
- describe: `🚀 ${t('routine_describe').d('Manage your routine')}`,
6
+ command: 'project [script]',
7
+ aliases: ['routine'],
8
+ describe: `🧭 ${t('routine_describe').d('Manage your project')}`,
8
9
  builder: (yargs) => {
9
10
  yargsIns = yargs;
10
11
  return yargs
@@ -16,7 +17,7 @@ const routineCommand = {
16
17
  type: 'boolean',
17
18
  default: false
18
19
  })
19
- .usage(`${t('common_usage').d('Usage')}: esa routine [list | delete]`);
20
+ .usage(`${t('common_usage').d('Usage')}: esa-cli project [list | delete]`);
20
21
  },
21
22
  handler: (argv) => {
22
23
  if (yargsIns && (argv.help || argv._.length < 2)) {