esa-cli 0.0.2-beta.12 → 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.
Files changed (70) hide show
  1. package/dist/commands/commit/index.js +20 -119
  2. package/dist/commands/commit/prodBuild.js +2 -3
  3. package/dist/commands/common/routineUtils.js +276 -0
  4. package/dist/commands/config.js +1 -1
  5. package/dist/commands/deploy/helper.js +31 -36
  6. package/dist/commands/deploy/index.js +78 -165
  7. package/dist/commands/deployments/delete.js +31 -6
  8. package/dist/commands/deployments/index.js +3 -3
  9. package/dist/commands/deployments/list.js +18 -27
  10. package/dist/commands/dev/build.js +3 -3
  11. package/dist/commands/dev/doProcess.js +5 -5
  12. package/dist/commands/dev/ew2/devPack.js +17 -8
  13. package/dist/commands/dev/ew2/mock/kv.js +2 -2
  14. package/dist/commands/dev/ew2/server.js +13 -10
  15. package/dist/commands/dev/index.js +12 -12
  16. package/dist/commands/dev/mockWorker/devPack.js +16 -7
  17. package/dist/commands/dev/mockWorker/server.js +7 -6
  18. package/dist/commands/domain/add.js +3 -3
  19. package/dist/commands/domain/delete.js +3 -3
  20. package/dist/commands/domain/index.js +3 -3
  21. package/dist/commands/domain/list.js +7 -7
  22. package/dist/commands/init/helper.js +59 -9
  23. package/dist/commands/init/index.js +416 -76
  24. package/dist/commands/init/template.jsonc +34 -0
  25. package/dist/commands/lang.js +2 -2
  26. package/dist/commands/login/index.js +9 -5
  27. package/dist/commands/logout.js +6 -6
  28. package/dist/commands/route/add.js +134 -43
  29. package/dist/commands/route/delete.js +6 -6
  30. package/dist/commands/route/index.js +3 -3
  31. package/dist/commands/route/list.js +4 -4
  32. package/dist/commands/routine/delete.js +2 -2
  33. package/dist/commands/routine/index.js +3 -3
  34. package/dist/commands/routine/list.js +5 -16
  35. package/dist/commands/site/index.js +2 -2
  36. package/dist/commands/site/list.js +6 -7
  37. package/dist/commands/utils.js +55 -19
  38. package/dist/components/descriptionInput.js +1 -1
  39. package/dist/components/mutiSelectTable.js +1 -1
  40. package/dist/components/selectInput.js +2 -3
  41. package/dist/components/selectItem.js +1 -1
  42. package/dist/docs/Commands_en.md +12 -16
  43. package/dist/docs/Commands_zh_CN.md +12 -16
  44. package/dist/docs/eslint-config-en.md +1 -0
  45. package/dist/docs/eslint-config.md +73 -0
  46. package/dist/docs/init-command-quick-test.md +208 -0
  47. package/dist/docs/init-command-test-guide.md +598 -0
  48. package/dist/i18n/index.js +2 -2
  49. package/dist/i18n/locales.json +161 -9
  50. package/dist/index.js +11 -11
  51. package/dist/libs/apiService.js +177 -14
  52. package/dist/libs/git/index.js +8 -4
  53. package/dist/libs/logger.js +63 -7
  54. package/dist/libs/service.js +2 -2
  55. package/dist/libs/templates/index.js +1 -1
  56. package/dist/utils/checkAssetsExist.js +80 -0
  57. package/dist/utils/checkDevPort.js +3 -17
  58. package/dist/utils/checkEntryFileExist.js +10 -0
  59. package/dist/utils/checkIsRoutineCreated.js +17 -16
  60. package/dist/utils/checkVersion.js +1 -1
  61. package/dist/utils/compress.js +80 -0
  62. package/dist/utils/download.js +5 -5
  63. package/dist/utils/fileMd5.js +1 -1
  64. package/dist/utils/fileUtils/index.js +71 -22
  65. package/dist/utils/installDeno.js +3 -3
  66. package/dist/utils/installEw2.js +7 -7
  67. package/dist/utils/openInBrowser.js +1 -1
  68. package/package.json +9 -3
  69. package/dist/docs/Dev_en.md +0 -0
  70. package/dist/docs/Dev_zh_CN.md +0 -0
@@ -7,12 +7,12 @@ 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 { ApiService } from '../../libs/apiService.js';
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')}`,
@@ -38,13 +38,17 @@ export default login;
38
38
  export function handleLogin(argv) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  generateDefaultConfig();
