esa-cli 0.0.2-beta.2 → 0.0.2-beta.21

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 (80) hide show
  1. package/dist/commands/commit/index.js +45 -117
  2. package/dist/commands/commit/prodBuild.js +2 -3
  3. package/dist/commands/common/constant.js +0 -19
  4. package/dist/commands/common/utils.js +419 -0
  5. package/dist/commands/config.js +1 -1
  6. package/dist/commands/deploy/helper.js +51 -72
  7. package/dist/commands/deploy/index.js +48 -187
  8. package/dist/commands/deployments/delete.js +32 -22
  9. package/dist/commands/deployments/index.js +3 -3
  10. package/dist/commands/deployments/list.js +22 -38
  11. package/dist/commands/dev/build.js +3 -3
  12. package/dist/commands/dev/doProcess.js +5 -5
  13. package/dist/commands/dev/ew2/cacheService.js +33 -0
  14. package/dist/commands/dev/ew2/devEntry.js +2 -1
  15. package/dist/commands/dev/ew2/devPack.js +30 -34
  16. package/dist/commands/dev/ew2/kvService.js +46 -0
  17. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  18. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  19. package/dist/commands/dev/ew2/server.js +165 -28
  20. package/dist/commands/dev/index.js +16 -16
  21. package/dist/commands/dev/mockWorker/devPack.js +32 -21
  22. package/dist/commands/dev/mockWorker/server.js +7 -6
  23. package/dist/commands/domain/add.js +3 -3
  24. package/dist/commands/domain/delete.js +7 -7
  25. package/dist/commands/domain/index.js +3 -3
  26. package/dist/commands/domain/list.js +10 -10
  27. package/dist/commands/init/helper.js +761 -0
  28. package/dist/commands/init/index.js +88 -220
  29. package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
  30. package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
  31. package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
  32. package/dist/commands/init/template.jsonc +84 -0
  33. package/dist/commands/init/types.js +1 -0
  34. package/dist/commands/lang.js +2 -2
  35. package/dist/commands/login/index.js +74 -34
  36. package/dist/commands/logout.js +6 -6
  37. package/dist/commands/route/add.js +138 -49
  38. package/dist/commands/route/delete.js +33 -27
  39. package/dist/commands/route/helper.js +124 -0
  40. package/dist/commands/route/index.js +3 -3
  41. package/dist/commands/route/list.js +56 -17
  42. package/dist/commands/routine/delete.js +2 -2
  43. package/dist/commands/routine/index.js +3 -3
  44. package/dist/commands/routine/list.js +9 -21
  45. package/dist/commands/site/index.js +2 -2
  46. package/dist/commands/site/list.js +6 -7
  47. package/dist/commands/utils.js +55 -19
  48. package/dist/components/descriptionInput.js +1 -1
  49. package/dist/components/mutiLevelSelect.js +43 -55
  50. package/dist/components/mutiSelectTable.js +1 -1
  51. package/dist/components/selectInput.js +2 -3
  52. package/dist/components/selectItem.js +1 -1
  53. package/dist/docs/Commands_en.md +142 -131
  54. package/dist/docs/Commands_zh_CN.md +139 -127
  55. package/dist/i18n/index.js +2 -2
  56. package/dist/i18n/locales.json +401 -21
  57. package/dist/index.js +27 -20
  58. package/dist/libs/api.js +32 -9
  59. package/dist/libs/apiService.js +262 -84
  60. package/dist/libs/git/index.js +86 -9
  61. package/dist/libs/interface.js +0 -1
  62. package/dist/libs/logger.js +162 -10
  63. package/dist/libs/service.js +2 -2
  64. package/dist/libs/templates/index.js +3 -2
  65. package/dist/utils/checkAssetsExist.js +80 -0
  66. package/dist/utils/checkDevPort.js +3 -17
  67. package/dist/utils/checkEntryFileExist.js +10 -0
  68. package/dist/utils/checkIsRoutineCreated.js +27 -26
  69. package/dist/utils/checkVersion.js +119 -1
  70. package/dist/utils/command.js +149 -0
  71. package/dist/utils/compress.js +136 -0
  72. package/dist/utils/download.js +182 -0
  73. package/dist/utils/fileMd5.js +1 -1
  74. package/dist/utils/fileUtils/base.js +1 -1
  75. package/dist/utils/fileUtils/index.js +69 -28
  76. package/dist/utils/installDeno.js +8 -8
  77. package/dist/utils/installEw2.js +7 -7
  78. package/dist/utils/openInBrowser.js +1 -1
  79. package/dist/utils/prompt.js +97 -0
  80. package/package.json +20 -12
