esa-cli 1.0.10 → 1.0.11

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 (40) hide show
  1. package/README.md +206 -22
  2. package/bin/enter.cjs +45 -12
  3. package/dist/bin/enter.cjs +45 -12
  4. package/dist/commands/commit/index.js +5 -4
  5. package/dist/commands/deployments/delete.js +1 -1
  6. package/dist/commands/deployments/list.js +1 -1
  7. package/dist/commands/dev/build.js +4 -1
  8. package/dist/commands/dev/doProcess.js +94 -36
  9. package/dist/commands/domain/add.js +1 -1
  10. package/dist/commands/domain/delete.js +2 -3
  11. package/dist/commands/domain/list.js +1 -1
  12. package/dist/commands/init/helper.js +12 -8
  13. package/dist/commands/init/index.js +3 -4
  14. package/dist/commands/login/index.js +9 -5
  15. package/dist/commands/logout.js +3 -3
  16. package/dist/commands/route/add.js +1 -1
  17. package/dist/commands/route/delete.js +1 -1
  18. package/dist/commands/route/list.js +1 -1
  19. package/dist/commands/routine/delete.js +1 -2
  20. package/dist/commands/routine/list.js +1 -1
  21. package/dist/commands/site/list.js +1 -1
  22. package/dist/commands/utils.js +9 -3
  23. package/dist/components/mutiSelectTable.js +16 -83
  24. package/dist/components/routeBuilder.js +30 -54
  25. package/dist/components/selectInput.js +27 -13
  26. package/dist/docs/Commands_en.md +14 -2
  27. package/dist/docs/Commands_zh_CN.md +11 -1
  28. package/dist/i18n/locales.json +1 -1
  29. package/dist/index.js +8 -3
  30. package/dist/libs/api.js +0 -8
  31. package/dist/libs/logger.js +7 -2
  32. package/dist/utils/fileMd5.js +13 -3
  33. package/dist/utils/fileUtils/base.js +14 -18
  34. package/dist/utils/fileUtils/index.js +20 -0
  35. package/package.json +18 -20
  36. package/zh_CN.md +2 -2
  37. package/dist/components/descriptionInput.js +0 -38
  38. package/dist/components/filterSelector.js +0 -132
  39. package/dist/components/selectItem.js +0 -6
  40. package/dist/components/yesNoPrompt.js +0 -9
@@ -1,31 +1,27 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
- const cliConfigFile = 'cliconfig.toml';
4
+ const projectConfigFiles = ['esa.jsonc', 'esa.toml'];
5
5
  export const getDirName = (metaUrl) => {
6
6
  const __filename = fileURLToPath(metaUrl);
7
7
  const __dirname = path.dirname(__filename);
8
8
  return __dirname;
9
9
  };
