esa-cli 0.0.2-beta.10 → 0.0.2-beta.13
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 +26 -115
- package/dist/commands/commit/prodBuild.js +2 -3
- package/dist/commands/common/routineUtils.js +276 -0
- package/dist/commands/config.js +1 -1
- package/dist/commands/deploy/helper.js +40 -61
- package/dist/commands/deploy/index.js +90 -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 +22 -11
- 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 +162 -27
- package/dist/commands/dev/index.js +14 -15
- package/dist/commands/dev/mockWorker/devPack.js +16 -7
- 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 +87 -13
- package/dist/commands/init/index.js +461 -57
- package/dist/commands/init/template.jsonc +34 -0
- package/dist/commands/lang.js +2 -2
- package/dist/commands/login/index.js +57 -7
- package/dist/commands/logout.js +5 -5
- package/dist/commands/route/add.js +138 -49
- package/dist/commands/route/delete.js +33 -27
- package/dist/commands/route/helper.js +124 -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 +9 -21
- package/dist/commands/site/index.js +1 -1
- package/dist/commands/site/list.js +6 -7
- package/dist/commands/utils.js +55 -19
- package/dist/components/descriptionInput.js +1 -1
- package/dist/components/mutiSelectTable.js +1 -1
- package/dist/components/selectInput.js +2 -3
- package/dist/components/selectItem.js +1 -1
- package/dist/docs/Commands_en.md +25 -15
- package/dist/docs/Commands_zh_CN.md +12 -2
- package/dist/docs/eslint-config-en.md +1 -0
- package/dist/docs/eslint-config.md +73 -0
- package/dist/docs/init-command-quick-test.md +208 -0
- package/dist/docs/init-command-test-guide.md +598 -0
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/locales.json +261 -17
- package/dist/index.js +17 -12
- package/dist/libs/api.js +32 -9
- package/dist/libs/apiService.js +258 -85
- package/dist/libs/git/index.js +8 -4
- package/dist/libs/interface.js +0 -1
- package/dist/libs/logger.js +63 -7
- package/dist/libs/service.js +2 -2
- package/dist/libs/templates/index.js +1 -1
- 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 +16 -31
- package/dist/utils/checkVersion.js +1 -1
- package/dist/utils/compress.js +80 -0
- package/dist/utils/download.js +5 -5
- package/dist/utils/fileMd5.js +1 -1
- package/dist/utils/fileUtils/index.js +71 -22
- package/dist/utils/installDeno.js +3 -3
- package/dist/utils/installEw2.js +7 -7
- package/dist/utils/openInBrowser.js +1 -1
- package/package.json +11 -6
|
@@ -7,24 +7,48 @@ 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 inquirer from 'inquirer';
|
|
11
|
-
import { getApiConfig, getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.js';
|
|
12
10
|
import chalk from 'chalk';
|
|
13
|
-
import
|
|
11
|
+
import inquirer from 'inquirer';
|
|
14
12
|
import t from '../../i18n/index.js';
|
|
13
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
15
14
|
import logger from '../../libs/logger.js';
|
|
15
|
+
import { getApiConfig, getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.js';
|
|
16
16
|
const login = {
|
|
17
17
|
command: 'login',
|
|
18
18
|
describe: `🔑 ${t('login_describe').d('Login to the server')}`,
|
|
19
|
-
builder: {
|
|
19
|
+
builder: (yargs) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
return yargs
|
|
22
|
+
.option('access-key-id', {
|
|
23
|
+
alias: 'ak',
|
|
24
|
+
describe: (_a = t('login_option_access_key_id')) === null || _a === void 0 ? void 0 : _a.d('AccessKey ID'),
|
|
25
|
+
type: 'string'
|
|
26
|
+
})
|
|
27
|
+
.option('access-key-secret', {
|
|
28
|
+
alias: 'sk',
|
|
29
|
+
describe: (_b = t('login_option_access_key_secret')) === null || _b === void 0 ? void 0 : _b.d('AccessKey Secret'),
|
|
30
|
+
type: 'string'
|
|
31
|
+
});
|
|
32
|
+
},
|
|
20
33
|
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
handleLogin();
|
|
34
|
+
handleLogin(argv);
|
|
22
35
|
})
|
|
23
36
|
};
|
|
24
37
|
export default login;
|
|
25
|
-
export function handleLogin() {
|
|
38
|
+
export function handleLogin(argv) {
|
|
26
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
40
|
generateDefaultConfig();
|
|
41
|
+
const accessKeyId = argv === null || argv === void 0 ? void 0 : argv['access-key-id'];
|
|
42
|
+
const accessKeySecret = argv === null || argv === void 0 ? void 0 : argv['access-key-secret'];
|
|
43
|
+
if (accessKeyId && accessKeySecret) {
|
|
44
|
+
yield handleLoginWithAKSK(accessKeyId, accessKeySecret);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (process.env.ESA_ACCESS_KEY_ID && process.env.ESA_ACCESS_KEY_SECRET) {
|
|
48
|
+
logger.log(`🔑 ${t('login_get_from_env').d(`Get AccessKey ID and AccessKey Secret from environment variables.`)}`);
|
|
49
|
+
yield handleLoginWithAKSK(process.env.ESA_ACCESS_KEY_ID, process.env.ESA_ACCESS_KEY_SECRET);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
28
52
|
const cliConfig = getCliConfig();
|
|
29
53
|
if (!cliConfig)
|
|
30
54
|
return;
|
|
@@ -33,7 +57,7 @@ export function handleLogin() {
|
|
|
33
57
|
cliConfig.auth.accessKeyId &&
|
|
34
58
|
cliConfig.auth.accessKeySecret) {
|
|
35
59
|
const service = yield ApiService.getInstance();
|
|
36
|
-
const loginStatus = yield service.checkLogin(
|
|
60
|
+
const loginStatus = yield service.checkLogin();
|
|
37
61
|
if (loginStatus.success) {
|
|
38
62
|
logger.warn(t('login_already').d('You are already logged in.'));
|
|
39
63
|
const action = yield inquirer.prompt([
|
|
@@ -64,6 +88,32 @@ export function handleLogin() {
|
|
|
64
88
|
}
|
|
65
89
|
});
|
|
66
90
|
}
|
|
91
|
+
function handleLoginWithAKSK(accessKeyId, accessKeySecret) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
let apiConfig = getApiConfig();
|
|
94
|
+
apiConfig.auth = {
|
|
95
|
+
accessKeyId,
|
|
96
|
+
accessKeySecret
|
|
97
|
+
};
|
|
98
|
+
try {
|
|
99
|
+
yield updateCliConfigFile({
|
|
100
|
+
auth: apiConfig.auth
|
|
101
|
+
});
|
|
102
|
+
const service = yield ApiService.getInstance();
|
|
103
|
+
service.updateConfig(apiConfig);
|
|
104
|
+
const loginStatus = yield service.checkLogin();
|
|
105
|
+
if (loginStatus.success) {
|
|
106
|
+
logger.success(t('login_success').d('Login success!'));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
logger.error(loginStatus.message || 'Login failed');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
logger.error(t('login_failed').d('An error occurred while trying to log in.'));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
67
117
|
export function getUserInputAuthInfo() {
|
|
68
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
119
|
const styledUrl = chalk.underline.blue('https://ram.console.aliyun.com/manage/ak');
|
package/dist/commands/logout.js
CHANGED
|
@@ -7,21 +7,21 @@ 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 { getCliConfig, updateCliConfigFile } from '../utils/fileUtils/index.js';
|
|
11
|
-
import logger from '../libs/logger.js';
|
|
12
10
|
import t from '../i18n/index.js';
|
|
11
|
+
import logger from '../libs/logger.js';
|
|
12
|
+
import { getCliConfig, updateCliConfigFile } from '../utils/fileUtils/index.js';
|
|
13
13
|
const logout = {
|
|
14
14
|
command: 'logout',
|
|
15
15
|
describe: `📥 ${t('logout_describe').d('Logout')}`,
|
|
16
16
|
builder: (yargs) => {
|
|
17
17
|
return yargs;
|
|
18
18
|
},
|
|
19
|
-
handler: (
|
|
20
|
-
handleLogout(
|
|
19
|
+
handler: () => {
|
|
20
|
+
handleLogout();
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
export default logout;
|
|
24
|
-
export function handleLogout(
|
|
24
|
+
export function handleLogout() {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
let cliConfig = getCliConfig();
|
|
27
27
|
if (!cliConfig) {
|
|
@@ -7,20 +7,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
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 { transferRouteToRuleString } from './helper.js';
|
|
19
18
|
const addRoute = {
|
|
20
|
-
command: 'add
|
|
19
|
+
command: 'add',
|
|
21
20
|
describe: `📥 ${t('route_add_describe').d('Bind a Route to a routine')}`,
|
|
22
21
|
builder: (yargs) => {
|
|
23
|
-
return yargs
|
|
22
|
+
return yargs
|
|
23
|
+
.option('route', {
|
|
24
|
+
describe: t('route_add_route_value_option').d('The route value. For example: example.com/*'),
|
|
25
|
+
alias: 'r',
|
|
26
|
+
type: 'string'
|
|
27
|
+
})
|
|
28
|
+
.option('site', {
|
|
29
|
+
describe: t('route_add_site_describe').d('The site to bind the route to. For example: example.com'),
|
|
30
|
+
alias: 's',
|
|
31
|
+
type: 'string'
|
|
32
|
+
})
|
|
33
|
+
.option('alias', {
|
|
34
|
+
alias: 'a',
|
|
35
|
+
describe: t('route_add_route_name_option').d('Route name (aliases)'),
|
|
36
|
+
type: 'string'
|
|
37
|
+
})
|
|
38
|
+
.fail((msg, err, yargsIns) => {
|
|
24
39
|
if (err)
|
|
25
40
|
throw err;
|
|
26
41
|
if (msg) {
|
|
@@ -36,7 +51,7 @@ const addRoute = {
|
|
|
36
51
|
};
|
|
37
52
|
export function handlerAddRoute(argv) {
|
|
38
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
var _a
|
|
54
|
+
var _a;
|
|
40
55
|
if (!checkDirectory()) {
|
|
41
56
|
return;
|
|
42
57
|
}
|
|
@@ -47,8 +62,6 @@ export function handlerAddRoute(argv) {
|
|
|
47
62
|
if (!isSuccess)
|
|
48
63
|
return;
|
|
49
64
|
yield validRoutine(projectConfig.name);
|
|
50
|
-
// input route and site
|
|
51
|
-
const { route, site } = argv;
|
|
52
65
|
const listSitesReq = {
|
|
53
66
|
SiteSearchType: 'fuzzy',
|
|
54
67
|
Status: 'active',
|
|
@@ -57,58 +70,134 @@ export function handlerAddRoute(argv) {
|
|
|
57
70
|
};
|
|
58
71
|
const server = yield ApiService.getInstance();
|
|
59
72
|
const ListSitesRes = yield server.listSites(listSitesReq);
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
if (!((_a = ListSitesRes === null || ListSitesRes === void 0 ? void 0 : ListSitesRes.data) === null || _a === void 0 ? void 0 : _a.Sites) || ListSitesRes.data.Sites.length === 0) {
|
|
74
|
+
logger.error(t('no_active_sites').d('No active sites found in your account'));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const siteList = ListSitesRes.data.Sites.map((i) => ({
|
|
78
|
+
name: i.SiteName,
|
|
62
79
|
value: i.SiteId
|
|
63
80
|
}));
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
// 获取路由名称,支持直接通过参数传入
|
|
82
|
+
let routeName = argv.alias;
|
|
83
|
+
if (!routeName) {
|
|
84
|
+
const response = yield inquirer.prompt([
|
|
85
|
+
{
|
|
86
|
+
type: 'input',
|
|
87
|
+
name: 'routeName',
|
|
88
|
+
message: t('create_route_route_name').d('Enter a Route Name (Aliases):'),
|
|
89
|
+
validate: (input) => {
|
|
90
|
+
if (!input) {
|
|
91
|
+
return t('route_name_input_required').d('Route name is required');
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
]);
|
|
97
|
+
routeName = response.routeName;
|
|
98
|
+
}
|
|
99
|
+
let siteName = argv.site;
|
|
100
|
+
let siteId;
|
|
101
|
+
if (!siteName) {
|
|
102
|
+
if (argv._.length > 2) {
|
|
103
|
+
siteName = argv._[2];
|
|
104
|
+
}
|
|
105
|
+
// 如果仍未提供站点名称,则提示选择
|
|
106
|
+
if (!siteName) {
|
|
107
|
+
const response = yield inquirer.prompt([
|
|
108
|
+
{
|
|
109
|
+
type: 'list',
|
|
110
|
+
name: 'routeSite',
|
|
111
|
+
message: t('create_route_site').d('Select a site that is active in your account:'),
|
|
112
|
+
choices: siteList
|
|
113
|
+
}
|
|
114
|
+
]);
|
|
115
|
+
siteId = response.routeSite;
|
|
76
116
|
}
|
|
77
117
|
else {
|
|
78
|
-
|
|
118
|
+
// 根据站点名称查找对应的站点ID
|
|
119
|
+
const matchedSite = siteList.find((site) => site.name === siteName);
|
|
120
|
+
if (matchedSite) {
|
|
121
|
+
siteId = matchedSite.value;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// 根据站点名称查找对应的站点ID
|
|
131
|
+
const matchedSite = siteList.find((site) => site.name === siteName);
|
|
132
|
+
if (matchedSite) {
|
|
133
|
+
siteId = matchedSite.value;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
|
|
137
|
+
return;
|
|
79
138
|
}
|
|
80
|
-
return;
|
|
81
139
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
140
|
+
// 获取路由值,支持直接通过参数传入
|
|
141
|
+
let inputRoute = argv.route;
|
|
142
|
+
if (!inputRoute) {
|
|
143
|
+
// 如果参数中提供了路由值,使用它
|
|
144
|
+
if (argv._.length > 1) {
|
|
145
|
+
inputRoute = argv._[1];
|
|
146
|
+
}
|
|
147
|
+
// 如果仍未提供路由值,则提示输入
|
|
148
|
+
if (!inputRoute) {
|
|
149
|
+
const response = yield inquirer.prompt([
|
|
150
|
+
{
|
|
151
|
+
type: 'input',
|
|
152
|
+
name: 'inputRoute',
|
|
153
|
+
message: t('create_route_route').d('Enter a Route (e.g., example.com/*):'),
|
|
154
|
+
validate: (input) => {
|
|
155
|
+
if (!input) {
|
|
156
|
+
return t('route_input_required').d('Route is required');
|
|
157
|
+
}
|
|
158
|
+
if (!input.includes('*') && !input.includes('/')) {
|
|
159
|
+
return t('route_format_invalid').d('Route format is invalid. Please include wildcard (*) or path (/)');
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
]);
|
|
165
|
+
inputRoute = response.inputRoute;
|
|
166
|
+
}
|
|
90
167
|
}
|
|
91
|
-
|
|
92
|
-
|
|
168
|
+
const rule = transferRouteToRuleString(inputRoute);
|
|
169
|
+
if (!rule) {
|
|
170
|
+
logger.error(t('route_format_invalid').d('Invalid route format'));
|
|
171
|
+
return;
|
|
93
172
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
173
|
+
// 获取站点名称用于显示
|
|
174
|
+
const selectedSite = siteList.find((site) => site.value === siteId);
|
|
175
|
+
const displaySiteName = selectedSite ? selectedSite.name : siteName;
|
|
176
|
+
const req = {
|
|
177
|
+
RoutineName: projectConfig.name,
|
|
178
|
+
RouteName: routeName,
|
|
179
|
+
SiteId: siteId,
|
|
180
|
+
RouteEnable: 'on',
|
|
181
|
+
Bypass: 'off',
|
|
182
|
+
Rule: rule
|
|
183
|
+
};
|
|
184
|
+
try {
|
|
185
|
+
logger.info(t('creating_route').d('Creating route...'));
|
|
186
|
+
const res = yield server.createRoutineRoute(req);
|
|
187
|
+
const addSuccess = (res === null || res === void 0 ? void 0 : res.code) === 200;
|
|
103
188
|
if (addSuccess) {
|
|
104
189
|
logger.success(t('route_add_success').d('Add route success!'));
|
|
190
|
+
logger.info(`Route "${routeName}" has been successfully added to routine "${projectConfig.name}" for site "${displaySiteName}"`);
|
|
105
191
|
}
|
|
106
192
|
else {
|
|
107
193
|
logger.error(t('route_add_fail').d('Add route fail!'));
|
|
108
194
|
}
|
|
109
195
|
}
|
|
110
|
-
|
|
111
|
-
logger.error(t('
|
|
196
|
+
catch (error) {
|
|
197
|
+
logger.error(t('route_add_fail').d('Add route fail!'));
|
|
198
|
+
if (error instanceof Error) {
|
|
199
|
+
logger.error(`Error: ${error.message}`);
|
|
200
|
+
}
|
|
112
201
|
}
|
|
113
202
|
});
|
|
114
203
|
}
|
|
@@ -7,20 +7,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
11
|
-
import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
|
|
12
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
13
|
-
import logger from '../../libs/logger.js';
|
|
14
10
|
import t from '../../i18n/index.js';
|
|
11
|
+
import api from '../../libs/api.js';
|
|
12
|
+
import logger from '../../libs/logger.js';
|
|
15
13
|
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
14
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
15
|
+
import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
|
|
16
16
|
const deleteRoute = {
|
|
17
|
-
command: 'delete <
|
|
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,124 @@
|
|
|
1
|
+
/* 操作符号枚举 */
|
|
2
|
+
export var OPERATOR_ENUM;
|
|
3
|
+
(function (OPERATOR_ENUM) {
|
|
4
|
+
OPERATOR_ENUM["Eq"] = "eq";
|
|
5
|
+
OPERATOR_ENUM["Ne"] = "ne";
|
|
6
|
+
OPERATOR_ENUM["Contains"] = "contains";
|
|
7
|
+
OPERATOR_ENUM["Negate_Contains"] = "negate_contains";
|
|
8
|
+
OPERATOR_ENUM["StartsWith"] = "starts_with";
|
|
9
|
+
OPERATOR_ENUM["Negate_StartsWith"] = "negate_starts_with";
|
|
10
|
+
OPERATOR_ENUM["EndsWith"] = "ends_with";
|
|
11
|
+
OPERATOR_ENUM["Negate_EndsWith"] = "negate_ends_with";
|
|
12
|
+
OPERATOR_ENUM["Matches"] = "matches";
|
|
13
|
+
OPERATOR_ENUM["Negate_Matches"] = "negate_matches";
|
|
14
|
+
OPERATOR_ENUM["In"] = "in";
|
|
15
|
+
OPERATOR_ENUM["Negate_In"] = "negate_in";
|
|
16
|
+
OPERATOR_ENUM["Gt"] = "gt";
|
|
17
|
+
OPERATOR_ENUM["Lt"] = "lt";
|
|
18
|
+
OPERATOR_ENUM["Ge"] = "ge";
|
|
19
|
+
OPERATOR_ENUM["Le"] = "le";
|
|
20
|
+
OPERATOR_ENUM["InList"] = "in_list";
|
|
21
|
+
OPERATOR_ENUM["Negate_InList"] = "negate_in_list";
|
|
22
|
+
})(OPERATOR_ENUM || (OPERATOR_ENUM = {}));
|
|
23
|
+
const RuleMatchTypeHost = 'http.host';
|
|
24
|
+
const RuleMatchTypeUriPath = 'http.request.uri.path';
|
|
25
|
+
const RuleMatchOperatorEq = OPERATOR_ENUM.Eq;
|
|
26
|
+
const RuleMatchOperatorStartsWith = OPERATOR_ENUM.StartsWith;
|
|
27
|
+
const RuleMatchOperatorEndsWith = OPERATOR_ENUM.EndsWith;
|
|
28
|
+
export const transferRouteToRuleString = (routePath) => {
|
|
29
|
+
if (!routePath) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
const index = routePath.indexOf('/');
|
|
33
|
+
let host = '';
|
|
34
|
+
let uriPath = '';
|
|
35
|
+
if (index < 0) {
|
|
36
|
+
host = routePath;
|
|
37
|
+
uriPath = '/';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
host = routePath.substring(0, index);
|
|
41
|
+
uriPath = routePath.substring(index);
|
|
42
|
+
}
|
|
43
|
+
let hostOperator = RuleMatchOperatorEq;
|
|
44
|
+
if (host.startsWith('*')) {
|
|
45
|
+
hostOperator = RuleMatchOperatorEndsWith;
|
|
46
|
+
host = host.replace(/\*/g, '');
|
|
47
|
+
}
|
|
48
|
+
let uriPathOperator = RuleMatchOperatorEq;
|
|
49
|
+
if (uriPath.endsWith('*')) {
|
|
50
|
+
uriPathOperator = RuleMatchOperatorStartsWith;
|
|
51
|
+
uriPath = uriPath.replace(/\*$/, '');
|
|
52
|
+
}
|
|
53
|
+
let ruleStr = '';
|
|
54
|
+
if (hostOperator === RuleMatchOperatorEq) {
|
|
55
|
+
if (uriPathOperator === RuleMatchOperatorEq) {
|
|
56
|
+
ruleStr = `(${RuleMatchTypeHost} ${hostOperator} "${host}" and ${RuleMatchTypeUriPath} ${uriPathOperator} "${uriPath}")`;
|
|
57
|
+
}
|
|
58
|
+
else if (uriPathOperator === RuleMatchOperatorStartsWith) {
|
|
59
|
+
ruleStr = `(${RuleMatchTypeHost} ${hostOperator} "${host}" and ${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath}, "${uriPath}"))`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (hostOperator === RuleMatchOperatorEndsWith) {
|
|
63
|
+
if (uriPathOperator === RuleMatchOperatorEq) {
|
|
64
|
+
ruleStr = `(${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost}, "${host}") and ${RuleMatchTypeUriPath} ${uriPathOperator} "${uriPath}")`;
|
|
65
|
+
}
|
|
66
|
+
else if (uriPathOperator === RuleMatchOperatorStartsWith) {
|
|
67
|
+
ruleStr = `(${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost}, "${host}") and ${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath}, "${uriPath}"))`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return ruleStr;
|
|
71
|
+
};
|
|
72
|
+
export const transferRuleStringToRoute = (ruleStr) => {
|
|
73
|
+
if (!ruleStr) {
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
// 去掉外层括号并按 " and " 分割
|
|
77
|
+
const cleanedRule = ruleStr.replace(/^\(|\)$/g, '');
|
|
78
|
+
const parts = cleanedRule.split(' and ');
|
|
79
|
+
if (parts.length !== 2) {
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
let host = '';
|
|
83
|
+
let uriPath = '';
|
|
84
|
+
// 处理host部分
|
|
85
|
+
const hostPart = parts[0].trim();
|
|
86
|
+
if (hostPart.startsWith(`${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost},`)) {
|
|
87
|
+
// host匹配eq时的逻辑
|
|
88
|
+
// ends_with(http.host, "value")
|
|
89
|
+
const match = hostPart.match(/ends_with\(http\.host,\s*"([^"]+)"\)/);
|
|
90
|
+
if (match) {
|
|
91
|
+
host = `*${match[1]}`; // 加前缀 *
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (hostPart.startsWith(`${RuleMatchTypeHost} ${RuleMatchOperatorEq}`)) {
|
|
95
|
+
// host匹配eq时的逻辑
|
|
96
|
+
// http.host eq "value"
|
|
97
|
+
const match = hostPart.match(/http\.host eq "([^"]+)"/);
|
|
98
|
+
if (match) {
|
|
99
|
+
host = match[1];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// 处理uriPath 部分
|
|
103
|
+
const uriPathPart = parts[1].trim();
|
|
104
|
+
if (uriPathPart.startsWith(`${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath},`)) {
|
|
105
|
+
// uriPath匹配startsWith时的逻辑
|
|
106
|
+
// starts_with(http.request.uri.path, "value")
|
|
107
|
+
const match = uriPathPart.match(/starts_with\(http\.request\.uri\.path,\s*"([^"]+)"\)/);
|
|
108
|
+
if (match) {
|
|
109
|
+
uriPath = `${match[1]}*`; // 加后缀 *
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (uriPathPart.startsWith(`${RuleMatchTypeUriPath} ${RuleMatchOperatorEq}`)) {
|
|
113
|
+
// uriPath匹配eq时的逻辑
|
|
114
|
+
// http.request.uri.path eq "value"
|
|
115
|
+
const match = uriPathPart.match(/http\.request\.uri\.path eq "([^"]+)"/);
|
|
116
|
+
if (match) {
|
|
117
|
+
uriPath = match[1];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (!host || !uriPath) {
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
return `${host}${uriPath}`;
|
|
124
|
+
};
|
|
@@ -1,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]',
|