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,17 +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 { execSync } from 'child_process';
11
+ import https from 'https';
10
12
  import os from 'os';
11
- import fs from 'fs-extra';
12
13
  import path from 'path';
13
14
  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';
15
+ import fs from 'fs-extra';
18
16
  import t from '../i18n/index.js';
19
- import { calculateFileMD5 } from './fileMd5.js';
17
+ import logger from '../libs/logger.js';
20
18
  import { checkOS } from './checkOS.js';
19
+ import { calculateFileMD5 } from './fileMd5.js';
20
+ import { getDirName } from './fileUtils/base.js';
21
21
  export const EW2DirName = '.ew2';
22
22
  export const EW2BinName = 'edgeworker2';
23
23
  export const EW2Path = path.join(os.homedir(), EW2DirName);
@@ -79,7 +79,7 @@ export function fetchRemoteManifest() {
79
79
  }
80
80
  });
81
81
  })
82
- .on('error', (err) => reject);
82
+ .on('error', () => reject);
83
83
  });
84
84
  }
85
85
  export function checkManifest() {
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import open from 'open';
11
- import logger from '../libs/logger.js';
12
11
  import t from '../i18n/index.js';
12
+ import logger from '../libs/logger.js';
13
13
  /**
14
14
  * Open url in browser
15
15
  * @param {string} url
@@ -0,0 +1,97 @@
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 { confirm as clackConfirm, isCancel, multiselect as clackMultiselect, select as clackSelect, text as clackText, cancel as clackCancel } from '@clack/prompts';
11
+ import multiLevelSelect from '../components/mutiLevelSelect.js';
12
+ function normalizeChoices(choices) {
13
+ if (!choices)
14
+ return undefined;
15
+ return choices.map((c) => {
16
+ if (typeof c === 'string')
17
+ return { label: c, value: c };
18
+ return { label: c.name, value: String(c.value), hint: c.hint };
19
+ });
20
+ }
21
+ export function promptParameter(param) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ var _a;
24
+ const { type, question, defaultValue, validate } = param;
25
+ let value = '';
26
+ const msg = question;
27
+ if (type === 'text') {
28
+ const v = yield clackText({
29
+ message: msg,
30
+ placeholder: typeof defaultValue === 'string' ? defaultValue : undefined,
31
+ initialValue: typeof defaultValue === 'string' ? defaultValue : undefined,
32
+ validate: validate
33
+ ? (val) => {
34
+ if (val === undefined)
35
+ return 'Value is required';
36
+ const res = validate(val);
37
+ return res === true ? undefined : res;
38
+ }
39
+ : undefined
40
+ });
41
+ if (isCancel(v)) {
42
+ clackCancel('Operation cancelled.');
43
+ process.exit(130);
44
+ }
45
+ value = v;
46
+ }
47
+ else if (type === 'confirm') {
48
+ const v = yield clackConfirm({
49
+ message: msg,
50
+ initialValue: (_a = defaultValue) !== null && _a !== void 0 ? _a : false
51
+ });
52
+ if (isCancel(v)) {
53
+ clackCancel('Operation cancelled.');
54
+ process.exit(130);
55
+ }
56
+ value = v;
57
+ }
58
+ else if (type === 'select') {
59
+ const options = normalizeChoices(param.choices) || [];
60
+ const v = yield clackSelect({
61
+ message: msg,
62
+ options,
63
+ initialValue: defaultValue || undefined
64
+ });
65
+ if (isCancel(v)) {
66
+ clackCancel('Operation cancelled.');
67
+ process.exit(130);
68
+ }
69
+ value = v;
70
+ }
71
+ else if (type === 'multiselect') {
72
+ const options = normalizeChoices(param.choices) || [];
73
+ const initialValues = (defaultValue || []).map((v) => String(v));
74
+ const v = yield clackMultiselect({
75
+ message: msg,
76
+ options,
77
+ initialValues
78
+ });
79
+ if (isCancel(v)) {
80
+ clackCancel('Operation cancelled.');
81
+ process.exit(130);
82
+ }
83
+ value = v;
84
+ }
85
+ else if (type === 'multiLevelSelect') {
86
+ const items = (param.treeItems || []);
87
+ const v = yield multiLevelSelect(items, msg);
88
+ if (v === null) {
89
+ clackCancel('Operation cancelled.');
90
+ process.exit(130);
91
+ }
92
+ value = v;
93
+ }
94
+ return value;
95
+ });
96
+ }
97
+ export default promptParameter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "0.0.2-beta.2",
3
+ "version": "0.0.2-beta.21",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",
@@ -15,12 +15,14 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "build": "rm -rf ./dist && rm -rf ./build && node ./genLocale.cjs && tsc && node ./copy.cjs",
18
- "watch": "tsc --watch",
18
+ "dev": "tsc --watch",
19
19
  "eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
20
+ "prepare": "husky install",
20
21
  "lint-staged": "lint-staged",
21
- "prepare": "npm run build",
22
- "test": "FORCE_COLOR=0 npx vitest ",
23
- "coverage": "vitest --coverage"
22
+ "test": "vitest --coverage",
23
+ "coverage": "vitest --coverage",
24
+ "lint": "eslint src/",
25
+ "lint:fix": "eslint src/ --fix"
24
26
  },
25
27
  "keywords": [
26
28
  "cli",
@@ -37,6 +39,7 @@
37
39
  "@testing-library/dom": "^10.4.0",
38
40
  "@testing-library/jest-dom": "^6.5.0",
39
41
  "@testing-library/react": "^16.0.1",
42
+ "@types/adm-zip": "^0.5.7",
40
43
  "@types/babel__generator": "^7.6.8",
41
44
  "@types/babel__traverse": "^7.20.6",
42
45
  "@types/cli-table": "^0.3.4",
@@ -49,11 +52,9 @@
49
52
  "@types/portscanner": "^2.1.4",
50
53
  "@types/react": "^18.2.47",
51
54
  "@types/yargs": "^17.0.32",
55
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
52
56
  "@typescript-eslint/parser": "^6.9.1",
53
- "eslint": "^8.52.0",
54
- "eslint-config-prettier": "^9.0.0",
55
- "eslint-plugin-react": "^7.33.2",
56
- "eslint-plugin-react-hooks": "^4.6.0",
57
+ "eslint-plugin-react": "latest",
57
58
  "husky": "^8.0.3",
58
59
  "jsdom": "^25.0.1",
59
60
  "lint-staged": "^15.0.2",
@@ -66,24 +67,26 @@
66
67
  "vitest": "^2.0.4"
67
68
  },
68
69
  "dependencies": {
69
- "@alicloud/esa20240910": "2.8.1",
70
+ "@alicloud/esa20240910": "2.25.0",
70
71
  "@alicloud/openapi-client": "^0.4.7",
71
72
  "@babel/generator": "^7.26.3",
72
73
  "@babel/parser": "^7.24.4",
73
74
  "@babel/traverse": "^7.24.1",
75
+ "@clack/prompts": "1.0.0-alpha.4",
74
76
  "@iarna/toml": "^2.2.5",
75
77
  "@types/inquirer": "^9.0.7",
76
78
  "@vitest/coverage-istanbul": "^2.0.4",
77
- "axios": "^1.7.7",
79
+ "adm-zip": "^0.5.16",
78
80
  "chalk": "^5.3.0",
79
81
  "chokidar": "^3.5.3",
80
82
  "cli-table3": "^0.6.5",
81
83
  "cross-spawn": "^7.0.3",
82
- "esa-template": "^0.0.3",
84
+ "esa-template": "0.0.9",
83
85
  "esbuild": "^0.21.1",
84
86
  "esbuild-plugin-less": "^1.3.8",
85
87
  "form-data": "^4.0.0",
86
88
  "fs-extra": "^11.2.0",
89
+ "haikunator": "^2.1.2",
87
90
  "http-proxy-agent": "^7.0.2",
88
91
  "ink": "^5.0.1",
89
92
  "ink-select-input": "^6.0.0",
@@ -100,6 +103,11 @@
100
103
  "winston-daily-rotate-file": "^5.0.0",
101
104
  "yargs": "^17.7.2"
102
105
  },
106
+ "lint-staged": {
107
+ "src/**/*.{ts,tsx,js,jsx}": [
108
+ "eslint --fix"
109
+ ]
110
+ },
103
111
  "repository": {
104
112
  "type": "git",
105
113
  "url": "git+ssh://git@github.com/aliyun/alibabacloud-esa-cli.git"