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.
@@ -9,43 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import fs from 'fs-extra';
11
11
  import path from 'path';
12
+ import inquirer from 'inquirer';
13
+ import { exit } from 'process';
12
14
  import Template from '../../libs/templates/index.js';
13
15
  import { installGit } from '../../libs/git/index.js';
14
- import { descriptionInput } from '../../components/descriptionInput.js';
16
+ import multiLevelSelect from '../../components/mutiLevelSelect.js';
15
17
  import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
16
18
  import t from '../../i18n/index.js';
17
19
  import logger from '../../libs/logger.js';
18
- import SelectItems from '../../components/selectInput.js';
19
20
  import { quickDeploy } from '../deploy/index.js';
20
- import chalk from 'chalk';
21
21
  import { ApiService } from '../../libs/apiService.js';
22
- import { exit } from 'process';
23
22
  import { checkRoutineExist } from '../../utils/checkIsRoutineCreated.js';
24
- import { execSync } from 'child_process';
25
- import MultiLevelSelect from '../../components/mutiLevelSelect.js';
26
- import { getDirName } from '../../utils/fileUtils/base.js';
27
- import { yesNoPromptAndExecute } from '../deploy/helper.js';
28
23
  import { checkIsLoginSuccess } from '../utils.js';
29
- export const getTemplateInstances = (templateHubPath) => {
30
- return fs
31
- .readdirSync(templateHubPath)
32
- .filter((item) => {
33
- const itemPath = path.join(templateHubPath, item);
34
- return (fs.statSync(itemPath).isDirectory() &&
35
- !['.git', 'node_modules', 'lib'].includes(item));
36
- })
37
- .map((item) => {
38
- var _a;
39
- const projectPath = path.join(templateHubPath, item);
40
- const projectConfig = getProjectConfig(projectPath);
41
- const templateName = (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '';
42
- return new Template(projectPath, templateName);
43
- });
44
- };
45
- const secondSetOfItems = [
46
- { label: 'Yes', value: 'yesInstall' },
47
- { label: 'No', value: 'noInstall' }
48
- ];
24
+ import chalk from 'chalk';
25
+ import { checkAndUpdatePackage, getTemplateInstances, preInstallDependencies, transferTemplatesToSelectItem } from './helper.js';
49
26
  const init = {
50
27
  command: 'init',
51
28
  describe: `📥 ${t('init_describe').d('Initialize a routine with a template')}`,
@@ -58,186 +35,141 @@ const init = {
58
35
  },
59
36
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
60
37
  yield handleInit(argv);
38
+ exit(0);
61
39
  })
62
40
  };
63
41
  export default init;