@@ -7,25 +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
- import { Base64 } from 'js-base64';
24
16
  import { checkIsLoginSuccess } from '../utils.js';
25
- import chalk from 'chalk';
26
- import { ApiService } from '../../libs/apiService.js';
27
- import t from '../../i18n/index.js';
28
- import moment from 'moment';
29
17
  const list = {
30
18
  command: 'list',
31
19
  describe: `📋 ${t('list_describe').d('List all your routines')}`,
@@ -39,8 +27,8 @@ const list = {
39
27
  export default list;
40
28
  export function handleList(argv) {
41
29
  return __awaiter(this, void 0, void 0, function* () {
42
- var _a;
43
- const { site } = argv, args = __rest(argv, ["site"]);
30
+ var _a, _b;
31
+ const { site } = argv;
44
32
  const isSuccess = yield checkIsLoginSuccess();
45
33
  if (!isSuccess)
46
34
  return;
@@ -59,8 +47,8 @@ export function handleList(argv) {
59
47
  logger.tree(siteNameList);
60
48
  return;
61
49
  }
62
- const res = yield server.getRoutineUserInfo();
63
- const routineList = res === null || res === void 0 ? void 0 : res.Routines;
50
+ const res = yield server.listUserRoutines();
51
+ const routineList = (_b = res === null || res === void 0 ? void 0 : res.body) === null || _b === void 0 ? void 0 : _b.Routines;
64
52
  if (routineList) {
65
53
  logger.log(chalk.bold.bgGray(`📃 ${t('list_routine_name_title').d('List all of routine')}:`));
66
54
  displayRoutineList(routineList);
@@ -77,7 +65,7 @@ export function displayRoutineList(versionList) {
77
65
  table.push([
78
66
  version.RoutineName,
79
67
  moment(version.CreateTime).format('YYYY/MM/DD HH:mm:ss'),
80
- Base64.decode(version.Description)
68
+ version.Description
81
69
  ]);
82
70
  });
83
71
  console.table(table.toString());
@@ -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,15 +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';
18
+ import { getRoot } from '../utils/fileUtils/base.js';
19
+ import { getCliConfig, projectConfigPath } from '../utils/fileUtils/index.js';
20
+ import { getRoutineDetails } from './common/utils.js';
19
21
  export const checkDirectory = (isCheckGit = false) => {
20
22
  const root = getRoot();
21
23
  if (fs.existsSync(projectConfigPath)) {
@@ -66,13 +68,6 @@ export const bindRoutineWithDomain = (name, domain) => __awaiter(void 0, void 0,
66
68
  logger.error(t('utils_domain_error').d('Domain is not active'));
67
69
  }
68
70
  });
69
- export const getRoutineVersionList = (name) => __awaiter(void 0, void 0, void 0, function* () {
70
- var _a;
71
- const server = yield ApiService.getInstance();
72
- const req = { Name: name };
73
- const res = yield server.getRoutine(req);
74
- return ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.CodeVersions) || [];
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,63 +7,51 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import React, { useState } from 'react';
11
- import { render, Text, useApp } from 'ink';
12
- import SelectInput from 'ink-select-input';
13
- import Item from './selectItem.js';
14
- import t from '../i18n/index.js';
15
- const Indicator = ({ isSelected }) => {
16
- return React.createElement(Text, null, isSelected ? '👉 ' : ' ');
17
- };
18
- const EXIT_ITEM = {
19
- label: t('exit_select_init_template').d('Exit'),
20
- key: 'exit',
21
- value: '__exit__'
22
- };
23
- const RETURN_ITEM = {
24
- label: t('return_select_init_template').d('Return'),
25
- key: 'return',
26
- value: '__return__'
27
- };
28
- const MultiLevelSelect = ({ items, handleSelect, handleExit }) => {
29
- const { exit } = useApp();
30
- const [stack, setStack] = useState([[...items, EXIT_ITEM]]);
31
- const currentItems = stack[stack.length - 1];
32
- const onSelect = (item) => {
33
- if (item.value === '__return__') {
34
- if (stack.length > 1) {
35
- // 返回上一级菜单
36
- setStack(stack.slice(0, -1));
10
+ import { isCancel, select as clackSelect } from '@clack/prompts';
11
+ import logger from '../libs/logger.js';
12
+ /**
13
+ * Perform multi-level selection and return the final selected template path
14
+ * @param items Array of selection items (including categories and sub-templates)
15
+ * @param message Initial prompt message
16
+ * @returns Selected template path, or null if the user exits
17
+ */
18
+ export default function multiLevelSelect(items_1) {
19
+ return __awaiter(this, arguments, void 0, function* (items, message = 'Select a template:') {
20
+ let currentItems = items; // Current level options
21
+ const stack = []; // Stack to store previous level options for back navigation
22
+ let selectedPath = null;
23
+ while (selectedPath === null) {
24
+ const choice = (yield clackSelect({
25
+ message,
26
+ options: [
27
+ ...currentItems.map((item) => ({
28
+ label: item.label,
29
+ value: item.value,
30
+ hint: item.hint
31
+ })),
32
+ ...(stack.length > 0 ? [{ label: 'Back', value: '__back__' }] : [])
33
+ ]
34
+ }));
35
+ if (isCancel(choice)) {
36
+ logger.log('User canceled the operation.');
37
+ return null;
38
+ }
39
+ if (choice === '__back__') {
40
+ currentItems = stack.pop(); // Return to the previous level
41
+ continue;
42
+ }
43
+ // If a category with children is selected
44
+ const selected = currentItems.find((i) => i.value === choice);
45
+ if (selected && selected.children && selected.children.length > 0) {
46
+ stack.push(currentItems); // Save the current level
47
+ currentItems = selected.children; // Move to the next level
48
+ message = `Select a template under ${selected.label}:`;
37
49
  }
38
50
  else {
39
- // 顶层菜单,执行退出逻辑
40
- handleExit();
41
- exit();
51
+ // A leaf node (no children) is selected, end the selection
52
+ selectedPath = choice;
42
53
  }
43
- return;
44
- }
45
- if (item.children && item.children.length > 0) {
46
- setStack([...stack, [...item.children, RETURN_ITEM]]); // 在子层级中添加“退出”选项
47
54
  }
48
- else {
49
- handleSelect(item);
50
- exit();
51
- }
52
- };
53
- return (React.createElement(SelectInput, { items: currentItems, onSelect: onSelect, itemComponent: Item, indicatorComponent: Indicator, limit: 10 }));
54
- };
55
- export const MultiLevelSelectComponent = (props) => __awaiter(void 0, void 0, void 0, function* () {
56
- const { items, handleSelect, handleExit } = props;
57
- return new Promise((resolve) => {
58
- const { unmount } = render(React.createElement(MultiLevelSelect, { items: items, handleSelect: (item) => {
59
- unmount();
60
- handleSelect && handleSelect(item);
61
- resolve(item);
62
- }, handleExit: () => {
63
- unmount();
64
- handleExit && handleExit();
65
- resolve(null);
66
- } }));
55
+ return selectedPath;
67
56
  });
68
- });
69
- export default MultiLevelSelectComponent;
57
+ }
@@ -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
  }