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.
Files changed (51) hide show
  1. package/dist/commands/commit/index.js +34 -25
  2. package/dist/commands/common/constant.js +0 -19
  3. package/dist/commands/deploy/helper.js +10 -26
  4. package/dist/commands/deploy/index.js +49 -60
  5. package/dist/commands/deployments/delete.js +1 -16
  6. package/dist/commands/deployments/index.js +1 -1
  7. package/dist/commands/deployments/list.js +8 -15
  8. package/dist/commands/dev/ew2/cacheService.js +33 -0
  9. package/dist/commands/dev/ew2/devEntry.js +2 -1
  10. package/dist/commands/dev/ew2/devPack.js +13 -26
  11. package/dist/commands/dev/ew2/kvService.js +27 -0
  12. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  13. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  14. package/dist/commands/dev/ew2/server.js +152 -19
  15. package/dist/commands/dev/index.js +4 -4
  16. package/dist/commands/dev/mockWorker/devPack.js +16 -14
  17. package/dist/commands/domain/add.js +1 -1
  18. package/dist/commands/domain/delete.js +4 -4
  19. package/dist/commands/domain/index.js +1 -1
  20. package/dist/commands/domain/list.js +3 -3
  21. package/dist/commands/init/helper.js +137 -0
  22. package/dist/commands/init/index.js +183 -187
  23. package/dist/commands/login/index.js +49 -3
  24. package/dist/commands/logout.js +1 -1
  25. package/dist/commands/route/add.js +50 -52
  26. package/dist/commands/route/delete.js +29 -23
  27. package/dist/commands/route/helper.js +124 -0
  28. package/dist/commands/route/index.js +1 -1
  29. package/dist/commands/route/list.js +53 -14
  30. package/dist/commands/routine/index.js +1 -1
  31. package/dist/commands/routine/list.js +4 -5
  32. package/dist/commands/site/index.js +1 -1
  33. package/dist/commands/utils.js +5 -5
  34. package/dist/components/mutiLevelSelect.js +44 -55
  35. package/dist/docs/Commands_en.md +27 -13
  36. package/dist/docs/Commands_zh_CN.md +14 -0
  37. package/dist/docs/Dev_en.md +0 -0
  38. package/dist/docs/Dev_zh_CN.md +0 -0
  39. package/dist/i18n/locales.json +144 -12
  40. package/dist/index.js +6 -9
  41. package/dist/libs/api.js +32 -9
  42. package/dist/libs/apiService.js +88 -78
  43. package/dist/libs/interface.js +0 -1
  44. package/dist/libs/logger.js +1 -1
  45. package/dist/libs/templates/index.js +2 -1
  46. package/dist/utils/checkIsRoutineCreated.js +7 -12
  47. package/dist/utils/checkVersion.js +1 -1
  48. package/dist/utils/download.js +182 -0
  49. package/dist/utils/fileUtils/base.js +1 -1
  50. package/dist/utils/installDeno.js +7 -7
  51. package/package.json +5 -5
@@ -7,18 +7,17 @@ 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
10
  import logger from '../../libs/logger.js';
12
- import { checkDirectory, checkIsLoginSuccess, isValidRouteForDomain } from '../utils.js';
11
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
13
12
  import { getProjectConfig } from '../../utils/fileUtils/index.js';
14
13
  import { ApiService } from '../../libs/apiService.js';
15
14
  import t from '../../i18n/index.js';