64
- export const preInstallDependencies = (targetPath) => __awaiter(void 0, void 0, void 0, function* () {
65
- const packageJsonPath = path.join(targetPath, 'package.json');
66
- if (fs.existsSync(packageJsonPath)) {
67
- logger.log(t('init_install_dependence').d('⌛️ Installing dependencies...'));
68
- execSync('npm install esa-template', {
69
- stdio: 'inherit',
70
- cwd: targetPath
71
- });
72
- logger.success(t('init_install_dependencies_success').d('Dependencies installed successfully.'));
73
- logger.log(t('init_build_project').d('⌛️ Building project...'));
74
- execSync('npm run build', { stdio: 'inherit', cwd: targetPath });
75
- logger.success(t('init_build_project_success').d('Project built successfully.'));
76
- }
77
- });
78
- export const transferTemplatesToSelectItem = (configs, templateInstanceList, lang) => {
79
- if (!configs)
80
- return [];
81
- return configs.map((config) => {
82
- var _a, _b;
83
- const name = config.Title_EN;
84
- const value = (_b = (_a = templateInstanceList.find((template) => {
85
- return name === template.title;
86
- })) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : '';
87
- const children = transferTemplatesToSelectItem(config.children, templateInstanceList);
88
- return {
89
- label: lang === 'en' ? config.Title_EN : config.Title_ZH,
90
- value: value,
91
- key: name,
92
- children
93
- };
94
- });
95
- };
96
- function checkAndUpdatePackage(packageName) {
42
+ export function promptProjectName() {
97
43
  return __awaiter(this, void 0, void 0, function* () {
98
- try {
99
- // 获取当前安装的版本
100
- const __dirname = getDirName(import.meta.url);
101
- const packageJsonPath = path.join(__dirname, '../../../');
102
- const versionInfo = execSync(`npm list ${packageName}`, {
103
- cwd: packageJsonPath
104
- }).toString();
105
- const match = versionInfo.match(new RegExp(`(${packageName})@([0-9.]+)`));
106
- const currentVersion = match ? match[2] : '';
107
- // 获取最新版本
108
- const latestVersion = execSync(`npm view ${packageName} version`)
109
- .toString()
110
- .trim();
111
- if (currentVersion !== latestVersion) {
112
- logger.log(t('display_current_esa_template_version').d(`Current esa-template version:`) +
113
- chalk.green(currentVersion) +
114
- ' ' +
115
- t('display_latest_esa_template_version').d(`Latest esa-template version:`) +
116
- chalk.green(latestVersion));
117
- yield yesNoPromptAndExecute(t('is_update_to_latest_version').d('Do you want to update templates to latest version?'), () => __awaiter(this, void 0, void 0, function* () {
118
- logger.log(t('updating_esa_template_to_latest_version', { packageName }).d(`Updating ${packageName} to the latest version...`));
119
- execSync(`rm -rf node_modules/${packageName} &&rm -rf package-lock.json &&npm install ${packageName}@latest`, {
120
- cwd: packageJsonPath
121
- });
122
- logger.log(t('updated_esa_template_to_latest_version', { packageName }).d(`${packageName} updated successfully`));
44
+ const { name } = yield inquirer.prompt([
45
+ {
46
+ type: 'input',
47
+ name: 'name',
48
+ message: `🖊️ ${t('init_input_name').d('Enter the name of edgeRoutine:')}`,
49
+ validate: (input) => {
50
+ const regex = /^[a-z0-9-]{2,}$/;
51
+ if (!regex.test(input)) {
52
+ return t('init_name_error').d('Error: The project name must be at least 2 characters long and can only contain lowercase letters, numbers, and hyphens.');
53
+ }
123
54
  return true;
124
- }));
55
+ }
125
56
  }
126
- else {
127
- logger.log(t('esa_template_is_latest_version', { packageName }).d(`${packageName} is latest.`));
57
+ ]);
58
+ return name;
59
+ });
60
+ }
61
+ export function prepareTemplateItems() {
62
+ var _a;
63
+ const templateInstanceList = getTemplateInstances(templateHubPath);
64
+ const templateConfig = getTemplatesConfig();
65
+ const cliConfig = getCliConfig();
66
+ const lang = (_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) !== null && _a !== void 0 ? _a : 'en';
67
+ return transferTemplatesToSelectItem(templateConfig, templateInstanceList, lang);
68
+ }
69
+ export function selectTemplate(items) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const selectedTemplatePath = yield multiLevelSelect(items, 'Select a template:');
72
+ if (!selectedTemplatePath) {
73
+ logger.log(t('init_cancel').d('User canceled the operation.'));
74
+ return null;
75
+ }
76
+ return selectedTemplatePath;
77
+ });
78
+ }
79
+ export function initializeProject(selectedTemplatePath, name) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const selectTemplate = new Template(selectedTemplatePath, name);
82
+ const projectConfig = getProjectConfig(selectedTemplatePath);
83
+ if (!projectConfig) {
84
+ logger.notInProject();
85
+ return null;
86
+ }
87
+ const targetPath = path.join(process.cwd(), name);
88
+ if (fs.existsSync(targetPath)) {
89
+ logger.error(t('already_exist_file_error').d('Error: The project already exists. It looks like a folder named "<project-name>" is already present in the current directory. Please try the following options: 1. Choose a different project name. 2. Delete the existing folder if it\'s not needed: `rm -rf <project-name>` (use with caution!). 3. Move to a different directory before running the init command.'));
90
+ return null;
91
+ }
92
+ yield fs.copy(selectedTemplatePath, targetPath);
93
+ projectConfig.name = name;
94
+ yield updateProjectConfigFile(projectConfig, targetPath);
95
+ yield preInstallDependencies(targetPath);
96
+ return { template: selectTemplate, targetPath };
97
+ });
98
+ }
99
+ export function handleGitInitialization(targetPath) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ const { initGit } = yield inquirer.prompt([
102
+ {
103
+ type: 'list',
104
+ name: 'initGit',
105
+ message: t('init_git').d('Do you want to init git in your project?'),
106
+ choices: ['Yes', 'No']
128
107
  }
108
+ ]);
109
+ if (initGit === 'Yes') {
110
+ installGit(targetPath);
111
+ }
112
+ else {
113
+ logger.log(t('init_skip_git').d('Git installation was skipped.'));
129
114
  }