10
10
  export const getRoot = (root) => {
11
- if (typeof root === 'undefined') {
12
- root = process.cwd();
13
- }
14
- if (path.parse(root).root === root) {
15
- return process.cwd();
16
- }
17
- const file = path.join(root, cliConfigFile);
18
- const prev = path.resolve(root, '../');
19
- try {
20
- const hasToml = fs.existsSync(file);
21
- if (hasToml) {
22
- return root;
11
+ const start = path.resolve(root !== null && root !== void 0 ? root : process.cwd());
12
+ let current = start;
13
+ while (true) {
14
+ try {
15
+ const hasProjectConfig = projectConfigFiles.some((fileName) => fs.existsSync(path.join(current, fileName)));
16
+ if (hasProjectConfig) {
17
+ return current;
18
+ }
23
19
  }
24
- else {
25
- return getRoot(prev);
20
+ catch (_a) { }
21
+ const parent = path.dirname(current);
22
+ if (parent === current) {
23
+ return process.cwd();
26
24
  }
27
- }
28
- catch (err) {
29
- return getRoot(prev);
25
+ current = parent;
30
26
  }
31
27
  };
@@ -269,6 +269,26 @@ export function getDevOpenBrowserUrl() {
269
269
  }
270
270
  export const getApiConfig = () => {
271
271
  var _a, _b, _c;
272
+ const envAccessKeyId = process.env.ALIBABA_CLOUD_ACCESS_KEY_ID ||
273
+ process.env.ESA_ACCESS_KEY_ID;
274
+ const envAccessKeySecret = process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET ||
275
+ process.env.ESA_ACCESS_KEY_SECRET;
276
+ const envSecurityToken = process.env.ALIBABA_CLOUD_SECURITY_TOKEN ||
277
+ process.env.ESA_SECURITY_TOKEN;
278
+ if (envAccessKeyId && envAccessKeySecret) {
279
+ const [cliConfig, projectConfig] = getConfigurations();
280
+ const endpoint = (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.endpoint) ||
281
+ (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.endpoint) ||
282
+ 'esa.cn-hangzhou.aliyuncs.com';
283
+ return {
284
+ auth: {
285
+ accessKeyId: envAccessKeyId,
286
+ accessKeySecret: envAccessKeySecret,
287
+ securityToken: envSecurityToken
288
+ },
289
+ endpoint
290
+ };
291
+ }
272
292
  const [cliConfig, projectConfig] = getConfigurations();
273
293
  let defaultConfig = {
274
294
  auth: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA Functions and Pages.",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",
@@ -36,11 +36,13 @@
36
36
  ],
37
37
  "author": "Kinice, Shengyuan Ma",
38
38
  "license": "MIT",
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
39
42
  "devDependencies": {
40
43
  "@babel/plugin-syntax-import-attributes": "^7.24.7",
41
44
  "@testing-library/dom": "^10.4.0",
42
45
  "@testing-library/jest-dom": "^6.5.0",
43
- "@testing-library/react": "^16.0.1",
44
46
  "@types/adm-zip": "^0.5.7",
45
47
  "@types/babel__generator": "^7.6.8",
46
48
  "@types/babel__traverse": "^7.20.6",
@@ -48,53 +50,52 @@
48
50
  "@types/cross-spawn": "^6.0.6",
49
51
  "@types/fs-extra": "^11.0.4",
50
52
  "@types/jest": "^29.5.12",
53
+ "@types/inquirer": "^9.0.7",
51
54
  "@types/lodash": "^4.14.202",
52
55
  "@types/node": "^20.8.10",
53
56
  "@types/node-fetch": "^2.6.9",
54
57
  "@types/portscanner": "^2.1.4",
55
- "@types/react": "^18.2.47",
56
58
  "@types/yargs": "^17.0.32",
57
- "@typescript-eslint/eslint-plugin": "^6.21.0",
58
- "@typescript-eslint/parser": "^6.9.1",
59
+ "@typescript-eslint/eslint-plugin": "8.46.1",
60
+ "@typescript-eslint/parser": "8.46.1",
59
61
  "eslint": "^8.57.0",
60
62
  "eslint-plugin-import": "^2.32.0",
61
- "eslint-plugin-react": "latest",
62
- "eslint-plugin-react-hooks": "^5.2.0",
63
+ "rimraf": "5.0.10",
63
64
  "husky": "^8.0.3",
64
65
  "jsdom": "^25.0.1",
65
66
  "lint-staged": "^15.0.2",
66
67
  "prettier": "^3.0.3",
67
68
  "tsc-files": "^1.1.4",
68
69
  "typescript": "^5.2.2",
69
- "vitest": "^2.0.4"
70
+ "@vitest/coverage-istanbul": "^3.2.6",
71
+ "vite": "6.4.3",
72
+ "vitest": "^3.2.6"
70
73
  },
71
74
  "dependencies": {
72
- "@alicloud/esa20240910": "2.25.0",
75
+ "@alicloud/esa20240910": "2.29.0",
73
76
  "@alicloud/openapi-client": "^0.4.7",
77
+ "@alicloud/tea-util": "^1.4.9",
74
78
  "@babel/generator": "^7.26.3",
75
79
  "@babel/parser": "^7.24.4",
76
80
  "@babel/traverse": "^7.24.1",
77
81
  "@clack/prompts": "1.0.0-alpha.4",
78
82
  "@iarna/toml": "^2.2.5",
79
- "@types/inquirer": "^9.0.7",
80
- "@vitest/coverage-istanbul": "^2.0.4",
81
- "adm-zip": "^0.5.16",
83
+ "adm-zip": "^0.6.0",
82
84
  "chalk": "^5.3.0",
83
85
  "chokidar": "^3.5.3",
84
86
  "cli-table3": "^0.6.5",
85
87
  "cross-spawn": "^7.0.3",
88
+ "debug": "^4.4.3",
86
89
  "esa-template": "^0.0.10",
87
- "esbuild": "^0.21.1",
90
+ "esbuild": "^0.25.12",
88
91
  "esbuild-plugin-less": "^1.3.8",
89
92
  "form-data": "^4.0.0",
90
93
  "fs-extra": "^11.2.0",
91
94
  "haikunator": "^2.1.2",
92
95
  "http-proxy-agent": "^7.0.2",
93
- "ink": "^5.0.1",
94
- "ink-select-input": "^6.0.0",
95
- "ink-text-input": "^6.0.0",
96
96
  "inquirer": "^9.2.15",
97
97
  "js-base64": "^3.7.7",
98
+ "lodash": "^4.17.21",
98
99
  "moment": "^2.30.1",
99
100
  "node-fetch": "^3.3.2",
100
101
  "open": "^9.1.0",
@@ -103,10 +104,7 @@
103
104
  "portscanner": "^2.2.0",
104
105
  "winston": "^3.11.0",
105
106
  "winston-daily-rotate-file": "^5.0.0",
106
- "yargs": "^17.7.2",
107
- "react": "^18.2.0",
108
- "react-dom": "^18.2.0",
109
- "rimraf": "^6.0.1"
107
+ "yargs": "^17.7.2"
110
108
  },
111
109
  "lint-staged": {
112
110
  "src/**/*.{ts,tsx,js,jsx}": [
package/zh_CN.md CHANGED
@@ -51,7 +51,7 @@ npm i -D esa-cli@latest
51
51
 
52
52
  ## 相关文档
53
53
 
54
- - [esa-cli 命令](./docs/Commands_zh_CN.md)
55
- - [ESA 配置文件说明](./docs/Config_zh_CN.md)
54
+ - [esa-cli 命令](https://github.com/aliyun/alibabacloud-esa-cli/blob/master/docs/Commands_zh_CN.md)
55
+ - [ESA 配置文件说明](https://github.com/aliyun/alibabacloud-esa-cli/blob/master/docs/Config_zh_CN.md)
56
56
  - [阿里云 ESA 文档](https://help.aliyun.com/document_detail/2710021.html)
57
57
  - [Functions 和 Pages API 参考](https://help.aliyun.com/document_detail/2710024.html)
@@ -1,38 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Box, render, Text } from 'ink';
11
- import TextInput from 'ink-text-input';
12
- import React, { useState } from 'react';
13
- export const DescriptionInput = ({ prompt, onSubmit, required }) => {
14
- const [input, setInput] = useState('');
15
- const [error, setError] = useState('');
16
- const handleSubmit = () => {
17
- if (required && !input.trim()) {
18
- setError('This field is required');
19
- }
20
- else {
21
- onSubmit(input);
22
- }
23
- };
24
- return (React.createElement(Box, { flexDirection: "column" },
25
- React.createElement(Box, null,
26
- React.createElement(Text, null, prompt)),
27
- React.createElement(TextInput, { value: input, onChange: setInput, onSubmit: handleSubmit }),
28
- error && (React.createElement(Box, null,
29
- React.createElement(Text, { color: "red" }, error)))));
30
- };
31
- export const descriptionInput = (prompt_1, ...args_1) => __awaiter(void 0, [prompt_1, ...args_1], void 0, function* (prompt, required = false) {
32
- return new Promise((resolve) => {
33
- const { unmount } = render(React.createElement(DescriptionInput, { prompt: prompt, required: required, onSubmit: (input) => {
34
- unmount();
35
- resolve(input);
36
- } }));
37
- });
38
- });
@@ -1,132 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Box, render, Text, useInput } from 'ink';
11
- import TextInput from 'ink-text-input';
12
- import React, { useState, useEffect } from 'react';
13
- import t from '../i18n/index.js';
14
- export const FilterSelector = ({ data, onSubmit, hideCount = 20 }) => {
15
- const [inputValue, setInputValue] = useState('');
16
- const [filteredData, setFilteredData] = useState(data);
17
- const [isShowFilteredData, setIsShowFilteredData] = useState(false);
18
- const [isSelectionMode, setIsSelectionMode] = useState(false);
19
- const [selectedIndex, setSelectedIndex] = useState(-1);
20
- const [tabPressCount, setTabPressCount] = useState(0);
21
- const [showAll, setShowAll] = useState(false);
22
- useEffect(() => {
23
- if (showAll && !isSelectionMode) {
24
- setFilteredData(data.filter((site) => site.label.includes(inputValue)));
25
- }
26
- }, [inputValue, data]);
27
- const handleSubmit = () => {
28
- onSubmit(inputValue);
29
- };
30
- useInput((input, key) => {
31
- if (key.return && isSelectionMode && filteredData[selectedIndex]) {
32
- setInputValue(filteredData[selectedIndex].label);
33
- setIsSelectionMode(false);
34
- setIsShowFilteredData(false);
35
- setSelectedIndex(-1);
36
- setTabPressCount(0);
37
- }
38
- else if (key.tab) {
39
- if (tabPressCount === 0) {
40
- const filteredDataInner = data.filter((site) => site.label.includes(inputValue));
41
- setFilteredData(filteredDataInner);
42
- if (filteredData.length === 1) {
43
- setIsShowFilteredData(false);
44
- setInputValue(filteredDataInner[0].label);
45
- setSelectedIndex(0);
46
- }
47
- else {
48
- setIsShowFilteredData(true);
49
- }
50
- }
51
- else if (tabPressCount === 1) {
52
- const filteredDataInner = data.filter((site) => site.label.includes(inputValue));
53
- setFilteredData(filteredDataInner);
54
- // Enter selection mode when match results >= 1
55
- if ((filteredDataInner.length >= 1 &&
56
- showAll &&
57
- filteredDataInner.length > hideCount) ||
58
- (filteredDataInner.length >= 1 &&
59
- filteredDataInner.length <= hideCount)) {
60
- setIsSelectionMode(true);
61
- setSelectedIndex(0);
62
- setInputValue(filteredDataInner[0].label);
63
- }
64
- }
65
- else if (tabPressCount >= 2 &&
66
- isSelectionMode &&
67
- (showAll || filteredData.length <= hideCount) &&
68
- filteredData.length > 1) {
69
- setSelectedIndex((prevIndex) => (prevIndex + 1) % filteredData.length);
70
- setInputValue(filteredData[(selectedIndex + 1) % filteredData.length].label);
71
- }
72
- setTabPressCount((prevCount) => prevCount + 1);
73
- }
74
- else if (key.downArrow && isSelectionMode) {
75
- setSelectedIndex((prevIndex) => (prevIndex + 1) % filteredData.length);
76
- setInputValue(filteredData[(selectedIndex + 1) % filteredData.length].label);
77
- }
78
- else if (key.upArrow && isSelectionMode) {
79
- setSelectedIndex((prevIndex) => (prevIndex - 1 + filteredData.length) % filteredData.length);
80
- setInputValue(filteredData[(selectedIndex - 1 + filteredData.length) % filteredData.length].label);
81
- }
82
- else if (key.leftArrow || key.rightArrow) {
83
- }
84
- else if (key.return) {
85
- handleSubmit();
86
- setTabPressCount(0);
87
- }
88
- else if (input === 'y' &&
89
- !showAll &&
90
- isShowFilteredData &&
91
- (filteredData === null || filteredData === void 0 ? void 0 : filteredData.length) > hideCount) {
92
- setShowAll(true);
93
- setIsSelectionMode(true);
94
- }
95
- else {
96
- setIsSelectionMode(false);
97
- setIsShowFilteredData(false);
98
- setSelectedIndex(-1);
99
- setTabPressCount(0);
100
- setShowAll(false);
101
- }
102
- });
103
- const renderFilterData = () => {
104
- return ((showAll || filteredData.length <= hideCount) &&
105
- filteredData.length > 1 && (React.createElement(React.Fragment, null,
106
- React.createElement(Text, null, `👉 ${t('route_add_tab_tip').d('Press Tab to select')}`),
107
- filteredData.map((item, index) => (React.createElement(Text, { key: index, inverse: index === selectedIndex }, item.label))))));
108
- };
109
- return (React.createElement(Box, { flexDirection: "column" },
110
- React.createElement(TextInput, { value: inputValue, highlightPastedText: true, onChange: (value) => {
111
- if (!showAll &&
112
- value[value.length - 1] === 'y' &&
113
- tabPressCount === 1) {
114
- return;
115
- }
116
- setInputValue(value);
117
- } }),
118
- isShowFilteredData && (React.createElement(React.Fragment, null,
119
- filteredData.length > hideCount && !showAll && (React.createElement(Text, null, t('route_add_see_more').d(`Do you wish to see all ${filteredData.length} possibilities? (y/n)`))),
120
- renderFilterData()))));
121
- };
122
- export const promptFilterSelector = (siteList) => __awaiter(void 0, void 0, void 0, function* () {
123
- return new Promise((resolve) => {
124
- const { unmount } = render(React.createElement(FilterSelector, { onSubmit: (input) => {
125
- unmount();
126
- resolve(siteList.find((site) => site.label === input) || {
127
- label: '',
128
- value: ''
129
- });
130
- }, data: siteList }));
131
- });
132
- });
@@ -1,6 +0,0 @@
1
- import { Text } from 'ink';
2
- import * as React from 'react';
3
- function Item({ isSelected = false, label }) {
4
- return React.createElement(Text, { color: isSelected ? 'green' : undefined }, label);
5
- }
6
- export default Item;
@@ -1,9 +0,0 @@
1
- import SelectItems from './selectInput.js';
2
- const yesNoItems = [
3
- { label: 'Yes', value: 'yes' },
4
- { label: 'No', value: 'no' }
5
- ];
6
- export const yesNoPrompt = (handleSelect, title) => {
7
- console.log(title);
8
- SelectItems({ items: yesNoItems, handleSelect });
9
- };