esa-cli 0.0.2-beta.10 → 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 (75) hide show
  1. package/dist/commands/commit/index.js +26 -115
  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 +40 -61
  6. package/dist/commands/deploy/index.js +90 -188
  7. package/dist/commands/deployments/delete.js +32 -22
  8. package/dist/commands/deployments/index.js +2 -2
  9. package/dist/commands/deployments/list.js +22 -38
  10. package/dist/commands/dev/build.js +3 -3
  11. package/dist/commands/dev/doProcess.js +5 -5
  12. package/dist/commands/dev/ew2/cacheService.js +33 -0
  13. package/dist/commands/dev/ew2/devEntry.js +2 -1
  14. package/dist/commands/dev/ew2/devPack.js +22 -11
  15. package/dist/commands/dev/ew2/kvService.js +27 -0
  16. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  17. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  18. package/dist/commands/dev/ew2/server.js +162 -27
  19. package/dist/commands/dev/index.js +14 -15
  20. package/dist/commands/dev/mockWorker/devPack.js +16 -7
  21. package/dist/commands/dev/mockWorker/server.js +7 -6
  22. package/dist/commands/domain/add.js +2 -2
  23. package/dist/commands/domain/delete.js +7 -7
  24. package/dist/commands/domain/index.js +2 -2
  25. package/dist/commands/domain/list.js +10 -10
  26. package/dist/commands/init/helper.js +87 -13
  27. package/dist/commands/init/index.js +461 -57
  28. package/dist/commands/init/template.jsonc +34 -0
  29. package/dist/commands/lang.js +2 -2
  30. package/dist/commands/login/index.js +57 -7
  31. package/dist/commands/logout.js +5 -5
  32. package/dist/commands/route/add.js +138 -49
  33. package/dist/commands/route/delete.js +33 -27
  34. package/dist/commands/route/helper.js +124 -0
  35. package/dist/commands/route/index.js +2 -2
  36. package/dist/commands/route/list.js +56 -17
  37. package/dist/commands/routine/delete.js +2 -2
  38. package/dist/commands/routine/index.js +2 -2
  39. package/dist/commands/routine/list.js +9 -21
  40. package/dist/commands/site/index.js +1 -1
  41. package/dist/commands/site/list.js +6 -7
  42. package/dist/commands/utils.js +55 -19
  43. package/dist/components/descriptionInput.js +1 -1
  44. package/dist/components/mutiSelectTable.js +1 -1
  45. package/dist/components/selectInput.js +2 -3
  46. package/dist/components/selectItem.js +1 -1
  47. package/dist/docs/Commands_en.md +25 -15
  48. package/dist/docs/Commands_zh_CN.md +12 -2
  49. package/dist/docs/eslint-config-en.md +1 -0
  50. package/dist/docs/eslint-config.md +73 -0
  51. package/dist/docs/init-command-quick-test.md +208 -0
  52. package/dist/docs/init-command-test-guide.md +598 -0
  53. package/dist/i18n/index.js +2 -2
  54. package/dist/i18n/locales.json +261 -17
  55. package/dist/index.js +17 -12
  56. package/dist/libs/api.js +32 -9
  57. package/dist/libs/apiService.js +258 -85
  58. package/dist/libs/git/index.js +8 -4
  59. package/dist/libs/interface.js +0 -1
  60. package/dist/libs/logger.js +63 -7
  61. package/dist/libs/service.js +2 -2
  62. package/dist/libs/templates/index.js +1 -1
  63. package/dist/utils/checkAssetsExist.js +80 -0
  64. package/dist/utils/checkDevPort.js +3 -17
  65. package/dist/utils/checkEntryFileExist.js +10 -0
  66. package/dist/utils/checkIsRoutineCreated.js +16 -31
  67. package/dist/utils/checkVersion.js +1 -1
  68. package/dist/utils/compress.js +80 -0
  69. package/dist/utils/download.js +5 -5
  70. package/dist/utils/fileMd5.js +1 -1
  71. package/dist/utils/fileUtils/index.js +71 -22
  72. package/dist/utils/installDeno.js +3 -3
  73. package/dist/utils/installEw2.js +7 -7
  74. package/dist/utils/openInBrowser.js +1 -1
  75. package/package.json +11 -6
