esa-cli 0.0.2-beta.2 → 0.0.2-beta.20
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.
- package/dist/commands/commit/index.js +48 -115
- package/dist/commands/commit/prodBuild.js +2 -3
- package/dist/commands/common/constant.js +0 -19
- package/dist/commands/common/utils.js +416 -0
- package/dist/commands/config.js +1 -1
- package/dist/commands/deploy/helper.js +51 -72
- package/dist/commands/deploy/index.js +50 -188
- package/dist/commands/deployments/delete.js +32 -22
- package/dist/commands/deployments/index.js +2 -2
- package/dist/commands/deployments/list.js +22 -38
- package/dist/commands/dev/build.js +3 -3
- package/dist/commands/dev/doProcess.js +5 -5
- package/dist/commands/dev/ew2/cacheService.js +33 -0
- package/dist/commands/dev/ew2/devEntry.js +2 -1
- package/dist/commands/dev/ew2/devPack.js +39 -43
- package/dist/commands/dev/ew2/kvService.js +27 -0
- package/dist/commands/dev/ew2/mock/cache.js +99 -15
- package/dist/commands/dev/ew2/mock/kv.js +142 -21
- package/dist/commands/dev/ew2/server.js +165 -29
- package/dist/commands/dev/index.js +17 -17
- package/dist/commands/dev/mockWorker/devPack.js +35 -24
- package/dist/commands/dev/mockWorker/server.js +7 -6
- package/dist/commands/domain/add.js +2 -2
- package/dist/commands/domain/delete.js +7 -7
- package/dist/commands/domain/index.js +2 -2
- package/dist/commands/domain/list.js +10 -10
- package/dist/commands/init/helper.js +759 -0
- package/dist/commands/init/index.js +88 -220
- package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
- package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
- package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
- package/dist/commands/init/template.jsonc +84 -0
- package/dist/commands/init/types.js +1 -0
- package/dist/commands/lang.js +2 -2
- package/dist/commands/login/index.js +74 -34
- package/dist/commands/logout.js +5 -5
- package/dist/commands/route/add.js +105 -49
- package/dist/commands/route/delete.js +33 -27
- package/dist/commands/route/helper.js +123 -0
- package/dist/commands/route/index.js +2 -2
- package/dist/commands/route/list.js +56 -17
- package/dist/commands/routine/delete.js +2 -2
- package/dist/commands/routine/index.js +2 -2
- package/dist/commands/routine/list.js +43 -37
- package/dist/commands/site/index.js +1 -1
- package/dist/commands/site/list.js +6 -7
- package/dist/commands/utils.js +59 -23
- package/dist/components/descriptionInput.js +1 -1
- package/dist/components/filterSelector.js +1 -1
- package/dist/components/mutiLevelSelect.js +43 -55
- package/dist/components/mutiSelectTable.js +1 -1
- package/dist/components/routeBuilder.js +68 -0
- package/dist/components/selectInput.js +2 -3
- package/dist/components/selectItem.js +1 -1
- package/dist/docs/Commands_en.md +142 -131
- package/dist/docs/Commands_zh_CN.md +139 -127
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/locales.json +435 -23
- package/dist/index.js +27 -20
- package/dist/libs/api.js +32 -9
- package/dist/libs/apiService.js +267 -88
- package/dist/libs/git/index.js +86 -9
- package/dist/libs/interface.js +0 -1
- package/dist/libs/logger.js +162 -10
- package/dist/libs/service.js +2 -2
- package/dist/libs/templates/index.js +3 -2
- package/dist/utils/checkAssetsExist.js +80 -0
- package/dist/utils/checkDevPort.js +3 -17
- package/dist/utils/checkEntryFileExist.js +10 -0
- package/dist/utils/checkIsRoutineCreated.js +28 -27
- package/dist/utils/checkVersion.js +119 -1
- package/dist/utils/command.js +149 -0
- package/dist/utils/compress.js +136 -0
- package/dist/utils/download.js +182 -0
- package/dist/utils/fileMd5.js +1 -1
- package/dist/utils/fileUtils/base.js +1 -1
- package/dist/utils/fileUtils/index.js +136 -44
- package/dist/utils/installDeno.js +8 -8
- package/dist/utils/installEw2.js +7 -7
- package/dist/utils/openInBrowser.js +1 -1
- package/dist/utils/prompt.js +97 -0
- package/package.json +19 -12
|
@@ -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
|
|
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 {
|
|
17
|
-
import
|
|
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 { routeBuilder } from '../../components/routeBuilder.js';
|
|
18
|
+
import { transferRouteToRuleString } from './helper.js';
|
|
19
19
|
const addRoute = {
|
|
20
|
-
command: 'add
|
|
20
|
+
command: 'add',
|
|
21
21
|
describe: `📥 ${t('route_add_describe').d('Bind a Route to a routine')}`,
|
|
22
22
|
builder: (yargs) => {
|
|
23
|
-
return yargs
|
|
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
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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('
|
|
119
|
+
logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
|
|
120
|
+
return;
|
|
79
121
|
}
|
|
80
|
-
return;
|
|
81
122
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
136
|
+
const rule = transferRouteToRuleString(inputRoute);
|
|
137
|
+
if (!rule) {
|
|
138
|
+
logger.error(t('route_format_invalid').d('Invalid route format'));
|
|
139
|
+
return;
|
|
93
140
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
111
|
-
logger.error(t('
|
|
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 <
|
|
17
|
+
command: 'delete <routeName>',
|
|
18
18
|
describe: `🗑 ${t('route_delete_describe').d('Delete a related route')}`,
|
|
19
19
|
builder: (yargs) => {
|
|
20
|
-
return yargs
|
|
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
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
66
|
-
const isDeleteSuccess =
|
|
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,7 +1,7 @@
|
|
|
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]',
|
|
@@ -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
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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: [
|
|
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,6 +1,6 @@
|
|
|
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]',
|