esa-cli 0.0.1-beta.8 → 0.0.2-beta.0

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 (50) hide show
  1. package/README.md +4 -6
  2. package/bin/enter.cjs +0 -1
  3. package/dist/README.md +4 -6
  4. package/dist/bin/enter.cjs +0 -1
  5. package/dist/commands/commit/index.js +2 -2
  6. package/dist/commands/commit/prodBuild.js +1 -1
  7. package/dist/commands/deploy/index.js +4 -2
  8. package/dist/commands/deployments/list.js +2 -1
  9. package/dist/commands/dev/build.js +57 -0
  10. package/dist/commands/dev/doProcess.js +10 -2
  11. package/dist/commands/dev/ew2/devEntry.js +9 -0
  12. package/dist/commands/dev/ew2/devPack.js +185 -0
  13. package/dist/commands/dev/ew2/mock/cache.js +32 -0
  14. package/dist/commands/dev/ew2/mock/kv.js +45 -0
  15. package/dist/commands/dev/ew2/server.js +234 -0
  16. package/dist/commands/dev/index.js +113 -50
  17. package/dist/commands/dev/{config → mockWorker}/devEntry.js +3 -2
  18. package/dist/commands/dev/{devPack.js → mockWorker/devPack.js} +10 -7
  19. package/dist/commands/dev/{server.js → mockWorker/server.js} +43 -36
  20. package/dist/commands/init/index.js +119 -47
  21. package/dist/commands/login/index.js +2 -2
  22. package/dist/commands/logout.js +0 -4
  23. package/dist/commands/route/list.js +2 -1
  24. package/dist/commands/routine/list.js +6 -4
  25. package/dist/commands/utils.js +2 -1
  26. package/dist/components/mutiLevelSelect.js +69 -0
  27. package/dist/i18n/index.js +4 -1
  28. package/dist/i18n/locales.json +897 -781
  29. package/dist/index.js +10 -3
  30. package/dist/libs/api.js +155 -0
  31. package/dist/libs/logger.js +42 -31
  32. package/dist/libs/service.js +178 -0
  33. package/dist/package.json +14 -7
  34. package/dist/utils/checkDevPort.js +19 -14
  35. package/dist/utils/checkOS.js +32 -0
  36. package/dist/utils/checkVersion.js +1 -1
  37. package/dist/utils/fileMd5.js +18 -0
  38. package/dist/utils/fileUtils/base.js +31 -0
  39. package/dist/utils/fileUtils/index.js +5 -33
  40. package/dist/utils/install/installEw2.sh +33 -0
  41. package/dist/utils/{installRuntime.js → installDeno.js} +16 -16
  42. package/dist/utils/installEw2.js +127 -0
  43. package/dist/utils/readJson.js +10 -0
  44. package/dist/utils/stepsRunner.js +33 -0
  45. package/dist/zh_CN.md +4 -5
  46. package/package.json +14 -7
  47. package/dist/commands/dev/config/devBuild.js +0 -26
  48. package/dist/libs/request.js +0 -98
  49. /package/dist/commands/dev/{config → mockWorker}/mock/cache.js +0 -0
  50. /package/dist/commands/dev/{config → mockWorker}/mock/kv.js +0 -0