@@ -7,14 +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 { getProjectConfig, readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
11
- import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
12
- import { displaySelectSpec } from '../deploy/index.js';
10
+ import { exit } from 'process';
13
11
  import { descriptionInput } from '../../components/descriptionInput.js';
14
- import { ApiService } from '../../libs/apiService.js';
15
- import prodBuild from './prodBuild.js';
16
- import logger from '../../libs/logger.js';
17
12
  import t from '../../i18n/index.js';
13
+ import { validateAndInitializeProject, generateCodeVersion } from '../common/routineUtils.js';
18
14
  const commit = {
19
15
  command: 'commit [entry]',
20
16
  describe: `📥 ${t('commit_describe').d('Commit your code, save as a new version')}`,
@@ -26,126 +22,41 @@ const commit = {
26
22
  type: 'boolean',
27
23
  default: false
28
24
  })
29
- .positional('entry', {
30
- describe: t('dev_entry_describe').d('Entry file of the Routine'),
31
- type: 'string',
32
- demandOption: false
25
+ .option('assets', {
26
+ alias: 'a',
27
+ describe: t('commit_option_assets').d('Assets directory'),
28
+ type: 'string'
29
+ })
30
+ .option('description', {
31
+ alias: 'd',
32
+ describe: t('commit_option_description').d('Description for the routine/version (skip interactive input)'),
33
+ type: 'string'
34
+ })
35
+ .option('name', {
36
+ alias: 'n',
37
+ describe: t('commit_option_name').d('Edge Routine name'),
38
+ type: 'string'
33
39
  });
34
40
  },
35
41
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
36
- handleCommit(argv);
42
+ yield handleCommit(argv);
43
+ exit();
37
44
  })
38
45
  };
39
46
  export default commit;
40
47
  export function handleCommit(argv) {
41
48
  return __awaiter(this, void 0, void 0, function* () {
42
- var _a, _b, _c;
43
- if (!checkDirectory())
44
- return;
45
- const projectConfig = getProjectConfig();
46
- if (!projectConfig)
47
- return logger.notInProject();
48
- if (!(yield checkIsLoginSuccess()))
49
+ const projectInfo = yield validateAndInitializeProject(argv === null || argv === void 0 ? void 0 : argv.name);
50
+ if (!projectInfo)
49
51
  return;
50
- yield prodBuild(!!argv.minify, argv === null || argv === void 0 ? void 0 : argv.entry);
51
- try {
52
- const server = yield ApiService.getInstance();
53
- const req = { Name: projectConfig.name };
54
- const response = yield server.getRoutine(req, false);
55
- let specName = (_a = response === null || response === void 0 ? void 0 : response.data.Envs[0].SpecName) !== null && _a !== void 0 ? _a : '50ms';
56
- let action = 'Creating';
57
- let description;
58
- if (!response) {
59
- logger.log(`🙅 ${t('commit_er_not_exist').d('No routine found, creating a new one')}`);
60
- description = yield descriptionInput(`🖊️ ${t('commit_er_description').d('Enter a description for the routine')}:`, false);
61
- const specList = ((_c = (_b = (yield server.ListRoutineOptionalSpecs())) === null || _b === void 0 ? void 0 : _b.data.Specs) !== null && _c !== void 0 ? _c : []).reduce((acc, item) => {
62
- if (item.IsAvailable) {
63
- acc.push(item.SpecName);
64
- }
65
- return acc;
66
- }, []);
67
- specName = yield displaySelectSpec(specList);
68
- }
69
- else {
70
- logger.log(`🔄 ${t('commit_er_exist').d('Routine exists, updating the code')}`);
71
- description = yield descriptionInput(`🖊️ ${t('commit_version_description').d('Enter a description for the version')}:`, false);
72
- action = 'Updating';
73
- }
74
- const code = readEdgeRoutineFile() || '';
75
- const edgeRoutine = {
76
- name: projectConfig.name,
77
- code,
78
- description,
79
- specName
80
- };
81
- if (action === 'Creating') {
82
- yield createEdgeRoutine(edgeRoutine);
83
- }
84
- else {
85
- if (!(yield uploadEdgeRoutineCode(edgeRoutine)))
86
- return;
87
- yield releaseOfficialVersion(edgeRoutine);
88
- }
89
- }
90
- catch (error) {
91
- logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
92
- }
93
- });
94
- }
95
- export function createEdgeRoutine(edgeRoutine) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- try {
98
- const server = yield ApiService.getInstance();
99
- const res = yield server.createRoutine(edgeRoutine);
100
- const createResult = (res === null || res === void 0 ? void 0 : res.data.Status) === 'OK';
101
- if (!createResult) {
102
- logger.error(t('commit_create_er_fail').d('An error occurred while trying to create a routine'));
103
- return false;
104
- }
105
- logger.success(t('commit_create_er_success').d('Routine created successfully.'));
106
- return yield uploadEdgeRoutineCode(edgeRoutine);
107
- }
108
- catch (error) {
109
- logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
110
- return false;
111
- }
112
- });
113
- }
114
- export function uploadEdgeRoutineCode(edgeRoutine) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- try {
117
- const server = yield ApiService.getInstance();
118
- const uploadResult = yield server.getRoutineStagingCodeUploadInfo(edgeRoutine);
119
- if (!uploadResult) {
120
- logger.error(t('commit_upload_fail').d('An error occurred while trying to upload your code'));
121
- process.exit(0);
122
- }
123
- logger.success(t('commit_upload_success').d('Code uploaded successfully.'));
124
- return true;
125
- }
126
- catch (error) {
127
- logger.error('123');
128
- logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
129
- process.exit(0);
130
- }
131
- });
132
- }
133
- export function releaseOfficialVersion(edgeRoutine) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- var _a;
136
- const param = {
137
- Name: edgeRoutine.name,
138
- CodeDescription: (_a = edgeRoutine.description) !== null && _a !== void 0 ? _a : ''
139
- };
140
- const server = yield ApiService.getInstance();
141
- const commitResult = yield server.commitRoutineStagingCode(param);
142
- if (commitResult) {
143
- logger.success(t('commit_success').d('Code version committed successfully.'));
144
- return true;
52
+ const { projectName } = projectInfo;
53
+ let description;
54
+ if (argv.description) {
55
+ description = argv.description;
145
56
  }
146
57
  else {
147
- logger.error(t('commit_fail').d('An error occurred while trying to commit your code.'));
148
- return false;
58
+ description = yield descriptionInput(`🖊️ ${t('commit_version_description').d('Enter a description for the version')}:`, false);
149
59
  }
60
+ yield generateCodeVersion(projectName, description, argv === null || argv === void 0 ? void 0 : argv.entry, argv === null || argv === void 0 ? void 0 : argv.assets, argv === null || argv === void 0 ? void 0 : argv.minify);
150
61
  });