41
- // Prioritize command line parameters
42
41
  const accessKeyId = argv === null || argv === void 0 ? void 0 : argv['access-key-id'];
43
42
  const accessKeySecret = argv === null || argv === void 0 ? void 0 : argv['access-key-secret'];
44
43
  if (accessKeyId && accessKeySecret) {
45
44
  yield handleLoginWithAKSK(accessKeyId, accessKeySecret);
46
45
  return;
47
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
+ }
48
52
  const cliConfig = getCliConfig();
49
53
  if (!cliConfig)
50
54
  return;
@@ -53,7 +57,7 @@ export function handleLogin(argv) {
53
57
  cliConfig.auth.accessKeyId &&
54
58
  cliConfig.auth.accessKeySecret) {
55
59
  const service = yield ApiService.getInstance();
56
- const loginStatus = yield service.checkLogin(false);
60
+ const loginStatus = yield service.checkLogin();
57
61
  if (loginStatus.success) {
58
62
  logger.warn(t('login_already').d('You are already logged in.'));
59
63
  const action = yield inquirer.prompt([
@@ -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
- describe: `🚪 ${t('logout_describe').d('Logout')}`,
15
+ describe: `📥 ${t('logout_describe').d('Logout')}`,
16
16
  builder: (yargs) => {
17
17
  return yargs;
18
18
  },
19
- handler: (argv) => {
20
- handleLogout(argv);
19
+ handler: () => {
20
+ handleLogout();
21
21
  }
22
22
  };
23
23
  export default logout;
24
- export function handleLogout(argv) {
24
+ export function handleLogout() {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  let cliConfig = getCliConfig();
27
27
  if (!cliConfig) {
@@ -7,19 +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 logger from '../../libs/logger.js';
11
- import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
12
- import { getProjectConfig } from '../../utils/fileUtils/index.js';
13
- import { ApiService } from '../../libs/apiService.js';
10
+ import inquirer from 'inquirer';
14
11
  import t from '../../i18n/index.js';
12
+ import { ApiService } from '../../libs/apiService.js';
13
+ import logger from '../../libs/logger.js';
15
14
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
16
- import inquirer from 'inquirer';
15
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
16
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
17
17
  import { transferRouteToRuleString } from './helper.js';
18
18
  const addRoute = {
19
- command: 'add [route] [site]',
20
- describe: `🚄 ${t('route_add_describe').d('Bind a Route to a routine')}`,
19
+ command: 'add',
20
+ describe: `📥 ${t('route_add_describe').d('Bind a Route to a routine')}`,
21
21
  builder: (yargs) => {
22
- return yargs.fail((msg, err, yargsIns) => {
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) => {
23
39
  if (err)
24
40
  throw err;
25
41
  if (msg) {
@@ -35,6 +51,7 @@ const addRoute = {
35
51
  };
36
52
  export function handlerAddRoute(argv) {
37
53
  return __awaiter(this, void 0, void 0, function* () {
54
+ var _a;
38
55
  if (!checkDirectory()) {
39
56
  return;
40
57
  }
@@ -53,60 +70,134 @@ export function handlerAddRoute(argv) {
53
70
  };
54
71
  const server = yield ApiService.getInstance();
55
72
  const ListSitesRes = yield server.listSites(listSitesReq);
56
- const siteList = ((ListSitesRes === null || ListSitesRes === void 0 ? void 0 : ListSitesRes.data.Sites) || []).map((i) => ({
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) => ({
57
78
  name: i.SiteName,
58
79
  value: i.SiteId
59
80
  }));
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');
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;
68
94
  }
69
- return true;
70
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];
71
104
  }
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
- }
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');
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
89
113
  }
90
- return true;
114
+ ]);
115
+ siteId = response.routeSite;
116
+ }
117
+ else {
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;
91
126
  }
92
127
  }
93
- ]);
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;
138
+ }
139
+ }
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
+ }
167
+ }
94
168
  const rule = transferRouteToRuleString(inputRoute);
169
+ if (!rule) {
170
+ logger.error(t('route_format_invalid').d('Invalid route format'));
171
+ return;
172
+ }
173
+ // 获取站点名称用于显示
174
+ const selectedSite = siteList.find((site) => site.value === siteId);
175
+ const displaySiteName = selectedSite ? selectedSite.name : siteName;
95
176
  const req = {
96
177
  RoutineName: projectConfig.name,
97
178
  RouteName: routeName,
98
- SiteId: routeSite,
179
+ SiteId: siteId,
99
180
  RouteEnable: 'on',
100
181
  Bypass: 'off',
101
182
  Rule: rule
102
183
  };
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!'));
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;
188
+ if (addSuccess) {
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}"`);
191
+ }
192
+ else {
193
+ logger.error(t('route_add_fail').d('Add route fail!'));
194
+ }
107
195
  }