16
- import { descriptionInput } from '../../components/descriptionInput.js';
17
- import { promptFilterSelector } from '../../components/filterSelector.js';
18
15
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
16
+ import inquirer from 'inquirer';
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
22
  return yargs.fail((msg, err, yargsIns) => {
24
23
  if (err)
@@ -36,7 +35,6 @@ const addRoute = {
36
35
  };
37
36
  export function handlerAddRoute(argv) {
38
37
  return __awaiter(this, void 0, void 0, function* () {
39
- var _a, _b, _c;
40
38
  if (!checkDirectory()) {
41
39
  return;
42
40
  }
@@ -47,8 +45,6 @@ export function handlerAddRoute(argv) {
47
45
  if (!isSuccess)
48
46
  return;
49
47
  yield validRoutine(projectConfig.name);
50
- // input route and site
51
- const { route, site } = argv;
52
48
  const listSitesReq = {
53
49
  SiteSearchType: 'fuzzy',
54
50
  Status: 'active',
@@ -58,57 +54,59 @@ export function handlerAddRoute(argv) {
58
54
  const server = yield ApiService.getInstance();
59
55
  const ListSitesRes = yield server.listSites(listSitesReq);
60
56
  const siteList = ((ListSitesRes === null || ListSitesRes === void 0 ? void 0 : ListSitesRes.data.Sites) || []).map((i) => ({
61
- label: i.SiteName,
57
+ name: i.SiteName,
62
58
  value: i.SiteId
63
59
  }));
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!'));
60
+ const { routeName } = yield inquirer.prompt([
61
+ {
62
+ type: 'input',
63
+ name: 'routeName',
64
+ message: t('create_route_route_name').d('Enter a Route Name (Aliases):'),
65
+ validate: (input) => {
66
+ if (!input) {
67
+ return t('route_name_input_required').d('Route name is required');
68
+ }
69
+ return true;
70
+ }
76
71
  }
77
- else {
78
- logger.error(t('route_add_fail').d('Add route fail!'));
72
+ ]);
73
+ const { routeSite } = yield inquirer.prompt([
74
+ {
75
+ type: 'list',
76
+ name: 'routeSite',
77
+ message: t('create_route_site').d('Select a site that is active in your account:'),
78
+ choices: siteList
79
79
  }
80
- return;
81
- }
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'));
90
- }
91
- if (!isValidRouteForDomain(inputRoute, domain.label)) {
92
- return logger.error(t('route_site_not_match').d('The route does not correspond to the domain.'));
93
- }
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';
103
- if (addSuccess) {
104
- logger.success(t('route_add_success').d('Add route success!'));
105
- }
106
- else {
107
- logger.error(t('route_add_fail').d('Add route fail!'));
80
+ ]);
81
+ const { inputRoute } = yield inquirer.prompt([
82
+ {
83
+ type: 'input',
84
+ name: 'inputRoute',
85
+ message: t('create_route_route').d('Enter a Route:'),
86
+ validate: (input) => {
87
+ if (!input) {
88
+ return t('route_input_required').d('Route is required');
89
+ }
90
+ return true;
91
+ }
108
92
  }
93
+ ]);
94
+ const rule = transferRouteToRuleString(inputRoute);
95
+ const req = {
96
+ RoutineName: projectConfig.name,
97
+ RouteName: routeName,
98
+ SiteId: routeSite,
99
+ RouteEnable: 'on',
100
+ Bypass: 'off',
101
+ Rule: rule
102
+ };
103
+ const res = yield server.createRoutineRoute(req);
104
+ const addSuccess = (res === null || res === void 0 ? void 0 : res.code) === 200;
105
+ if (addSuccess) {
106
+ logger.success(t('route_add_success').d('Add route success!'));
109
107
  }
110
108
  else {
111
- logger.error(t('invalid_domain').d('Input domain is invalid'));
109
+ logger.error(t('route_add_fail').d('Add route fail!'));
112
110
  }
113
111
  });
114
112
  }
@@ -9,18 +9,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { getProjectConfig } from '../../utils/fileUtils/index.js';
11
11
  import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
12
- import { ApiService } from '../../libs/apiService.js';
13
12
  import logger from '../../libs/logger.js';
14
13
  import t from '../../i18n/index.js';
15
14
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
15
+ import api from '../../libs/api.js';
16
16
  const deleteRoute = {
17
17
  command: 'delete <route>',
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('route', {
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
+ };
@@ -5,7 +5,7 @@ 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
@@ -10,10 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { getProjectConfig } from '../../utils/fileUtils/index.js';
11
11
  import Table from 'cli-table3';
12
12
  import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
13
- import { ApiService } from '../../libs/apiService.js';
14
13
  import logger from '../../libs/logger.js';
15
14
  import t from '../../i18n/index.js';
16
15
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
16
+ import api from '../../libs/api.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
  });
@@ -4,7 +4,7 @@ import t from '../../i18n/index.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
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  };
21
21
  import Table from 'cli-table3';
22
22
  import logger from '../../libs/logger.js';
23
- import { Base64 } from 'js-base64';
24
23
  import { checkIsLoginSuccess } from '../utils.js';
25
24
  import chalk from 'chalk';
26
25
  import { ApiService } from '../../libs/apiService.js';
@@ -39,7 +38,7 @@ const list = {
39
38
  export default list;
40
39
  export function handleList(argv) {
41
40
  return __awaiter(this, void 0, void 0, function* () {
42
- var _a;
41
+ var _a, _b;
43
42
  const { site } = argv, args = __rest(argv, ["site"]);
44
43
  const isSuccess = yield checkIsLoginSuccess();
45
44
  if (!isSuccess)
@@ -59,8 +58,8 @@ export function handleList(argv) {
59
58
  logger.tree(siteNameList);
60
59
  return;
61
60
  }
62
- const res = yield server.getRoutineUserInfo();
63
- const routineList = res === null || res === void 0 ? void 0 : res.Routines;
61
+ const res = yield server.listUserRoutines();
62
+ const routineList = (_b = res === null || res === void 0 ? void 0 : res.body) === null || _b === void 0 ? void 0 : _b.Routines;
64
63
  if (routineList) {
65
64
  logger.log(chalk.bold.bgGray(`📃 ${t('list_routine_name_title').d('List all of routine')}:`));
66
65
  displayRoutineList(routineList);
@@ -77,7 +76,7 @@ export function displayRoutineList(versionList) {
77
76
  table.push([
78
77
  version.RoutineName,
79
78
  moment(version.CreateTime).format('YYYY/MM/DD HH:mm:ss'),
80
- Base64.decode(version.Description)
79
+ version.Description
81
80
  ]);
82
81
  });
83
82
  console.table(table.toString());
@@ -3,7 +3,7 @@ import t from '../../i18n/index.js';
3
3
  let yargsIns;
4
4
  const siteCommand = {
5
5
  command: 'site [script]',
6
- describe: `🚀 ${t('site_describe').d('Manage your sites')}`,
6
+ describe: `📈 ${t('site_describe').d('Manage your sites')}`,
7
7
  builder: (yargs) => {
8
8
  yargsIns = yargs;
9
9
  return yargs
@@ -16,6 +16,7 @@ import chalk from 'chalk';
16
16
  import t from '../i18n/index.js';
17
17
  import { ApiService } from '../libs/apiService.js';
18
18
  import logger from '../libs/logger.js';
19
+ import api from '../libs/api.js';
19
20
  export const checkDirectory = (isCheckGit = false) => {
20
21
  const root = getRoot();
21
22
  if (fs.existsSync(projectConfigPath)) {
@@ -67,11 +68,10 @@ export const bindRoutineWithDomain = (name, domain) => __awaiter(void 0, void 0,
67
68
  }
68
69
  });
69
70
  export const getRoutineVersionList = (name) => __awaiter(void 0, void 0, void 0, function* () {
70
- var _a;
71
- const server = yield ApiService.getInstance();
72
- const req = { Name: name };
73
- const res = yield server.getRoutine(req);
74
- return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.CodeVersions) || [];
71
+ var _a, _b;
72
+ const req = { name };
73
+ const res = yield api.listRoutineCodeVersions(req);
74
+ return (_b = (_a = res.body) === null || _a === void 0 ? void 0 : _a.codeVersions) !== null && _b !== void 0 ? _b : [];
75
75
  });
76
76
  export function validName(name) {
77
77
  return /^[a-zA-Z0-9-_]+$/.test(name);
@@ -7,63 +7,52 @@ 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 React, { useState } from 'react';
11
- import { render, Text, useApp } from 'ink';
12
- import SelectInput from 'ink-select-input';
13
- import Item from './selectItem.js';
14
- import t from '../i18n/index.js';
15
- const Indicator = ({ isSelected }) => {
16
- return React.createElement(Text, null, isSelected ? '👉 ' : ' ');
17
- };
18
- const EXIT_ITEM = {
19
- label: t('exit_select_init_template').d('Exit'),
20
- key: 'exit',
21
- value: '__exit__'
22
- };
23
- const RETURN_ITEM = {
24
- label: t('return_select_init_template').d('Return'),
25
- key: 'return',
26
- value: '__return__'
27
- };
28
- const MultiLevelSelect = ({ items, handleSelect, handleExit }) => {
29
- const { exit } = useApp();
30
- const [stack, setStack] = useState([[...items, EXIT_ITEM]]);
31
- const currentItems = stack[stack.length - 1];
32
- const onSelect = (item) => {
33
- if (item.value === '__return__') {
34
- if (stack.length > 1) {
35
- // 返回上一级菜单
36
- setStack(stack.slice(0, -1));
10
+ import inquirer from 'inquirer';
11
+ import logger from '../libs/logger.js';
12
+ /**
13
+ * Perform multi-level selection and return the final selected template path
14
+ * @param items Array of selection items (including categories and sub-templates)
15
+ * @param message Initial prompt message
16
+ * @returns Selected template path, or null if the user exits
17
+ */
18
+ export default function multiLevelSelect(items_1) {
19
+ return __awaiter(this, arguments, void 0, function* (items, message = 'Select a template:') {
20
+ let currentItems = items; // Current level options
21
+ const stack = []; // Stack to store previous level options for back navigation
22
+ let selectedPath = null;
23
+ while (selectedPath === null) {
24
+ const { choice } = yield inquirer.prompt([
25
+ {
26
+ type: 'list',
27
+ name: 'choice',
28
+ message,
29
+ pageSize: 10,
30
+ choices: [
31
+ ...currentItems.map((item) => ({ name: item.label, value: item })),
32
+ ...(stack.length > 0 ? [{ name: 'Back', value: 'back' }] : []), // Show "Back" if there’s a previous level
33
+ { name: 'Exit', value: 'exit' }
34
+ ]
35
+ }
36
+ ]);
37
+ if (choice === 'exit') {
38
+ logger.log('User canceled the operation.');
39
+ return null;
40
+ }
41
+ if (choice === 'back') {
42
+ currentItems = stack.pop(); // Return to the previous level
43
+ continue;
44
+ }
45
+ // If a category with children is selected
46
+ if (choice.children && choice.children.length > 0) {
47
+ stack.push(currentItems); // Save the current level
48
+ currentItems = choice.children; // Move to the next level
49
+ message = `Select a template under ${choice.label}:`;
37
50
  }
38
51
  else {
39
- // 顶层菜单,执行退出逻辑
40
- handleExit();
41
- exit();
52
+ // A leaf node (no children) is selected, end the selection
53
+ selectedPath = choice.value;
42
54
  }
43
- return;
44
- }
45
- if (item.children && item.children.length > 0) {
46
- setStack([...stack, [...item.children, RETURN_ITEM]]); // 在子层级中添加“退出”选项
47
55
  }
48
- else {
49
- handleSelect(item);
50
- exit();
51
- }
52
- };
53
- return (React.createElement(SelectInput, { items: currentItems, onSelect: onSelect, itemComponent: Item, indicatorComponent: Indicator, limit: 10 }));
54
- };
55
- export const MultiLevelSelectComponent = (props) => __awaiter(void 0, void 0, void 0, function* () {
56
- const { items, handleSelect, handleExit } = props;
57
- return new Promise((resolve) => {
58
- const { unmount } = render(React.createElement(MultiLevelSelect, { items: items, handleSelect: (item) => {
59
- unmount();
60
- handleSelect && handleSelect(item);
61
- resolve(item);
62
- }, handleExit: () => {
63
- unmount();
64
- handleExit && handleExit();
65
- resolve(null);
66
- } }));
56
+ return selectedPath;
67
57
  });
68
- });
69
- export default MultiLevelSelectComponent;
58
+ }