151
62
  }
@@ -7,15 +7,14 @@ 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
+ import path from 'path';
10
12
  import esbuild from 'esbuild';
11
13
  import { lessLoader } from 'esbuild-plugin-less';
12
- import path from 'path';
13
- import fs from 'fs';
14
14
  import { getRoot } from '../../utils/fileUtils/base.js';
15
15
  import { NODE_EXTERNALS } from '../common/constant.js';
16
16
  const userRoot = getRoot();
17
17
  const entry = path.resolve(userRoot, 'src/index.js');
18
- const outfile = path.resolve(userRoot, '.dev/pub.js');
19
18
  export default function () {
20
19
  return __awaiter(this, arguments, void 0, function* (minify = false, customEntry, outputPath) {
21
20
  const entryPoint = customEntry
@@ -0,0 +1,276 @@
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 chalk from 'chalk';
11
+ import t from '../../i18n/index.js';
12
+ import { ApiService } from '../../libs/apiService.js';
13
+ import logger from '../../libs/logger.js';
14
+ import { ensureRoutineExists } from '../../utils/checkIsRoutineCreated.js';
15
+ import compress from '../../utils/compress.js';
16
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
17
+ import sleep from '../../utils/sleep.js';
18
+ import { checkIsLoginSuccess } from '../utils.js';
19
+ export function commitRoutineWithAssets(requestParams, zipBuffer) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ try {
22
+ const server = yield ApiService.getInstance();
23
+ const apiResult = yield server.CreateRoutineWithAssetsCodeVersion(requestParams);
24
+ if (!apiResult || !apiResult.data.OssPostConfig) {
25
+ return {
26
+ isSuccess: false,
27
+ res: null
28
+ };
29
+ }
30
+ const ossConfig = apiResult.data.OssPostConfig;
31
+ if (!ossConfig.OSSAccessKeyId ||
32
+ !ossConfig.Signature ||
33
+ !ossConfig.Url ||
34
+ !ossConfig.Key ||
35
+ !ossConfig.Policy) {
36
+ console.error('Missing required OSS configuration fields');
37
+ return {
38
+ isSuccess: false,
39
+ res: null
40
+ };
41
+ }
42
+ let uploadSuccess = false;
43
+ for (let i = 0; i < 3; i++) {
44
+ uploadSuccess = yield server.uploadToOss({
45
+ OSSAccessKeyId: ossConfig.OSSAccessKeyId,
46
+ Signature: ossConfig.Signature,
47
+ Url: ossConfig.Url,
48
+ Key: ossConfig.Key,
49
+ Policy: ossConfig.Policy,
50
+ XOssSecurityToken: ossConfig.XOssSecurityToken || ''
51
+ }, zipBuffer);
52
+ if (uploadSuccess) {
53
+ break;
54
+ }
55
+ }
56
+ return {
57
+ isSuccess: uploadSuccess,
58
+ res: apiResult
59
+ };
60
+ }
61
+ catch (error) {
62
+ console.error('Error in createRoutineWithAssetsCodeVersion:', error);
63
+ return {
64
+ isSuccess: false,
65
+ res: null
66
+ };
67
+ }
68
+ });
69
+ }
70
+ /**
71
+ * 通用的项目验证和初始化函数
72
+ * 包含目录检查、项目配置获取、登录检查、routine存在性检查
73
+ */
74
+ export function validateAndInitializeProject(name) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const projectConfig = getProjectConfig();
77
+ if (!projectConfig) {
78
+ logger.notInProject();
79
+ return null;
80
+ }
81
+ const projectName = name || projectConfig.name;
82
+ const isSuccess = yield checkIsLoginSuccess();
83
+ if (!isSuccess) {
84
+ return null;
85
+ }
86
+ yield ensureRoutineExists(projectName);
87
+ return { projectConfig, projectName };
88
+ });
89
+ }
90
+ /**
91
+ * 通用的routine详情获取函数
92
+ */
93
+ export function getRoutineDetails(projectName) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const server = yield ApiService.getInstance();
96
+ const req = { Name: projectName };
97
+ return yield server.getRoutine(req, false);
98
+ });
99
+ }
100
+ /**
101
+ * 通用的代码压缩和提交函数
102
+ * 支持assets和普通代码两种模式
103
+ */
104
+ export function generateCodeVersion(projectName_1, description_1, entry_1, assets_1) {
105
+ return __awaiter(this, arguments, void 0, function* (projectName, description, entry, assets, minify = false, projectPath) {
106
+ const zip = yield compress(entry, assets, minify, projectPath);
107
+ const res = yield commitRoutineWithAssets({
108
+ Name: projectName,
109
+ CodeDescription: description
110
+ }, zip === null || zip === void 0 ? void 0 : zip.toBuffer());
111
+ if (res === null || res === void 0 ? void 0 : res.isSuccess) {
112
+ logger.success('Your code has been successfully committed');
113
+ return {
114
+ isSuccess: true,
115
+ res: res === null || res === void 0 ? void 0 : res.res
116
+ };
117
+ }
118
+ else {
119
+ logger.error('Generate code version failed');
120
+ return {
121
+ isSuccess: false,
122
+ res: null
123
+ };
124
+ }
125
+ });
126
+ }
127
+ /**
128
+ * 根据 env 在一个或多个环境部署
129
+ */
130
+ export function deployToEnvironments(name, codeVersion, env) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ if (env === 'all') {
133
+ const isStagingSuccess = yield deployCodeVersion(name, codeVersion, 'staging');
134
+ const isProdSuccess = yield deployCodeVersion(name, codeVersion, 'production');
135
+ return isStagingSuccess && isProdSuccess;
136
+ }
137
+ return yield deployCodeVersion(name, codeVersion, env);
138
+ });
139
+ }
140
+ /**
141
+ * 通用的快速部署函数
142
+ * 结合了压缩、提交和部署的完整流程
143
+ */
144
+ export function commitAndDeployVersion(projectConfig_1, scriptEntry_1, assets_1) {
145
+ return __awaiter(this, arguments, void 0, function* (projectConfig, scriptEntry, assets, description = '', projectPath, env = 'production', minify = false, version) {
146
+ var _a, _b, _c;
147
+ if (version) {
148
+ return yield deployToEnvironments(projectConfig.name, version, env);
149
+ }
150
+ else {
151
+ const res = yield generateCodeVersion(projectConfig.name, description, scriptEntry || projectConfig.entry, assets || ((_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory), minify || projectConfig.minify, projectPath);
152
+ const isCommitSuccess = res === null || res === void 0 ? void 0 : res.isSuccess;
153
+ if (isCommitSuccess) {
154
+ const codeVersion = (_c = (_b = res === null || res === void 0 ? void 0 : res.res) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.CodeVersion;
155
+ if (!codeVersion) {
156
+ logger.error('Failed to read CodeVersion from response.');
157
+ return false;
158
+ }
159
+ return yield deployToEnvironments(projectConfig.name, codeVersion, env);
160
+ }
161
+ else {
162
+ return false;
163
+ }
164
+ }
165
+ });
166
+ }
167
+ /**
168
+ * 通用的版本部署函数
169
+ */
170
+ export function deployCodeVersion(name, codeVersion, environment) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ const server = yield ApiService.getInstance();
173
+ // Ensure the committed code version is ready before deploying
174
+ const isReady = yield waitForCodeVersionReady(name, codeVersion);
175
+ if (!isReady) {
176
+ logger.error('The code version is not ready for deployment.');
177
+ return false;
178
+ }
179
+ const res = yield server.createRoutineCodeDeployment({
180
+ Name: name,
181
+ CodeVersions: [{ Percentage: 100, CodeVersion: codeVersion }],
182
+ Strategy: 'percentage',
183
+ Env: environment
184
+ });
185
+ if (res) {
186
+ logger.success(`Your code has been successfully deployed to ${chalk.cyan(environment)}`);
187
+ return true;
188
+ }
189
+ else {
190
+ logger.error('Your code has not been deployed');
191
+ return false;
192
+ }
193
+ });
194
+ }
195
+ /**
196
+ * Poll routine code version status until it becomes ready
197
+ */
198
+ export function waitForCodeVersionReady(name_1, codeVersion_1) {
199
+ return __awaiter(this, arguments, void 0, function* (name, codeVersion, timeoutMs = 5 * 60 * 1000, intervalMs = 1000) {
200
+ var _a, _b;
201
+ if (!name || !codeVersion) {
202
+ return false;
203
+ }
204
+ const server = yield ApiService.getInstance();
205
+ const start = Date.now();
206
+ logger.log(`⏳ Waiting for code version ${chalk.cyan(codeVersion)} to be ready...`);
207
+ while (Date.now() - start < timeoutMs) {
208
+ try {
209
+ const info = yield server.getRoutineCodeVersionInfo({
210
+ Name: name,
211
+ CodeVersion: codeVersion
212
+ });
213
+ const status = (_b = (_a = info === null || info === void 0 ? void 0 : info.data) === null || _a === void 0 ? void 0 : _a.Status) === null || _b === void 0 ? void 0 : _b.toLowerCase();
214
+ if (status === 'init') {
215
+ yield sleep(intervalMs);
216
+ continue;
217
+ }
218
+ else if (status === 'available') {
219
+ logger.log(`✅ Code version ${chalk.cyan(codeVersion)} is ready.`);
220
+ return true;
221
+ }
222
+ else {
223
+ logger.error(`Code version ${chalk.cyan(codeVersion)} build ${status}.`);
224
+ return false;
225
+ }
226
+ }
227
+ catch (e) {
228
+ // swallow and retry until timeout
229
+ console.log(e);
230
+ }
231
+ }
232
+ logger.error(`⏰ Waiting for code version ${chalk.cyan(codeVersion)} timed out.`);
233
+ return false;
234
+ });
235
+ }
236
+ /**
237
+ * 通用的部署成功显示函数
238
+ * 显示部署成功信息、访问链接和后续操作指南
239
+ */
240
+ export function displayDeploySuccess(projectName_1) {
241
+ return __awaiter(this, arguments, void 0, function* (projectName, showDomainGuide = true, showRouteGuide = true) {
242
+ var _a;
243
+ const service = yield ApiService.getInstance();
244
+ const res = yield service.getRoutine({ Name: projectName });
245
+ const defaultUrl = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.DefaultRelatedRecord;
246
+ const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
247
+ if (showDomainGuide) {
248
+ logger.log(`👉 ${t('deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
249
+ }
250
+ if (showRouteGuide) {
251
+ logger.log(`👉 ${t('deploy_success_guide_2').d('Run this command to add routes')}: ${chalk.green('esa route add -r <ROUTE> -s <SITE>')}`);
252
+ }
253
+ logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
254
+ logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
255
+ });
256
+ }
257
+ /**
258
+ * 通用的快速部署函数(用于init命令)
259
+ * 结合了登录检查、routine创建、代码提交和部署的完整流程
260
+ */
261
+ export function quickDeployForInit(targetPath_1, projectConfig_1) {
262
+ return __awaiter(this, arguments, void 0, function* (targetPath, projectConfig, description = 'Quick deploy from init') {
263
+ var _a, _b;
264
+ const isLoginSuccess = yield checkIsLoginSuccess();
265
+ if (!isLoginSuccess) {
266
+ logger.log(chalk.yellow(t('not_login_auto_deploy').d('You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.')));
267
+ return false;
268
+ }
269
+ yield ensureRoutineExists(projectConfig.name);
270
+ const isProdSuccess = yield commitAndDeployVersion(projectConfig, projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry, (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory, description, targetPath, 'all');
271
+ if (isProdSuccess) {
272
+ yield displayDeploySuccess((_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '');
273
+ }
274
+ return isProdSuccess;
275
+ });
276
+ }
@@ -1,8 +1,8 @@
1
1
  import fs from 'fs';
2
2
  import spawn from 'cross-spawn';
3
- import { projectConfigPath, cliConfigPath } from '../utils/fileUtils/index.js';
4
3
  import t from '../i18n/index.js';
5
4
  import logger from '../libs/logger.js';
5
+ import { projectConfigPath, cliConfigPath } from '../utils/fileUtils/index.js';
6
6
  const editConfigFile = (configPath) => {
7
7
  const editor = process.env.EDITOR || 'vi';
8
8
  spawn(editor, [configPath], {
@@ -7,17 +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 chalk from 'chalk';
11
+ import moment from 'moment';
10
12
  import SelectItems from '../../components/selectInput.js';
11
13
  import { yesNoPrompt } from '../../components/yesNoPrompt.js';
14
+ import t from '../../i18n/index.js';
12
15
  import { PublishType } from '../../libs/interface.js';
13
- import { ApiService } from '../../libs/apiService.js';
14
- import { descriptionInput } from '../../components/descriptionInput.js';
15
- import { readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
16
- import { displaySelectSpec } from './index.js';
17
- import { createEdgeRoutine, releaseOfficialVersion, uploadEdgeRoutineCode } from '../commit/index.js';
18
16
  import logger from '../../libs/logger.js';
19
- import t from '../../i18n/index.js';
20
- import prodBuild from '../commit/prodBuild.js';
21
17
  export function yesNoPromptAndExecute(message, execute) {
22
18
  return new Promise((resolve) => {
23
19
  yesNoPrompt((item) => __awaiter(this, void 0, void 0, function* () {
@@ -33,11 +29,14 @@ export function yesNoPromptAndExecute(message, execute) {
33
29
  }
34
30
  export function promptSelectVersion(versionList) {
35
31
  const items = versionList
36
- .filter((version) => version.CodeVersion !== 'unstable')
37
- .map((version, index) => ({
38
- label: version.CodeVersion,
39
- value: String(index)
40
- }));
32
+ .filter((version) => version.codeVersion !== 'unstable')
33
+ .map((version, index) => {
34
+ var _a;
35
+ return ({
36
+ label: (_a = version.codeVersion) !== null && _a !== void 0 ? _a : '',
37
+ value: String(index)
38
+ });
39
+ });
41
40
  return new Promise((resolve) => {
42
41
  const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () {
43
42
  resolve(item.label);
@@ -45,15 +44,14 @@ export function promptSelectVersion(versionList) {
45
44
  SelectItems({ items, handleSelect: handleSelection });
46
45
  });
47
46
  }
48
- export function displaySelectDeployType() {
47
+ export function displaySelectDeployEnv() {
49
48
  logger.log(`📃 ${t('deploy_env_select_description').d('Please select which environment you want to deploy')}`);
50
49
  const selectItems = [
51
50
  { label: t('deploy_env_staging').d('Staging'), value: PublishType.Staging },
52
51
  {
53
52
  label: t('deploy_env_production').d('Production'),
54
53
  value: PublishType.Production
55
- },
56
- { label: t('deploy_env_canary').d('Canary'), value: PublishType.Canary }
54
+ }
57
55
  ];
58
56
  return new Promise((resolve) => {
59
57
  const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () {
@@ -62,52 +60,33 @@ export function displaySelectDeployType() {
62
60
  SelectItems({ items: selectItems, handleSelect: handleSelection });
63
61
  });
64
62
  }
65
- export function createAndDeployVersion(projectConfig_1) {
66
- return __awaiter(this, arguments, void 0, function* (projectConfig, createUnstable = false, customEntry) {
67
- var _a, _b, _c, _d;
68
- try {
69
- const server = yield ApiService.getInstance();
70
- const description = yield descriptionInput(createUnstable
71
- ? `🖊️ ${t('deploy_description_routine').d('Enter the description of the routine')}:`
72
- : `🖊️ ${t('deploy_description_version').d('Enter the description of the code version')}:`, false);
73
- yield prodBuild(false, customEntry);
74
- const code = readEdgeRoutineFile();
75
- const specList = ((_b = (_a = (yield server.ListRoutineOptionalSpecs())) === null || _a === void 0 ? void 0 : _a.data.Specs) !== null && _b !== void 0 ? _b : []).reduce((acc, item) => {
76
- if (item.IsAvailable) {
77
- acc.push(item.SpecName);
78
- }
79
- return acc;
80
- }, []);
81
- let specName;
82
- if (createUnstable) {
83
- specName = yield displaySelectSpec(specList);
84
- }
85
- else {
86
- const req = { Name: (_c = projectConfig.name) !== null && _c !== void 0 ? _c : '' };
87
- const response = yield server.getRoutine(req);
88
- specName = (_d = response === null || response === void 0 ? void 0 : response.data.Envs[0].SpecName) !== null && _d !== void 0 ? _d : '50ms';
89
- }
90
- const edgeRoutine = {
91
- name: projectConfig.name,
92
- code: code || '',
93
- description: description,
94
- specName: specName
95
- };
96
- if (createUnstable) {
97
- return yield createEdgeRoutine(edgeRoutine);
98
- }
99
- else {
100
- const uploadResult = yield uploadEdgeRoutineCode(edgeRoutine);
101
- if (!uploadResult) {
102
- return false;
103
- }
104
- return yield releaseOfficialVersion(edgeRoutine);
105
- }
106
- }
107
- catch (error) {
108
- logger.error(`
109
- ${t('deploy_error').d('An error occurred during the creation or publishing process')}: ${error}`);
110
- return false;
63
+ export function displayVersionList(allVersions, stagingVersions, productionVersions) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ var _a, _b, _c;
66
+ logger.log(`${chalk.bgYellow('Active')} ${t('deploy_env_staging').d('Staging')}`);
67
+ logger.log(`${chalk.bgGreen('Active')} ${t('deploy_env_production').d('Production')}`);
68
+ const data = [];
69
+ for (let i = 0; i < allVersions.length; i++) {
70
+ const version = allVersions[i];
71
+ const createTime = moment(version.createTime).format('YYYY/MM/DD HH:mm:ss');
72
+ const tags = [
73
+ stagingVersions.includes((_a = version.codeVersion) !== null && _a !== void 0 ? _a : '')
74
+ ? chalk.bgYellow('Active')
75
+ : '',
76
+ productionVersions.includes((_b = version.codeVersion) !== null && _b !== void 0 ? _b : '')
77
+ ? chalk.bgGreen('Active')
78
+ : ''
79
+ ];
80
+ data.push([
81
+ `${version.codeVersion} ${tags.join(' ')}`,
82
+ createTime,
83
+ (_c = version.codeDescription) !== null && _c !== void 0 ? _c : ''
84
+ ]);
111
85
  }
86
+ logger.table([
87
+ t('deploy_table_header_version').d('Version'),
88
+ t('deploy_table_header_created').d('Created'),
89
+ t('deploy_table_header_description').d('Description')
90
+ ], data);
112
91
  });
113
92
  }