108
- else {
196
+ catch (error) {
109
197
  logger.error(t('route_add_fail').d('Add route fail!'));
198
+ if (error instanceof Error) {
199
+ logger.error(`Error: ${error.message}`);
200
+ }
110
201
  }
111
202
  });
112
203
  }
@@ -7,18 +7,18 @@ 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 logger from '../../libs/logger.js';
13
10
  import t from '../../i18n/index.js';
14
- import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
15
11
  import api from '../../libs/api.js';
12
+ import logger from '../../libs/logger.js';
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 <route>',
17
+ command: 'delete <routeName>',
18
18
  describe: `🗑 ${t('route_delete_describe').d('Delete a related route')}`,
19
19
  builder: (yargs) => {
20
20
  return yargs
21
- .positional('route', {
21
+ .positional('routeName', {
22
22
  describe: t('route_delete_positional_describe').d('The name of the routes to delete'),
23
23
  type: 'string',
24
24
  demandOption: true
@@ -1,11 +1,11 @@
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]',
8
- describe: `🚄 ${t('route_describe').d('Manage the routes bound to your routine')}`,
8
+ describe: `🚀 ${t('route_describe').d('Manage the routes bound to your routine')}`,
9
9
  builder: (yargs) => {
10
10
  yargsIns = yargs;
11
11
  return yargs
@@ -7,13 +7,13 @@ 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 logger from '../../libs/logger.js';
14
11
  import t from '../../i18n/index.js';
15
- import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
16
12
  import api from '../../libs/api.js';
13
+ import logger from '../../libs/logger.js';
14
+ import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
15
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
16
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
17
17
  import { transferRuleStringToRoute } from './helper.js';
18
18
  const listRoute = {
19
19
  command: 'list',
@@ -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,10 +1,10 @@
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]',
7
- describe: `🧭 ${t('routine_describe').d('Manage your routine')}`,
7
+ describe: `🚀 ${t('routine_describe').d('Manage your routine')}`,
8
8
  builder: (yargs) => {
9
9
  yargsIns = yargs;
10
10
  return yargs
@@ -7,24 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
10
+ import chalk from 'chalk';
21
11
  import Table from 'cli-table3';
12
+ import moment from 'moment';
13
+ import t from '../../i18n/index.js';
14
+ import { ApiService } from '../../libs/apiService.js';
22
15
  import logger from '../../libs/logger.js';
23
16
  import { checkIsLoginSuccess } from '../utils.js';
24
- import chalk from 'chalk';
25
- import { ApiService } from '../../libs/apiService.js';
26
- import t from '../../i18n/index.js';
27
- import moment from 'moment';
28
17
  const list = {
29
18
  command: 'list',
30
19
  describe: `📋 ${t('list_describe').d('List all your routines')}`,
@@ -39,7 +28,7 @@ export default list;
39
28
  export function handleList(argv) {
40
29
  return __awaiter(this, void 0, void 0, function* () {
41
30
  var _a, _b;
42
- const { site } = argv, args = __rest(argv, ["site"]);
31
+ const { site } = argv;
43
32
  const isSuccess = yield checkIsLoginSuccess();
44
33
  if (!isSuccess)
45
34
  return;
@@ -1,9 +1,9 @@
1
- import siteList from './list.js';
2
1
  import t from '../../i18n/index.js';
2
+ import siteList from './list.js';
3
3
  let yargsIns;
4
4
  const siteCommand = {
5
5
  command: 'site [script]',
6
- describe: `📈 ${t('site_describe').d('Manage your sites')}`,
6
+ describe: `🚀 ${t('site_describe').d('Manage your sites')}`,
7
7
  builder: (yargs) => {
8
8
  yargsIns = yargs;
9
9
  return yargs
@@ -7,25 +7,24 @@ 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 logger from '../../libs/logger.js';
11
- import { checkIsLoginSuccess } from '../utils.js';
12
10
  import chalk from 'chalk';
13
- import { ApiService } from '../../libs/apiService.js';
14
11
  import t from '../../i18n/index.js';
12
+ import { ApiService } from '../../libs/apiService.js';
13
+ import logger from '../../libs/logger.js';
14
+ import { checkIsLoginSuccess } from '../utils.js';
15
15
  const list = {
16
16
  command: 'list',
17
17
  describe: `📋 ${t('site_describe_list').d('List all your sites')}`,
18
18
  builder: (yargs) => {
19
19
  return yargs.usage(`${t('common_usage').d('Usage')}: \$0 list []`);
20
20
  },
21
- handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
22
- handleList(argv);
21
+ handler: () => __awaiter(void 0, void 0, void 0, function* () {
22
+ handleList();
23
23
  })
24
24
  };
25
25
  export default list;
26
- export function handleList(argv) {
26
+ export function handleList() {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
- // const { site, ...args } = argv;
29
28
  var _a;
30
29
  const isSuccess = yield checkIsLoginSuccess();
31
30
  if (!isSuccess)
@@ -7,16 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import fs from 'fs';
11
10
  import { execSync } from 'child_process';
12
- import { isInstalledGit } from '../libs/git/index.js';
13
- import { getCliConfig, projectConfigPath } from '../utils/fileUtils/index.js';
14
- import { getRoot } from '../utils/fileUtils/base.js';
11
+ import fs from 'fs';
15
12
  import chalk from 'chalk';
16
13
  import t from '../i18n/index.js';
14
+ import api from '../libs/api.js';
17
15
  import { ApiService } from '../libs/apiService.js';
16
+ import { isInstalledGit } from '../libs/git/index.js';
18
17
  import logger from '../libs/logger.js';
19
- import api from '../libs/api.js';
18
+ import { getRoot } from '../utils/fileUtils/base.js';
19
+ import { getCliConfig, projectConfigPath } from '../utils/fileUtils/index.js';
20
+ import { getRoutineDetails } from './common/routineUtils.js';
20
21
  export const checkDirectory = (isCheckGit = false) => {
21
22
  const root = getRoot();
22
23
  if (fs.existsSync(projectConfigPath)) {
@@ -67,12 +68,6 @@ export const bindRoutineWithDomain = (name, domain) => __awaiter(void 0, void 0,
67
68
  logger.error(t('utils_domain_error').d('Domain is not active'));
68
69
  }
69
70
  });
70
- export const getRoutineVersionList = (name) => __awaiter(void 0, void 0, void 0, function* () {
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
- });
76
71
  export function validName(name) {
77
72
  return /^[a-zA-Z0-9-_]+$/.test(name);
78
73
  }
@@ -82,25 +77,56 @@ export function validDomain(domain) {
82
77
  }
83
78
  export function checkIsLoginSuccess() {
84
79
  return __awaiter(this, void 0, void 0, function* () {
80
+ var _a, _b;
81
+ let accessKeyId = process.env.ESA_ACCESS_KEY_ID;
82
+ let accessKeySecret = process.env.ESA_ACCESS_KEY_SECRET;
83
+ let endpoint = process.env.ESA_ENDPOINT;
85
84
  const cliConfig = getCliConfig();
86
- const namedCommand = chalk.green('esa login');
87
- if (!cliConfig || !cliConfig.auth) {
88
- return false;
85
+ if (!accessKeyId || !accessKeySecret) {
86
+ accessKeyId = (_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId;
87
+ accessKeySecret = (_b = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret;
88
+ }
89
+ if (!endpoint) {
90
+ endpoint = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.endpoint;
89
91
  }
90
- if (!cliConfig.auth.accessKeyId || !cliConfig.auth.accessKeySecret) {
92
+ const namedCommand = chalk.green('esa login');
93
+ if (!accessKeyId || !accessKeySecret) {
91
94
  logger.log(`❌ ${t('utils_login_error').d('Maybe you are not logged in yet.')}`);
92
95
  logger.log(`🔔 ${t('utils_login_error_config', { namedCommand }).d(`Please run command to login: ${namedCommand}`)}`);
93
96
  return false;
94
97
  }
98
+ return yield validateLoginCredentials(accessKeyId, accessKeySecret, endpoint, namedCommand);
99
+ });
100
+ }
101
+ /**
102
+ * 验证登录凭据的公共函数
103
+ * @param accessKeyId AccessKey ID
104
+ * @param accessKeySecret AccessKey Secret
105
+ * @param namedCommand 命令名称(用于错误提示)
106
+ * @param showError 是否显示错误信息
107
+ * @returns 登录是否成功
108
+ */
109
+ export function validateLoginCredentials(accessKeyId_1, accessKeySecret_1, endpoint_1, namedCommand_1) {
110
+ return __awaiter(this, arguments, void 0, function* (accessKeyId, accessKeySecret, endpoint, namedCommand, showError = true) {
95
111
  const server = yield ApiService.getInstance();
96
- server.updateConfig(cliConfig);
112
+ server.updateConfig({
113
+ auth: {
114
+ accessKeyId,
115
+ accessKeySecret
116
+ },
117
+ endpoint: endpoint
118
+ });
97
119
  const res = yield server.checkLogin();
98
120
  if (res.success) {
99
121
  return true;
100
122
  }
101
- logger.log(res.message || '');
102
- logger.log(`❌ ${t('utils_login_error').d('Maybe you are not logged in yet.')}`);
103
- logger.log(`🔔 ${t('utils_login_error_config', { namedCommand }).d(`Please run command to login: ${namedCommand}`)}`);
123
+ if (showError) {
124
+ logger.log(res.message || '');
125
+ logger.log(`❌ ${t('utils_login_error').d('Maybe you are not logged in yet.')}`);
126
+ if (namedCommand) {
127
+ logger.log(`🔔 ${t('utils_login_error_config', { namedCommand }).d(`Please run command to login: ${namedCommand}`)}`);
128
+ }
129
+ }
104
130
  return false;
105
131
  });
106
132
  }
@@ -138,3 +164,13 @@ export const getAllSites = () => __awaiter(void 0, void 0, void 0, function* ()
138
164
  };
139
165
  });
140
166
  });
167
+ export const getRoutineCodeVersions = (projectName) => __awaiter(void 0, void 0, void 0, function* () {
168
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
169
+ const routineDetail = yield getRoutineDetails(projectName);
170
+ const req = { name: projectName };
171
+ const res = yield api.listRoutineCodeVersions(req);
172
+ const allVersions = (_b = (_a = res.body) === null || _a === void 0 ? void 0 : _a.codeVersions) !== null && _b !== void 0 ? _b : [];
173
+ const stagingVersions = ((_g = (_f = (_e = (_d = (_c = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _c === void 0 ? void 0 : _c.Envs) === null || _d === void 0 ? void 0 : _d.find((item) => item.Env === 'staging')) === null || _e === void 0 ? void 0 : _e.CodeDeploy) === null || _f === void 0 ? void 0 : _f.CodeVersions) === null || _g === void 0 ? void 0 : _g.map((item) => item.CodeVersion)) || [];
174
+ const productionVersions = ((_m = (_l = (_k = (_j = (_h = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _h === void 0 ? void 0 : _h.Envs) === null || _j === void 0 ? void 0 : _j.find((item) => item.Env === 'production')) === null || _k === void 0 ? void 0 : _k.CodeDeploy) === null || _l === void 0 ? void 0 : _l.CodeVersions) === null || _m === void 0 ? void 0 : _m.map((item) => item.CodeVersion)) || [];
175
+ return { allVersions, stagingVersions, productionVersions };
176
+ });
@@ -7,9 +7,9 @@ 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
10
  import { Box, render, Text } from 'ink';
12
11
  import TextInput from 'ink-text-input';
12
+ import React, { useState } from 'react';
13
13
  export const DescriptionInput = ({ prompt, onSubmit, required }) => {
14
14
  const [input, setInput] = useState('');
15
15
  const [error, setError] = useState('');
@@ -7,8 +7,8 @@ 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
10
  import { Box, render, Text, useInput } from 'ink';
11
+ import React, { useState } from 'react';
12
12
  import t from '../i18n/index.js';
13
13
  export const MultiSelectTable = ({ items, itemsPerRow, onSubmit, boxWidth = 25 }) => {
14
14
  const [selectedIndexes, setSelectedIndexes] = useState(new Set());
@@ -1,7 +1,6 @@
1
- import React from 'react';
2
- import { render } from 'ink';
1
+ import { render, Text } from 'ink';
3
2
  import SelectInput from 'ink-select-input';
4
- import { Text } from 'ink';
3
+ import React from 'react';
5
4
  import Item from './selectItem.js';
6
5
  const Indicator = ({ isSelected }) => {
7
6
  return React.createElement(Text, null, isSelected ? '👉 ' : ' ');
@@ -1,5 +1,5 @@
1
- import * as React from 'react';
2
1
  import { Text } from 'ink';
2
+ import * as React from 'react';
3
3
  function Item({ isSelected = false, label }) {
4
4
  return React.createElement(Text, { color: isSelected ? 'green' : undefined }, label);
5
5
  }