esa-cli 0.0.2-beta.8 → 0.0.5

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.
@@ -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
+ };
@@ -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
  });
@@ -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
+ }
@@ -918,5 +918,65 @@
918
918
  "deno_install_success_tips": {
919
919
  "en": "Please run ${dev} again",
920
920
  "zh_CN": "请重新运行 ${dev}"
921
+ },
922
+ "no_build_script": {
923
+ "en": "No build script found in package.json, skipping build step.",
924
+ "zh_CN": "在 package.json 中未找到构建脚本,跳过构建步骤。"
925
+ },
926
+ "init_cancel": {
927
+ "en": "User canceled the operation.",
928
+ "zh_CN": "用户取消了操作。"
929
+ },
930
+ "routine_create_success": {
931
+ "en": "Routine created successfully.",
932
+ "zh_CN": "边缘函数创建成功"
933
+ },
934
+ "routine_create_fail": {
935
+ "en": "Routine created failed.",
936
+ "zh_CN": "边缘函数创建失败"
937
+ },
938
+ "create_route_route": {
939
+ "en": "Enter a Route:",
940
+ "zh_CN": ""
941
+ },
942
+ "route_name_input_required": {
943
+ "en": "Route name is required",
944
+ "zh_CN": ""
945
+ },
946
+ "create_route_mode": {
947
+ "en": "Which mode of route do you want to use?",
948
+ "zh_CN": ""
949
+ },
950
+ "create_route_site": {
951
+ "en": "Select a site that is active in your account:",
952
+ "zh_CN": ""
953
+ },
954
+ "route_input_required": {
955
+ "en": "Route is required",
956
+ "zh_CN": ""
957
+ },
958
+ "create_route_rule": {
959
+ "en": "Enter a Rule Expression:",
960
+ "zh_CN": ""
961
+ },
962
+ "rule_input_required": {
963
+ "en": "Rule is required",
964
+ "zh_CN": ""
965
+ },
966
+ "route_list_simple_title": {
967
+ "en": "Related simple mode routes",
968
+ "zh_CN": ""
969
+ },
970
+ "route_list_custom_title": {
971
+ "en": "Related custom mode routes",
972
+ "zh_CN": ""
973
+ },
974
+ "create_route_route_name": {
975
+ "en": "Enter a Route Name (Aliases):",
976
+ "zh_CN": ""
977
+ },
978
+ "no_route_found": {
979
+ "en": "No route found! Please check the route name.",
980
+ "zh_CN": ""
921
981
  }
922
982
  }
package/dist/libs/api.js CHANGED
@@ -140,9 +140,6 @@ class Client {
140
140
  const request = new $ESA.CreateRoutineRequest(params);
141
141
  return this.callApi(this.client.createRoutineWithOptions.bind(this.client), request);
142
142
  }
143
- listRoutineOptionalSpecs() {
144
- return this.callApi(this.client.listRoutineOptionalSpecsWithOptions.bind(this.client));
145
- }
146
143
  createRoutineRelatedRecord(params) {
147
144
  const request = new $ESA.CreateRoutineRelatedRecordRequest(params);
148
145
  return this.callApi(this.client.createRoutineRelatedRecordWithOptions.bind(this.client), request);
@@ -151,5 +148,34 @@ class Client {
151
148
  const request = new $ESA.DeleteRoutineRelatedRecordRequest(params);
152
149
  return this.callApi(this.client.deleteRoutineRelatedRecordWithOptions.bind(this.client), request);
153
150
  }
151
+ createRoutineRoute(params) {
152
+ const request = new $ESA.CreateRoutineRouteRequest(params);
153
+ const newRequest = Object.assign(request, { mode: 'simple' });
154
+ return this.callApi(this.client.createRoutineRouteWithOptions.bind(this.client), newRequest);
155
+ }
156
+ deleteRoutineRoute(params) {
157
+ const request = new $ESA.DeleteRoutineRouteRequest(params);
158
+ return this.callApi(this.client.deleteRoutineRouteWithOptions.bind(this.client), request);
159
+ }
160
+ getRoutineRoute(params) {
161
+ const request = new $ESA.GetRoutineRouteRequest(params);
162
+ return this.callApi(this.client.getRoutineRouteWithOptions.bind(this.client), request);
163
+ }
164
+ listSiteRoutes(params) {
165
+ const request = new $ESA.ListSiteRoutesRequest(params);
166
+ return this.callApi(this.client.listSiteRoutes.bind(this.client), request);
167
+ }
168
+ listRoutineRoutes(params) {
169
+ const request = new $ESA.ListRoutineRoutesRequest(params);
170
+ return this.callApi(this.client.listRoutineRoutes.bind(this.client), request);
171
+ }
172
+ updateRoutineRoute(params) {
173
+ const request = new $ESA.UpdateRoutineRouteRequest(params);
174
+ return this.callApi(this.client.updateRoutineRoute.bind(this.client), request);
175
+ }
176
+ listRoutineCodeVersions(params) {
177
+ const request = new $ESA.ListRoutineCodeVersionsRequest(params);
178
+ return this.callApi(this.client.listRoutineCodeVersions.bind(this.client), request);
179
+ }
154
180
  }
155
181
  export default new Client();