130
- catch (error) {
131
- if (error instanceof Error) {
132
- logger.error('检测和更新包时发生错误,跳过更新模版');
115
+ });
116
+ }
117
+ export function handleDeployment(targetPath, projectConfig) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ var _a, _b, _c;
120
+ const isLoginSuccess = yield checkIsLoginSuccess();
121
+ if (!isLoginSuccess) {
122
+ logger.log(chalk.yellow(t('not_login_auto_deploy').d('You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.')));
123
+ return;
124
+ }
125
+ const { deploy } = yield inquirer.prompt([
126
+ {
127
+ type: 'list',
128
+ name: 'deploy',
129
+ message: t('auto_deploy').d('Do you want to deploy your project?'),
130
+ choices: ['Yes', 'No']
133
131
  }
132
+ ]);
133
+ if (deploy === 'Yes') {
134
+ yield checkRoutineExist((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '', targetPath);
135
+ yield quickDeploy(targetPath, projectConfig);
136
+ const service = yield ApiService.getInstance();
137
+ const res = yield service.getRoutine({ Name: (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '' });
138
+ const defaultUrl = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.DefaultRelatedRecord;
139
+ const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
140
+ logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
141
+ logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
134
142
  }
135
143
  });
136
144
  }
137
145
  export function handleInit(argv) {
138
146
  return __awaiter(this, void 0, void 0, function* () {
139
- var _a;
140
- const { config } = argv;
141
- // 更新template npm包
147
+ // Update the template package (currently commented out)
142
148
  yield checkAndUpdatePackage('esa-template');
143
- if (config !== undefined) {
149
+ // If config option is provided, generate config file and exit
150
+ const config = getCliConfig();
151
+ if (config === undefined) {
144
152
  yield generateConfigFile(String(config));
145
- return;
146
153
  }
147
- const name = yield descriptionInput(`🖊️ ${t('init_input_name').d('Enter the name of edgeRoutine:')}`, true);
148
- const regex = /^[a-z0-9-]{2,}$/;
149
- if (!regex.test(name)) {
150
- logger.error(t('init_name_error').d('Error: The project name must be at least 2 characters long and can only contain lowercase letters, numbers, and hyphens.'));
154
+ const name = yield promptProjectName();
155
+ const templateItems = prepareTemplateItems();
156
+ // Select a template
157
+ const selectedTemplatePath = yield selectTemplate(templateItems);
158
+ if (!selectedTemplatePath) {
151
159
  return;
152
160
  }
153
- const templateInstanceList = getTemplateInstances(templateHubPath);
154
- const templateConfig = getTemplatesConfig();
155
- const cliConfig = getCliConfig();
156
- const lang = (_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) !== null && _a !== void 0 ? _a : 'en';
157
- const firstSetOfItems = transferTemplatesToSelectItem(templateConfig, templateInstanceList, lang);
158
- let selectTemplate;
159
- let targetPath;
160
- let projectConfig;
161
- const preInstallDependencies = () => __awaiter(this, void 0, void 0, function* () {
162
- const packageJsonPath = path.join(targetPath, 'package.json');
163
- if (fs.existsSync(packageJsonPath)) {
164
- logger.log('Install dependencies');
165
- logger.log(t('init_install_dependence').d('⌛️ Installing dependencies...'));
166
- execSync('npm install', { stdio: 'inherit', cwd: targetPath });
167
- logger.success(t('init_install_dependencies_success').d('Dependencies installed successfully.'));
168
- logger.log(t('init_build_project').d('⌛️ Building project...'));
169
- execSync('npm run build', { stdio: 'inherit', cwd: targetPath });
170
- logger.success(t('init_build_project_success').d('Project built successfully.'));
171
- }
172
- });
173
- const handleFirstSelection = (item) => __awaiter(this, void 0, void 0, function* () {
174
- if (item.key === 'exit') {
175
- process.exit(0);
176
- }
177
- const configPath = item.value;
178
- selectTemplate = new Template(configPath, name);
179
- projectConfig = getProjectConfig(configPath);
180
- if (!projectConfig)
181
- return logger.notInProject();
182
- const newPath = process.cwd() + '/' + name;
183
- targetPath = newPath;
184
- if (fs.existsSync(newPath)) {
185
- logger.error(t('already_exist_file_error').d('Error: The project already exists. It looks like a folder named "<project-name>" is already present in the current directory. Please try the following options: 1. Choose a different project name. 2. Delete the existing folder if it\'s not needed: `rm -rf <project-name>` (use with caution!). 3. Move to a different directory before running the init command.'));
186
- exit(0);
187
- }
188
- yield fs.copy(configPath, newPath);
189
- projectConfig.name = name;
190
- updateProjectConfigFile(projectConfig, newPath);
191
- preInstallDependencies();
192
- logger.log(t('init_git').d('Do you want to init git in your project?'));
193
- SelectItems({
194
- items: secondSetOfItems,
195
- handleSelect: handleSecondSelection
196
- });
197
- });
198
- const handleSecondSelection = (item) => __awaiter(this, void 0, void 0, function* () {
199
- if (item.value === 'yesInstall') {
200
- installGit(targetPath);
201
- }
202
- else {
203
- logger.log(t('init_skip_git').d('Git installation was skipped.'));
204
- }
205
- const isLoginSuccess = yield checkIsLoginSuccess();
206
- if (!isLoginSuccess) {
207
- logger.log(chalk.yellow(t('not_login_auto_deploy').d('You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.')));
208
- process.exit(0);
209
- }
210
- logger.log(t('auto_deploy').d('Do you want to deploy your project?'));
211
- SelectItems({
212
- items: secondSetOfItems,
213
- handleSelect: handleThirdSelection
214
- });
215
- });
216
- const handleThirdSelection = (item) => __awaiter(this, void 0, void 0, function* () {
217
- var _a, _b, _c;
218
- // 选择自动生成版本并发布
219
- if (item.value === 'yesInstall') {
220
- yield checkRoutineExist((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '', targetPath);
221
- projectConfig && (yield quickDeploy(targetPath, projectConfig));
222
- const service = yield ApiService.getInstance();
223
- const res = yield service.getRoutine({ Name: (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '' });
224
- const defaultUrl = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.DefaultRelatedRecord;
225
- const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
226
- logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
227
- logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
228
- }
229
- selectTemplate.printSummary();
230
- exit(0);
231
- });
232
- try {
233
- MultiLevelSelect({
234
- items: firstSetOfItems,
235
- handleSelect: handleFirstSelection
236
- });
237
- }
238
- catch (error) {
239
- logger.error(t('init_error').d('An error occurred while initializing.'));
240
- console.log(error);
161
+ // Initialize project files and configuration
162
+ const project = yield initializeProject(selectedTemplatePath, name);
163
+ if (!project) {
164
+ return;
241
165
  }
166
+ const { template, targetPath } = project;
167
+ // Handle Git initialization
168
+ yield handleGitInitialization(targetPath);
169
+ // Handle deployment
170
+ const projectConfig = getProjectConfig(targetPath);
171
+ yield handleDeployment(targetPath, projectConfig);
172
+ template.printSummary();
173
+ return;
242
174
  });
243
175
  }
@@ -7,15 +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 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
20
  describe: `📥 ${t('route_add_describe').d('Bind a Route to a routine')}`,
@@ -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
  }