@@ -0,0 +1,32 @@
1
+ import os from 'os';
2
+ export var Platforms;
3
+ (function (Platforms) {
4
+ Platforms["Win"] = "win";
5
+ Platforms["AppleArm"] = "darwin-arm64";
6
+ Platforms["AppleIntel"] = "darwin-x86_64";
7
+ Platforms["LinuxX86"] = "linux-x86_64";
8
+ Platforms["Linux"] = "linux";
9
+ Platforms["others"] = "others";
10
+ })(Platforms || (Platforms = {}));
11
+ export const checkOS = () => {
12
+ const platform = os.platform();
13
+ const cpus = os.cpus();
14
+ const cpuModel = cpus[0].model.toLowerCase();
15
+ const arch = os.arch();
16
+ if (platform === 'win32') {
17
+ return Platforms.Win;
18
+ }
19
+ if (platform === 'darwin') {
20
+ if (cpuModel.includes('apple')) {
21
+ return Platforms.AppleArm;
22
+ }
23
+ return Platforms.AppleIntel;
24
+ }
25
+ if (platform === 'linux') {
26
+ if (arch === 'x64') {
27
+ return Platforms.LinuxX86;
28
+ }
29
+ return Platforms.Linux;
30
+ }
31
+ return Platforms.others;
32
+ };
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { promises as fs } from 'fs';
11
- import { getDirName } from '../utils/fileUtils/index.js';
11
+ import { getDirName } from '../utils/fileUtils/base.js';
12
12
  import path from 'path';
13
13
  export function handleCheckVersion() {
14
14
  return __awaiter(this, void 0, void 0, function* () {
@@ -0,0 +1,18 @@
1
+ import fs from 'fs-extra';
2
+ import crypto from 'crypto';
3
+ export function calculateFileMD5(filePath) {
4
+ return new Promise((resolve, reject) => {
5
+ const hash = crypto.createHash('md5');
6
+ const fileStream = fs.createReadStream(filePath);
7
+ fileStream.on('data', (data) => {
8
+ hash.update(data);
9
+ });
10
+ fileStream.on('end', () => {
11
+ const md5sum = hash.digest('hex');
12
+ resolve(md5sum);
13
+ });
14
+ fileStream.on('error', (err) => {
15
+ reject(err);
16
+ });
17
+ });
18
+ }
@@ -0,0 +1,31 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ const cliConfigFile = 'cliconfig.toml';
5
+ export const getDirName = (metaUrl) => {
6
+ const __filename = fileURLToPath(metaUrl);
7
+ const __dirname = path.dirname(__filename);
8
+ return __dirname;
9
+ };
10
+ export const getRoot = (root) => {
11
+ if (typeof root === 'undefined') {
12
+ root = process.cwd();
13
+ }
14
+ if (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;
23
+ }
24
+ else {
25
+ return getRoot(prev);
26
+ }
27
+ }
28
+ catch (err) {
29
+ return getRoot(prev);
30
+ }
31
+ };
@@ -7,44 +7,16 @@ 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 toml from '@iarna/toml';
11
- import path from 'path';
12
10
  import fs from 'fs';
11
+ import os from 'os';
12
+ import path from 'path';
13
+ import toml from '@iarna/toml';
13
14
  import { promises as fsPromises } from 'fs';
14
- import { fileURLToPath } from 'url';
15
+ import { getDirName, getRoot } from './base.js';
15
16
  import logger from '../../libs/logger.js';
16
17
  import t from '../../i18n/index.js';
17
- import os from 'os';
18
18
  const projectConfigFile = 'esa.toml';
19
- const cliConfigFile = 'cliconfig.toml';
20
- export const getDirName = (metaUrl) => {
21
- const __filename = fileURLToPath(metaUrl);
22
- const __dirname = path.dirname(__filename);
23
- return __dirname;
24
- };
25
19
  const __dirname = getDirName(import.meta.url);
26
- export const getRoot = (root) => {
27
- if (typeof root === 'undefined') {
28
- root = process.cwd();
29
- }
30
- if (root === '/') {
31
- return process.cwd();
32
- }
33
- const file = path.join(root, cliConfigFile);
34
- const prev = path.resolve(root, '../');
35
- try {
36
- const hasToml = fs.existsSync(file);
37
- if (hasToml) {
38
- return root;
39
- }
40
- else {
41
- return getRoot(prev);
42
- }
43
- }
44
- catch (err) {
45
- return getRoot(prev);
46
- }
47
- };
48
20
  const root = getRoot();
49
21
  export const projectConfigPath = path.join(root, projectConfigFile);
50
22
  export const cliConfigPath = path.join(os.homedir(), '.esa/config/default.toml');
@@ -216,7 +188,7 @@ export const getApiConfig = () => {
216
188
  };
217
189
  return config;
218
190
  };
219
- export const templateHubPath = path.join(getDirName(import.meta.url), '../../../node_modules/esa-template/src');
191
+ export const templateHubPath = path.join(getDirName(import.meta.url), '../../node_modules/esa-template/src');
220
192
  export const getTemplatesConfig = () => {
221
193
  const manifestPath = path.join(templateHubPath, 'manifest.json');
222
194
  const config = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
@@ -0,0 +1,33 @@
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ os_type=$(uname -s)
5
+
6
+ if [ "$os_type" = "Darwin" ]; then
7
+ cpu_info=$(sysctl -n machdep.cpu.brand_string)
8
+ if echo "$cpu_info" | grep -q "Apple M"; then
9
+ target="darwin-arm64"
10
+ else
11
+ target="darwin-x86_64"
12
+ fi
13
+ else
14
+ target="linux-x86_64"
15
+ fi
16
+
17
+ version="$1"
18
+ ew2_uri="http://esa-runtime.myalicdn.com/ew2/${version}/${target}/edgeworker2"
19
+ echo "${ew2_uri}"
20
+ bin_dir="$HOME/.ew2"
21
+ exe="$bin_dir/edgeworker2"
22
+
23
+ if [ ! -d "$bin_dir" ]; then
24
+ mkdir -p "$bin_dir"
25
+ fi
26
+
27
+ curl --fail --location --progress-bar --output "$exe" "$ew2_uri"
28
+
29
+ chmod +rwx "$exe"
30
+ chmod +rw "$bin_dir"
31
+
32
+ echo "Runtime was installed successfully to $exe"
33
+
@@ -9,13 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { exec, execSync } from 'child_process';
11
11
  import os from 'os';
12
- import { getDirName } from './fileUtils/index.js';
12
+ import { getDirName } from './fileUtils/base.js';
13
13
  import logger from '../libs/logger.js';
14
14
  import path from 'path';
15
15
  import t from '../i18n/index.js';
16
- export function preCheckRuntime() {
16
+ export function preCheckDeno() {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
- const command = yield checkRuntimeInstalled();
18
+ const command = yield checkDenoInstalled();
19
19
  if (!command) {
20
20
  logger.error(t('install_runtime_explain').d('Under the beta phase, we are temporarily using Deno as the local development runtime. It needs to be installed first.'));
21
21
  installDeno();
@@ -24,20 +24,20 @@ export function preCheckRuntime() {
24
24
  return command;
25
25
  });
26
26
  }
27
- function checkDeno(command) {
28
- return new Promise((resolve, reject) => {
29
- exec(`${command} --version`, (err) => {
30
- if (err) {
31
- reject();
32
- }
33
- else {
34
- resolve(command);
35
- }
36
- });
37
- });
38
- }
39
- export function checkRuntimeInstalled() {
27
+ export function checkDenoInstalled() {
40
28
  const homeDeno = path.resolve(os.homedir(), '.deno/bin/deno');
29
+ function checkDeno(command) {
30
+ return new Promise((resolve, reject) => {
31
+ exec(`${command} --version`, (err) => {
32
+ if (err) {
33
+ reject();
34
+ }
35
+ else {
36
+ resolve(command);
37
+ }
38
+ });
39
+ });
40
+ }
41
41
  return new Promise((resolve) => {
42
42
  // @ts-ignore
43
43
  Promise.any([checkDeno('deno'), checkDeno(homeDeno)])
@@ -0,0 +1,127 @@
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 os from 'os';
11
+ import fs from 'fs-extra';
12
+ import path from 'path';
13
+ import util from 'util';
14
+ import https from 'https';
15
+ import { execSync } from 'child_process';
16
+ import logger from '../libs/logger.js';
17
+ import { getDirName } from './fileUtils/base.js';
18
+ import t from '../i18n/index.js';
19
+ import { calculateFileMD5 } from './fileMd5.js';
20
+ import { checkOS } from './checkOS.js';
21
+ export const EW2DirName = '.ew2';
22
+ export const EW2BinName = 'edgeworker2';
23
+ export const EW2Path = path.join(os.homedir(), EW2DirName);
24
+ export const EW2BinPath = path.join(EW2Path, EW2BinName);
25
+ export const EW2ManifestPath = path.join(EW2Path, 'manifest.json');
26
+ export function preCheckEw2() {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const fsAccess = util.promisify(fs.access);
29
+ const manifestRes = yield checkManifest();
30
+ function installVersion(manifest) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ try {
33
+ yield installEw2(manifest);
34
+ return true;
35
+ }
36
+ catch (error) {
37
+ const err = error;
38
+ logger.error(err.message);
39
+ return false;
40
+ }
41
+ });
42
+ }
43
+ try {
44
+ yield fsAccess(EW2BinPath, fs.constants.X_OK);
45
+ if (!manifestRes.isLatest) {
46
+ logger.warn(t('install_runtime_update_tip').d(`🔔 Runtime must be update to use esa dev. Installing...`));
47
+ return yield installVersion(manifestRes.remoteManifest);
48
+ }
49
+ return true;
50
+ }
51
+ catch (error) {
52
+ const err = error;
53
+ if (err.code === 'EACCES') {
54
+ logger.pathEacces(EW2BinPath);
55
+ return false;
56
+ }
57
+ if (err.code === 'ENOENT' || err.code === 'EPERM') {
58
+ logger.warn(t('install_runtime_tip').d(`🔔 Runtime must be installed to use esa dev. Installing...`));
59
+ return yield installVersion(manifestRes.remoteManifest);
60
+ }
61
+ logger.error(err.message);
62
+ return false;
63
+ }
64
+ });
65
+ }
66
+ export function fetchRemoteManifest() {
67
+ return new Promise((resolve, reject) => {
68
+ https
69
+ .get('https://edgestar-cn.oss-cn-beijing.aliyuncs.com/ew2/manifest.json', (res) => {
70
+ let data = '';
71
+ res.on('data', (chunk) => (data += chunk));
72
+ res.on('end', () => {
73
+ try {
74
+ const json = JSON.parse(data);
75
+ resolve(json);
76
+ }
77
+ catch (err) {
78
+ reject(null);
79
+ }
80
+ });
81
+ })
82
+ .on('error', (err) => reject);
83
+ });
84
+ }
85
+ export function checkManifest() {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ let isLatest = false;
88
+ const remoteManifest = yield fetchRemoteManifest();
89
+ const localManifestExists = yield fs.pathExists(EW2ManifestPath);
90
+ logger.info(`Remote version: ${remoteManifest.version}`);
91
+ if (localManifestExists) {
92
+ const localManifest = yield fs.readJSON(EW2ManifestPath);
93
+ isLatest = localManifest.version === remoteManifest.version;
94
+ logger.info(`Local version: ${localManifest.version}`);
95
+ if (!isLatest) {
96
+ logger.log(`Runtime Latest version: ${remoteManifest.version}, Current version: ${localManifest.version}`);
97
+ }
98
+ }
99
+ return {
100
+ remoteManifest,
101
+ isLatest
102
+ };
103
+ });
104
+ }
105
+ export function installEw2(manifest) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ const __dirname = getDirName(import.meta.url);
108
+ const p = path.join(__dirname, './install');
109
+ const installCommand = `sh ${p}/installEw2.sh ${manifest.version}`;
110
+ try {
111
+ execSync(installCommand, { stdio: 'inherit', env: Object.assign({}, process.env) });
112
+ const md5 = yield calculateFileMD5(EW2BinPath);
113
+ const os = checkOS();
114
+ // @ts-ignore;
115
+ if (md5 === manifest[`${os}_checksum`]) {
116
+ logger.success('Runtime checksum success.');
117
+ }
118
+ yield fs.writeJSON(EW2ManifestPath, manifest);
119
+ logger.success(t('install_runtime_success').d(`Runtime installed.`));
120
+ return true;
121
+ }
122
+ catch (error) {
123
+ logger.error(`Failed to install: ${error.message}`);
124
+ return false;
125
+ }
126
+ });
127
+ }
@@ -0,0 +1,10 @@
1
+ import { readFileSync } from 'fs';
2
+ export const readJson = (jsonPath) => {
3
+ try {
4
+ const json = JSON.parse(readFileSync(jsonPath, 'utf8'));
5
+ return json;
6
+ }
7
+ catch (_) {
8
+ throw new TypeError(`${jsonPath} is not a valid JSON file.`);
9
+ }
10
+ };
@@ -0,0 +1,33 @@
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 ora from 'ora';
11
+ function stepsRunner(promises) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ const results = [];
14
+ for (const promise of promises) {
15
+ const spinner = ora('Loading...').start();
16
+ try {
17
+ const result = yield promise();
18
+ spinner.succeed('Success!');
19
+ results.push({ status: 'success', message: result });
20
+ }
21
+ catch (error) {
22
+ spinner.fail('Error: ' + (error instanceof Error ? error.message : 'Unknown Error'));
23
+ results.push({
24
+ status: 'error',
25
+ message: error instanceof Error ? error.message : 'Unknown Error'
26
+ });
27
+ break;
28
+ }
29
+ }
30
+ return results;
31
+ });
32
+ }
33
+ export default stepsRunner;
package/dist/zh_CN.md CHANGED
@@ -9,9 +9,10 @@
9
9
  - [边缘安全加速(ESA)](https://www.aliyun.com/product/esa)
10
10
  - [边缘函数概述](https://help.aliyun.com/document_detail/2710021.html)
11
11
 
12
- > **注意**: ESA CLI 处于公测阶段,如果您在使用中遇到任何问题,或者有任何建议,请随时提交 issue 或 pull request。
13
- >
14
- > 我们正在积极改进,并欢迎任何反馈。感谢您的理解与支持!
12
+ > **注意**: **ESA CLI 在0.0.2以上版本的本地开发模式替换成了ESA边缘函数相同的Runtime,目前实际表现与线上相同,欢迎体验!**
13
+
14
+ ESA CLI 处于公测阶段,如果您在使用中遇到任何问题,或者有任何建议,请随时提交 issue 或 pull request。
15
+ 我们正在积极改进,并欢迎任何反馈。感谢您的理解与支持!
15
16
 
16
17
  ## 安装
17
18
 
@@ -75,8 +76,6 @@ export default {
75
76
  ![调试界面](https://github.com/aliyun/alibabacloud-esa-cli/blob/master/docs/dev.png)
76
77
 
77
78
  - 在界面上按 `b` 即可在浏览器中打开调试页面。
78
- - 在界面上按 `d` 可以查看调试引导。**Chrome 不允许命令行打开调试页面。**
79
- - 在 Chrome 浏览器中打开 `Chrome://inspect#devices` 页面,可以看到一个运行的`Remote Target`,点击下面的`inspect`即可查看 console 信息。**注意,EdgeRoutine 的代码为服务端代码,所以预览页面的控制台并不会输出入口文件中的 `console`,只能通过`inspect`调试。**
80
79
  - 在界面上按 `c` 可以清空面板。
81
80
  - 在界面上按 `x` 可以退出调试。
82
81
  - 可以用 `esa dev --port <port>` 临时指定端口,也可以使用 `esa config -l` 按照项目配置端口。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "0.0.1-beta.8",
3
+ "version": "0.0.2-beta.0",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",
@@ -16,14 +16,14 @@
16
16
  "eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
17
17
  "lint-staged": "lint-staged",
18
18
  "prepare": "npm run build",
19
- "test": "vitest",
20
- "coverage": "vitest --coverage",
21
- "preuninstall": "rm -rf ~/.esa/config"
19
+ "test": "FORCE_COLOR=0 npx vitest ",
20
+ "coverage": "vitest --coverage"
22
21
  },
23
22
  "keywords": [
24
23
  "cli",
25
24
  "edge",
26
25
  "esa",
26
+ "edgeRoutine",
27
27
  "alibaba",
28
28
  "ali"
29
29
  ],
@@ -31,8 +31,11 @@
31
31
  "license": "MIT",
32
32
  "devDependencies": {
33
33
  "@babel/plugin-syntax-import-attributes": "^7.24.7",
34
+ "@testing-library/dom": "^10.4.0",
34
35
  "@testing-library/jest-dom": "^6.5.0",
35
36
  "@testing-library/react": "^16.0.1",
37
+ "@types/babel__generator": "^7.6.8",
38
+ "@types/babel__traverse": "^7.20.6",
36
39
  "@types/cli-table": "^0.3.4",
37
40
  "@types/cross-spawn": "^6.0.6",
38
41
  "@types/fs-extra": "^11.0.4",
@@ -50,7 +53,6 @@
50
53
  "eslint-plugin-react-hooks": "^4.6.0",
51
54
  "husky": "^8.0.3",
52
55
  "jsdom": "^25.0.1",
53
- "@testing-library/dom": "^10.4.0",
54
56
  "lint-staged": "^15.0.2",
55
57
  "prettier": "^3.0.3",
56
58
  "react": "^18.2.0",
@@ -61,33 +63,38 @@
61
63
  "vitest": "^2.0.4"
62
64
  },
63
65
  "dependencies": {
66
+ "@alicloud/esa20240910": "2.8.1",
64
67
  "@alicloud/openapi-client": "^0.4.7",
68
+ "@babel/generator": "^7.26.3",
65
69
  "@babel/parser": "^7.24.4",
66
70
  "@babel/traverse": "^7.24.1",
67
71
  "@iarna/toml": "^2.2.5",
68
- "@tqman/ink-table": "^0.0.0-development",
69
72
  "@types/inquirer": "^9.0.7",
70
73
  "@vitest/coverage-istanbul": "^2.0.4",
74
+ "axios": "^1.7.7",
71
75
  "chalk": "^5.3.0",
72
76
  "chokidar": "^3.5.3",
73
77
  "cli-table3": "^0.6.5",
74
78
  "cross-spawn": "^7.0.3",
75
- "esa-template": "^0.0.1-beta.2",
79
+ "esa-template": "^0.0.3",
76
80
  "esbuild": "^0.21.1",
77
81
  "esbuild-plugin-less": "^1.3.8",
78
82
  "form-data": "^4.0.0",
79
83
  "fs-extra": "^11.2.0",
84
+ "http-proxy-agent": "^7.0.2",
80
85
  "ink": "^5.0.1",
81
86
  "ink-select-input": "^6.0.0",
82
87
  "ink-text-input": "^6.0.0",
83
88
  "inquirer": "^9.2.15",
84
89
  "js-base64": "^3.7.7",
90
+ "moment": "^2.30.1",
85
91
  "node-fetch": "^3.3.2",
86
92
  "open": "^9.1.0",
87
93
  "ora": "^7.0.1",
88
94
  "os-locale": "^6.0.2",
89
95
  "portscanner": "^2.2.0",
90
96
  "winston": "^3.11.0",
97
+ "winston-daily-rotate-file": "^5.0.0",
91
98
  "yargs": "^17.7.2"
92
99
  },
93
100
  "repository": {
@@ -1,26 +0,0 @@
1
- import esbuild from 'esbuild';
2
- import { lessLoader } from 'esbuild-plugin-less';
3
- import path from 'path';
4
- import { getRoot } from '../../../utils/fileUtils/index.js';
5
- import { NODE_EXTERNALS } from '../../common/constant.js';
6
- export default function (options) {
7
- const userRoot = getRoot();
8
- // @ts-ignore
9
- const id = global.id;
10
- const devEntry = path.resolve(userRoot, `.dev/devEntry-${id}.js`);
11
- return esbuild.build({
12
- entryPoints: [devEntry],
13
- outfile: path.resolve(userRoot, `.dev/index-${id}.js`),
14
- bundle: true,
15
- minify: !!options.minify,
16
- splitting: false,
17
- format: 'esm',
18
- platform: 'browser',
19
- external: NODE_EXTERNALS,
20
- // @ts-ignore
21
- plugins: [lessLoader()],
22
- loader: {
23
- '.client.js': 'text'
24
- }
25
- });
26
- }
@@ -1,98 +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 fetch, { Headers } from 'node-fetch';
11
- class HttpRequest {
12
- constructor(defaultHeaders = {
13
- 'Content-Type': 'application/json'
14
- }, timeout = 15000, retryCount = 3) {
15
- this.defaultHeaders = new Headers(defaultHeaders);
16
- this.timeout = timeout;
17
- this.retryCount = retryCount;
18
- }
19
- static getInstance(defaultHeaders, timeout, retryCount) {
20
- if (!HttpRequest.instance) {
21
- HttpRequest.instance = new HttpRequest(defaultHeaders, timeout, retryCount);
22
- Object.freeze(HttpRequest.instance);
23
- }
24
- return HttpRequest.instance;
25
- }
26
- fetchWithTimeout(url_1) {
27
- return __awaiter(this, arguments, void 0, function* (url, options = {}) {
28
- const controller = new AbortController();
29
- const id = setTimeout(() => controller.abort(), this.timeout);
30
- options.signal = controller.signal;
31
- try {
32
- return yield fetch(url, options);
33
- }
34
- catch (error) {
35
- throw new Error(`请求超时或失败: ${error.message}`);
36
- }
37
- finally {
38
- clearTimeout(id);
39
- }
40
- });
41
- }
42
- fetchWithRetry(url_1) {
43
- return __awaiter(this, arguments, void 0, function* (url, options = {}) {
44
- for (let attempt = 1; attempt <= this.retryCount; attempt++) {
45
- try {
46
- const response = yield this.fetchWithTimeout(url, options);
47
- if (response.ok) {
48
- return response;
49
- }
50
- throw new Error(`服务器响应错误: ${response.status} ${response.statusText}`);
51
- }
52
- catch (error) {
53
- if (attempt === this.retryCount) {
54
- throw error;
55
- }
56
- }
57
- }
58
- throw new Error('达到最大重试次数');
59
- });
60
- }
61
- get(url, headers) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- try {
64
- const response = yield this.fetchWithRetry(url, {
65
- method: 'GET',
66
- headers: headers
67
- ? new Headers(Object.assign(Object.assign({}, this.defaultHeaders), headers))
68
- : this.defaultHeaders
69
- });
70
- return yield response.json();
71
- }
72
- catch (error) {
73
- console.error(`GET请求错误: ${error.message}`);
74
- throw error;
75
- }
76
- });
77
- }
78
- post(url, data, headers) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- try {
81
- const response = yield this.fetchWithRetry(url, {
82
- method: 'POST',
83
- body: JSON.stringify(data),
84
- headers: headers
85
- ? new Headers(Object.assign(Object.assign({}, this.defaultHeaders), headers))
86
- : this.defaultHeaders
87
- });
88
- return yield response.json();
89
- }
90
- catch (error) {
91
- console.error(`POST请求错误: ${error.message}`);
92
- throw error;
93
- }
94
- });
95
- }
96
- }
97
- const request = HttpRequest.getInstance();
98
- export default request;