esa-cli 0.0.2-beta.12 → 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 (70) hide show
  1. package/dist/commands/commit/index.js +20 -119
  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 +31 -36
  6. package/dist/commands/deploy/index.js +78 -165
  7. package/dist/commands/deployments/delete.js +31 -6
  8. package/dist/commands/deployments/index.js +3 -3
  9. package/dist/commands/deployments/list.js +18 -27
  10. package/dist/commands/dev/build.js +3 -3
  11. package/dist/commands/dev/doProcess.js +5 -5
  12. package/dist/commands/dev/ew2/devPack.js +17 -8
  13. package/dist/commands/dev/ew2/mock/kv.js +2 -2
  14. package/dist/commands/dev/ew2/server.js +13 -10
  15. package/dist/commands/dev/index.js +12 -12
  16. package/dist/commands/dev/mockWorker/devPack.js +16 -7
  17. package/dist/commands/dev/mockWorker/server.js +7 -6
  18. package/dist/commands/domain/add.js +3 -3
  19. package/dist/commands/domain/delete.js +3 -3
  20. package/dist/commands/domain/index.js +3 -3
  21. package/dist/commands/domain/list.js +7 -7
  22. package/dist/commands/init/helper.js +59 -9
  23. package/dist/commands/init/index.js +416 -76
  24. package/dist/commands/init/template.jsonc +34 -0
  25. package/dist/commands/lang.js +2 -2
  26. package/dist/commands/login/index.js +9 -5
  27. package/dist/commands/logout.js +6 -6
  28. package/dist/commands/route/add.js +134 -43
  29. package/dist/commands/route/delete.js +6 -6
  30. package/dist/commands/route/index.js +3 -3
  31. package/dist/commands/route/list.js +4 -4
  32. package/dist/commands/routine/delete.js +2 -2
  33. package/dist/commands/routine/index.js +3 -3
  34. package/dist/commands/routine/list.js +5 -16
  35. package/dist/commands/site/index.js +2 -2
  36. package/dist/commands/site/list.js +6 -7
  37. package/dist/commands/utils.js +55 -19
  38. package/dist/components/descriptionInput.js +1 -1
  39. package/dist/components/mutiSelectTable.js +1 -1
  40. package/dist/components/selectInput.js +2 -3
  41. package/dist/components/selectItem.js +1 -1
  42. package/dist/docs/Commands_en.md +12 -16
  43. package/dist/docs/Commands_zh_CN.md +12 -16
  44. package/dist/docs/eslint-config-en.md +1 -0
  45. package/dist/docs/eslint-config.md +73 -0
  46. package/dist/docs/init-command-quick-test.md +208 -0
  47. package/dist/docs/init-command-test-guide.md +598 -0
  48. package/dist/i18n/index.js +2 -2
  49. package/dist/i18n/locales.json +161 -9
  50. package/dist/index.js +11 -11
  51. package/dist/libs/apiService.js +177 -14
  52. package/dist/libs/git/index.js +8 -4
  53. package/dist/libs/logger.js +63 -7
  54. package/dist/libs/service.js +2 -2
  55. package/dist/libs/templates/index.js +1 -1
  56. package/dist/utils/checkAssetsExist.js +80 -0
  57. package/dist/utils/checkDevPort.js +3 -17
  58. package/dist/utils/checkEntryFileExist.js +10 -0
  59. package/dist/utils/checkIsRoutineCreated.js +17 -16
  60. package/dist/utils/checkVersion.js +1 -1
  61. package/dist/utils/compress.js +80 -0
  62. package/dist/utils/download.js +5 -5
  63. package/dist/utils/fileMd5.js +1 -1
  64. package/dist/utils/fileUtils/index.js +71 -22
  65. package/dist/utils/installDeno.js +3 -3
  66. package/dist/utils/installEw2.js +7 -7
  67. package/dist/utils/openInBrowser.js +1 -1
  68. package/package.json +9 -3
  69. package/dist/docs/Dev_en.md +0 -0
  70. package/dist/docs/Dev_zh_CN.md +0 -0
@@ -7,19 +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 chalk from 'chalk';
11
- import { getProjectConfig, readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
12
- import { Environment, PublishType } from '../../libs/interface.js';
13
- import logger from '../../libs/logger.js';
14
- import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
15
- import { ApiService } from '../../libs/apiService.js';
16
- import { createAndDeployVersion, displaySelectDeployType, promptSelectVersion, yesNoPromptAndExecute } from './helper.js';
17
- import t from '../../i18n/index.js';
18
- import prodBuild from '../commit/prodBuild.js';
19
10
  import { exit } from 'process';
20
- import path from 'path';
21
- import { checkRoutineExist } from '../../utils/checkIsRoutineCreated.js';
22
- import moment from 'moment';
11
+ import t from '../../i18n/index.js';
12
+ import { validateAndInitializeProject, commitAndDeployVersion, displayDeploySuccess } from '../common/routineUtils.js';
23
13
  const deploy = {
24
14
  command: 'deploy [entry]',
25
15
  builder: (yargs) => {
@@ -28,11 +18,6 @@ const deploy = {
28
18
  describe: t('dev_entry_describe').d('Entry file of the Routine'),
29
19
  type: 'string',
30
20
  demandOption: false
31
- })
32
- .option('quick', {
33
- alias: 'q',
34
- describe: t('deploy_quick_describe').d('Quick deploy the routine to production environment'),
35
- type: 'boolean'
36
21
  })
37
22
  .option('version', {
38
23
  alias: 'v',
@@ -44,6 +29,31 @@ const deploy = {
44
29
  describe: t('deploy_option_environment').d('Environment to deploy to: staging or production (skip interactive selection)'),
45
30
  type: 'string',
46
31
  choices: ['staging', 'production']
32
+ })
33
+ .option('name', {
34
+ alias: 'n',
35
+ describe: t('deploy_option_name').d('Name of the routine'),
36
+ type: 'string'
37
+ })
38
+ .option('assets', {
39
+ alias: 'a',
40
+ describe: t('deploy_option_assets').d('Deploy assets'),
41
+ type: 'boolean'
42
+ })
43
+ .option('description', {
44
+ alias: 'd',
45
+ describe: t('deploy_option_description').d('Description of the version'),
46
+ type: 'string'
47
+ })
48
+ .option('minify', {
49
+ alias: 'm',
50
+ describe: t('deploy_option_minify').d('Minify the code'),
51
+ type: 'boolean'
52
+ })
53
+ .option('minify', {
54
+ alias: 'm',
55
+ describe: t('deploy_option_minify').d('Minify the code'),
56
+ type: 'boolean'
47
57
  });
48
58
  },
49
59
  describe: `🚀 ${t('deploy_describe').d('Deploy your project')}`,
@@ -52,157 +62,60 @@ const deploy = {
52
62
  exit();
53
63
  })
54
64
  };
55
- export default deploy;
56
- export function quickDeploy(entry, projectConfig) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const server = yield ApiService.getInstance();
59
- const entryFile = path.resolve(entry !== null && entry !== void 0 ? entry : '', 'src/index.js');
60
- yield prodBuild(false, entryFile, entry);
61
- const code = readEdgeRoutineFile(entry) || '';
62
- const res = yield server.quickDeployRoutine({
63
- name: projectConfig.name,
64
- code: code
65
- });
66
- if (res) {
67
- logger.success(t('quick_deploy_success').d('Your code has been successfully deployed'));
68
- logger.log(`👉 ${t('quick_deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
69
- }
70
- else {
71
- logger.error(t('quick_deploy_failed').d('Quick deploy failed'));
72
- throw Error(t('quick_deploy_failed').d('Quick deploy failed'));
73
- }
74
- });
75
- }
76
65
  export function handleDeploy(argv) {
77
66
  return __awaiter(this, void 0, void 0, function* () {
78
- var _a, _b, _c, _d;
79
- if (!checkDirectory()) {
80
- return;
81
- }
82
- const projectConfig = getProjectConfig();
83
- if (!projectConfig)
84
- return logger.notInProject();
85
- const isSuccess = yield checkIsLoginSuccess();
86
- if (!isSuccess)
87
- return;
88
- const server = yield ApiService.getInstance();
89
- const entry = argv.entry;
90
- yield checkRoutineExist(projectConfig.name, entry);
91
- const req = { Name: projectConfig.name };
92
- const routineDetail = yield server.getRoutine(req, false);
93
- const versionList = yield getRoutineVersionList(projectConfig.name);
94
- const customEntry = argv.entry;
95
- const stagingVersion = (_b = (_a = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _a === void 0 ? void 0 : _a.Envs[1]) === null || _b === void 0 ? void 0 : _b.CodeVersion;
96
- const productionVersion = (_d = (_c = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _c === void 0 ? void 0 : _c.Envs[0]) === null || _d === void 0 ? void 0 : _d.CodeVersion;
97
- if (argv.quick) {
98
- yield quickDeploy(customEntry, projectConfig);
99
- exit(0);
100
- }
101
- if (versionList.length === 0) {
102
- logger.log(t('no_formal_version_found').d('No formal version found, you need to create a version first.'));
103
- yield handleOnlyUnstableVersionFound(projectConfig, customEntry);
104
- }
105
- else {
106
- yield displayVersionList(versionList, stagingVersion, productionVersion);
107
- let selectedVersion;
108
- let selectedType;
109
- // Check if version and environment are provided via command line arguments
110
- if (argv.version && argv.environment) {
111
- // Validate version exists
112
- const versionExists = versionList.some((v) => v.codeVersion === argv.version);
113
- if (!versionExists) {
114
- logger.error(t('deploy_version_not_found').d(`Version '${argv.version}' not found`));
115
- return;
116
- }
117
- selectedVersion = argv.version;
118
- selectedType =
119
- argv.environment === 'staging'
120
- ? PublishType.Staging
121
- : PublishType.Production;
122
- logger.log(chalk.bold(`${t('deploy_using_version').d('Using version')}: ${selectedVersion}`));
123
- logger.log(chalk.bold(`${t('deploy_using_environment').d('Using environment')}: ${argv.environment}`));
124
- }
125
- else {
126
- logger.log(chalk.bold(`${t('deploy_version_select').d('Select the version you want to publish')}:`));
127
- selectedVersion = yield promptSelectVersion(versionList);
128
- selectedType = yield displaySelectDeployType();
129
- }
130
- yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
131
- }
132
- });
133
- }
134
- function handleNoVersionsFound(projectConfig, customEntry) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- logger.log(`😄 ${t('deploy_first_time').d("This is first time to deploy. Let's create a version first!")}`);
137
- const created = yield yesNoPromptAndExecute(`📃 ${t('deploy_create_formal_version_ques').d('Do you want to create an unstable version now?')}`, () => createAndDeployVersion(projectConfig, true));
138
- if (created) {
139
- yield handleOnlyUnstableVersionFound(projectConfig);
140
- }
141
- });
142
- }
143
- function promptAndDeployVersion(projectConfig) {
144
- return __awaiter(this, void 0, void 0, function* () {
145
- const versionList = yield getRoutineVersionList(projectConfig.name);
146
- yield displayVersionList(versionList);
147
- logger.log(`📃 ${t('deploy_select_version').d("Select which version you'd like to deploy")}`);
148
- const selectedVersion = yield promptSelectVersion(versionList);
149
- const selectedType = yield displaySelectDeployType();
150
- yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
151
- });
152
- }
153
- export function handleOnlyUnstableVersionFound(projectConfig, customEntry) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- const created = yield yesNoPromptAndExecute(`📃 ${t('deploy_create_formal_version_ques').d('Do you want to create a formal version to deploy on production environment?')}`, () => createAndDeployVersion(projectConfig));
156
- if (created) {
157
- yield promptAndDeployVersion(projectConfig);
158
- }
159
- });
160
- }
161
- export function deploySelectedCodeVersion(name, selectedType, version) {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- const server = yield ApiService.getInstance();
164
- const param = {
165
- Name: name,
166
- Env: selectedType === PublishType.Staging
167
- ? Environment.Staging
168
- : Environment.Production
169
- };
170
- param.CodeVersion = version;
171
- try {
172
- const res = yield server.publishRoutineCodeVersion(param);
173
- if (res) {
174
- logger.success(t('deploy_success').d('Your code has been successfully deployed'));
175
- logger.log(`👉 ${t('deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
176
- }
177
- }
178
- catch (e) {
179
- console.error(e);
180
- }
181
- });
182
- }
183
- export function displayVersionList(versionList_1) {
184
- return __awaiter(this, arguments, void 0, function* (versionList, stagingVersion = 'unstable', productionVersion = 'unstable') {
185
67
  var _a;
186
- logger.log(`${chalk.bgYellow('Active')} ${t('deploy_env_staging').d('Staging')}`);
187
- logger.log(`${chalk.bgGreen('Active')} ${t('deploy_env_production').d('Production')}`);
188
- const data = [];
189
- for (let i = 0; i < versionList.length; i++) {
190
- const version = versionList[i];
191
- const createTime = moment(version.createTime).format('YYYY/MM/DD HH:mm:ss');
192
- const tags = [
193
- version.codeVersion === stagingVersion ? chalk.bgYellow('Active') : '',
194
- version.codeVersion === productionVersion ? chalk.bgGreen('Active') : ''
195
- ];
196
- data.push([
197
- `${version.codeVersion} ${tags.join(' ')}`,
198
- createTime,
199
- (_a = version.codeDescription) !== null && _a !== void 0 ? _a : ''
200
- ]);
68
+ const projectInfo = yield validateAndInitializeProject(argv === null || argv === void 0 ? void 0 : argv.name);
69
+ if (!projectInfo)
70
+ return;
71
+ const { projectConfig, projectName } = projectInfo;
72
+ const entry = argv.entry || projectConfig.entry;
73
+ const assets = argv.assets || ((_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory);
74
+ const success = yield commitAndDeployVersion(projectConfig, entry, assets, argv.description || '', undefined, argv.environment, argv.minify, argv.version);
75
+ if (success) {
76
+ yield displayDeploySuccess(projectName, true, false);
201
77
  }
202
- logger.table([
203
- t('deploy_table_header_version').d('Version'),
204
- t('deploy_table_header_created').d('Created'),
205
- t('deploy_table_header_description').d('Description')
206
- ], data, [30, 25, 15]);
78
+ // if (allVersions.length === 0) {
79
+ // logger.log(
80
+ // t('no_formal_version_found').d(
81
+ // 'No formal version found, you need to create a version first.'
82
+ // )
83
+ // );
84
+ // const commitRes = await generateCodeVersion(projectName, '', entry, assets);
85
+ // if (!commitRes?.isSuccess) {
86
+ // exit(0);
87
+ // }
88
+ // }
89
+ // const {
90
+ // allVersions: committedVersionList,
91
+ // stagingVersions,
92
+ // productionVersions
93
+ // } = await getRoutineCodeVersions(projectName);
94
+ // await displayVersionList(
95
+ // committedVersionList,
96
+ // stagingVersions,
97
+ // productionVersions
98
+ // );
99
+ // const selectedVersion =
100
+ // (argv.version as string) ||
101
+ // (await promptSelectVersion(committedVersionList));
102
+ // const selectedEnvironment =
103
+ // (argv.environment as string) || (await displaySelectDeployEnv());
104
+ // if (
105
+ // selectedEnvironment !== PublishType.Staging &&
106
+ // selectedEnvironment !== PublishType.Production
107
+ // ) {
108
+ // logger.error(t('deploy_invalid_environment').d('Invalid environment'));
109
+ // exit(0);
110
+ // }
111
+ // const success = await deployCodeVersion(
112
+ // projectName,
113
+ // selectedVersion,
114
+ // selectedEnvironment as PublishType
115
+ // );
116
+ // if (success) {
117
+ // await displayDeploySuccess(projectName, true, true);
118
+ // }
207
119
  });
208
120
  }
121
+ export default deploy;
@@ -7,13 +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 { getProjectConfig } from '../../utils/fileUtils/index.js';
11
- import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
12
- import { ApiService } from '../../libs/apiService.js';
10
+ import chalk from 'chalk';
11
+ import { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
13
12
  import t from '../../i18n/index.js';
13
+ import { ApiService } from '../../libs/apiService.js';
14
14
  import logger from '../../libs/logger.js';
15
- import { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
16
15
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
16
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
17
+ import { checkDirectory, checkIsLoginSuccess, getRoutineCodeVersions } from '../utils.js';
17
18
  const deploymentsDelete = {
18
19
  command: 'delete [deploymentId..]',
19
20
  describe: `🗑 ${t('deployments_delete_describe').d('Delete one or more deployment versions')}`,
@@ -50,13 +51,37 @@ export function handleDeleteDeployments(argv) {
50
51
  let versions = argv.deploymentId;
51
52
  const isInteractive = argv.i;
52
53
  if (isInteractive) {
53
- const versionList = yield getRoutineVersionList(projectConfig.name);
54
+ const { allVersions, stagingVersions, productionVersions } = yield getRoutineCodeVersions(projectConfig.name);
55
+ // 显示正在部署的版本信息
56
+ if (stagingVersions.length > 0 || productionVersions.length > 0) {
57
+ logger.log(chalk.yellow('⚠️ Currently deploying versions:'));
58
+ if (stagingVersions.length > 0) {
59
+ logger.log(chalk.yellow(` Staging: ${stagingVersions.join(',')}`));
60
+ }
61
+ if (productionVersions.length > 0) {
62
+ logger.log(chalk.yellow(` Production: ${productionVersions.join(',')}`));
63
+ }
64
+ logger.log('');
65
+ }
54
66
  logger.log(t('delete_deployments_table_title').d(' Version ID Description'));
55
- const selectList = versionList.map((item) => {
67
+ // 过滤掉正在部署的版本
68
+ const selectList = allVersions
69
+ .filter((item) => {
70
+ var _a, _b;
71
+ if (stagingVersions.length === 0 && productionVersions.length === 0)
72
+ return true;
73
+ return (!stagingVersions.includes((_a = item.codeVersion) !== null && _a !== void 0 ? _a : '') &&
74
+ !productionVersions.includes((_b = item.codeVersion) !== null && _b !== void 0 ? _b : ''));
75
+ })
76
+ .map((item) => {
56
77
  return {
57
78
  label: item.codeVersion + ' ' + item.codeDescription
58
79
  };
59
80
  });
81
+ if (selectList.length === 0) {
82
+ logger.error('No deletable versions found. All versions are currently deployed.');
83
+ return;
84
+ }
60
85
  versions = (yield displayMultiSelectTable(selectList, 1, 100)).map((item) => item.slice(0, item.indexOf(' ')));
61
86
  }
62
87
  for (let i = 0; i < versions.length; i++) {
@@ -1,10 +1,10 @@
1
- import deploymentsList from './list.js';
2
- import deploymentsDelete from './delete.js';
3
1
  import t from '../../i18n/index.js';
2
+ import deploymentsDelete from './delete.js';
3
+ import deploymentsList from './list.js';
4
4
  let yargsIns;
5
5
  const deploymentsCommand = {
6
6
  command: 'deployments [script]',
7
- describe: `📜 ${t('deployments_describe').d('Manage your deployments')}`,
7
+ describe: `🚀 ${t('deployments_describe').d('Manage your deployments')}`,
8
8
  builder: (yargs) => {
9
9
  yargsIns = yargs;
10
10
  return yargs
@@ -7,28 +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 { displayVersionList } from '../deploy/index.js';
11
- import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
12
- import { getProjectConfig } from '../../utils/fileUtils/index.js';
13
10
  import chalk from 'chalk';
14
- import { ApiService } from '../../libs/apiService.js';
15
11
  import t from '../../i18n/index.js';
12
+ import { ApiService } from '../../libs/apiService.js';
16
13
  import logger from '../../libs/logger.js';
17
14
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
15
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
16
+ import { displayVersionList } from '../deploy/helper.js';
17
+ import { checkIsLoginSuccess, getRoutineCodeVersions } from '../utils.js';
18
18
  const deploymentsList = {
19
19
  command: 'list',
20
20
  describe: `🔍 ${t('deployments_list_describe').d('List all deployments')}`,
21
- handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
22
- handleListDeployments(argv);
21
+ handler: () => __awaiter(void 0, void 0, void 0, function* () {
22
+ handleListDeployments();
23
23
  })
24
24
  };
25
25
  export default deploymentsList;
26
- export function handleListDeployments(argv) {
26
+ export function handleListDeployments() {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
- var _a, _b, _c, _d;
29
- if (!checkDirectory()) {
30
- return;
31
- }
32
28
  const projectConfig = getProjectConfig();
33
29
  if (!projectConfig)
34
30
  return logger.notInProject();
@@ -37,45 +33,40 @@ export function handleListDeployments(argv) {
37
33
  return;
38
34
  yield validRoutine(projectConfig.name);
39
35
  const server = yield ApiService.getInstance();
40
- const versionList = yield getRoutineVersionList(projectConfig.name);
41
36
  const req = { Name: projectConfig.name };
42
37
  const routineDetail = yield server.getRoutine(req);
43
38
  if (!routineDetail)
44
39
  return;
45
- //测试环境版本
46
- const stagingVersion = (_b = (_a = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _a === void 0 ? void 0 : _a.Envs[1]) === null || _b === void 0 ? void 0 : _b.CodeVersion;
47
- //生产环境版本
48
- const productionVersion = (_d = (_c = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _c === void 0 ? void 0 : _c.Envs[0]) === null || _d === void 0 ? void 0 : _d.CodeVersion;
49
- yield displayListPrompt(routineDetail);
50
- yield displayVersionList(versionList, stagingVersion, productionVersion);
40
+ const { allVersions, stagingVersions, productionVersions } = yield getRoutineCodeVersions(projectConfig.name);
41
+ yield displayDeployingVersions(routineDetail, stagingVersions, productionVersions);
42
+ yield displayVersionList(allVersions, stagingVersions, productionVersions);
51
43
  });
52
44
  }
53
- function displayListPrompt(routineDetail) {
45
+ function displayDeployingVersions(routineDetail, stagingVersions, productionVersions) {
54
46
  return __awaiter(this, void 0, void 0, function* () {
55
47
  var _a, _b;
56
- const stagingEnv = routineDetail.data.Envs[1];
57
- const prodEnv = routineDetail.data.Envs[0];
58
48
  const server = yield ApiService.getInstance();
59
49
  const res = yield server.getRoutineStagingEnvIp();
60
50
  const stagingIpList = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.IPV4) !== null && _b !== void 0 ? _b : [];
61
51
  const coloredStagingIpList = stagingIpList.map((ip) => {
62
52
  return chalk.green(ip);
63
53
  });
64
- const showEnvTable = (version, region) => {
54
+ const showEnvTable = (version) => {
65
55
  const data = [{ Version: version }];
66
- if (region) {
67
- data.push({ Region: region });
68
- }
69
56
  logger.table([], data);
70
57
  };
71
58
  logger.log(chalk.bold(t('deploy_env_staging').d('Staging')));
72
59
  if (stagingIpList.length > 0) {
73
60
  logger.log(`Staging IP: ${coloredStagingIpList.join(', ')}`);
74
61
  }
75
- showEnvTable(stagingEnv.CodeVersion);
62
+ if (stagingVersions.length > 0) {
63
+ showEnvTable(stagingVersions.join(','));
64
+ }
76
65
  logger.block();
77
66
  logger.log(`${chalk.bold(`${t('deploy_env_production').d('Production')} ${chalk.green('●')}`)}`);
78
- showEnvTable(prodEnv.CodeVersion);
67
+ if (productionVersions.length > 0) {
68
+ showEnvTable(productionVersions.join(','));
69
+ }
79
70
  logger.log(`${t('show_default_url').d(`You can visit:`)} ${chalk.yellowBright(routineDetail.data.DefaultRelatedRecord)}`);
80
71
  logger.info(routineDetail.data.DefaultRelatedRecord);
81
72
  logger.block();
@@ -1,12 +1,12 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import _generator from '@babel/generator';
4
+ import parser from '@babel/parser';
5
+ import _traverse from '@babel/traverse';
3
6
  import esbuild from 'esbuild';
4
7
  import { lessLoader } from 'esbuild-plugin-less';
5
8
  import { getRoot } from '../../utils/fileUtils/base.js';
6
9
  import { NODE_EXTERNALS } from '../common/constant.js';
7
- import parser from '@babel/parser';
8
- import _traverse from '@babel/traverse';
9
- import _generator from '@babel/generator';
10
10
  const replacements = { cache: 'mockCache', EdgeKV: 'mockKV' };
11
11
  const traverse = _traverse.default;
12
12
  const generator = _generator.default;
@@ -7,14 +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 React, { useEffect } from 'react';
11
- import { Box, Text, useApp, useInput, render } from 'ink';
12
10
  import chalk from 'chalk';
11
+ import { Box, Text, useApp, useInput, render } from 'ink';
12
+ import React, { useEffect } from 'react';
13
+ import t from '../../i18n/index.js';
13
14
  import logger from '../../libs/logger.js';
14
- import openInBrowser from '../../utils/openInBrowser.js';
15
- import { getDevOpenBrowserUrl } from '../../utils/fileUtils/index.js';
16
15
  import { checkOS, Platforms } from '../../utils/checkOS.js';
17
- import t from '../../i18n/index.js';
16
+ import { getDevOpenBrowserUrl } from '../../utils/fileUtils/index.js';
17
+ import openInBrowser from '../../utils/openInBrowser.js';
18
18
  const InteractionBox = ({ worker }) => {
19
19
  const { exit } = useApp();
20
20
  const inspectLink = chalk.underline.blue('chrome://inspect/#devices');
@@ -7,15 +7,15 @@ 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 path from 'path';
11
10
  import fs from 'fs';
12
- import logger from '../../../libs/logger.js';
13
- import devBuild from '../build.js';
11
+ import path from 'path';
14
12
  import t from '../../../i18n/index.js';
15
- import { getDevConf } from '../../../utils/fileUtils/index.js';
16
- import { getRoot, getDirName } from '../../../utils/fileUtils/base.js';
13
+ import logger from '../../../libs/logger.js';
17
14
  import { checkPort } from '../../../utils/checkDevPort.js';
15
+ import { getRoot, getDirName } from '../../../utils/fileUtils/base.js';
16
+ import { getDevConf } from '../../../utils/fileUtils/index.js';
18
17
  import { EW2Path } from '../../../utils/installEw2.js';
18
+ import devBuild from '../build.js';
19
19
  // 生成可用的Ew2端口
20
20
  const generateEw2Port = () => __awaiter(void 0, void 0, void 0, function* () {
21
21
  let ew2port = 3322;
@@ -129,13 +129,22 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
129
129
  }
130
130
  return fs.promises.writeFile(configPath, `export default ${JSON.stringify(Object.assign(options, { [id]: currentOptions }))}`);
131
131
  });
132
- const devPack = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (restarting = false) {
132
+ const devPack = () => __awaiter(void 0, void 0, void 0, function* () {
133
133
  logger.ora.start('Processing...\n');
134
134
  const userRoot = getRoot();
135
- const configPath = path.resolve(userRoot, 'esa.toml');
135
+ // Try to find config file in order of preference: .jsonc, .toml
136
+ const configFormats = ['esa.jsonc', 'esa.toml'];
137
+ let configPath = null;
138
+ for (const format of configFormats) {
139
+ const testPath = path.resolve(userRoot, format);
140
+ if (fs.existsSync(testPath)) {
141
+ configPath = testPath;
142
+ break;
143
+ }
144
+ }
136
145
  let port, minify, localUpstream, entry;
137
146
  let projectEntry = path.resolve(userRoot, 'src/index.js');
138
- if (fs.existsSync(configPath)) {
147
+ if (configPath) {
139
148
  port = getDevConf('port', 'dev', 18080);
140
149
  minify = getDevConf('minify', 'dev', false);
141
150
  localUpstream = getDevConf('localUpstream', 'dev', '');
@@ -134,10 +134,10 @@ class EdgeKV {
134
134
  );
135
135
  }
136
136
  case 'stream':
137
- const value = await fetchRes.text();
137
+ const stream = fetchRes.body;
138
138
  return new ReadableStream({
139
139
  start(controller) {
140
- controller.enqueue(new TextEncoder().encode(value));
140
+ controller.enqueue(new TextEncoder().encode('hello world'));
141
141
  controller.close();
142
142
  }
143
143
  });
@@ -8,17 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import * as http from 'http';
11
+ import chalk from 'chalk';
11
12
  import spawn from 'cross-spawn';
13
+ import { HttpProxyAgent } from 'http-proxy-agent';
12
14
  import fetch from 'node-fetch';
15
+ import t from '../../../i18n/index.js';
13
16
  import logger from '../../../libs/logger.js';
14
17
  import { getRoot } from '../../../utils/fileUtils/base.js';
15
18
  import { EW2BinPath } from '../../../utils/installEw2.js';
16
- import { HttpProxyAgent } from 'http-proxy-agent';
17
- import chalk from 'chalk';
19
+ import sleep from '../../../utils/sleep.js';
18
20
  import CacheService from './cacheService.js';
19
21
  import EdgeKV from './kvService.js';
20
- import t from '../../../i18n/index.js';
21
- import sleep from '../../../utils/sleep.js';
22
22
  const getColorForStatusCode = (statusCode, message) => {
23
23
  if (statusCode >= 100 && statusCode < 200) {
24
24
  return chalk.blue(`${statusCode} ${message}`);
@@ -87,8 +87,9 @@ class Ew2Server {
87
87
  stdio: ['pipe', 'pipe', 'pipe']
88
88
  });
89
89
  this.workerStartTimeout = setTimeout(() => {
90
+ var _a;
90
91
  reject(new Error(t('dev_worker_timeout').d('Worker start timeout')));
91
- this.worker && this.worker.kill();
92
+ (_a = this.worker) === null || _a === void 0 ? void 0 : _a.kill();
92
93
  }, 60000);
93
94
  const sendToRuntime = () => {
94
95
  return new Promise((resolveStart) => {
@@ -102,7 +103,7 @@ class Ew2Server {
102
103
  const req = http.get(options, (res) => {
103
104
  resolveStart(res.statusCode);
104
105
  });
105
- req.on('error', (err) => {
106
+ req.on('error', () => {
106
107
  resolveStart(null);
107
108
  });
108
109
  req.end();
@@ -125,7 +126,8 @@ class Ew2Server {
125
126
  this.worker.on('close', this.closeHandler.bind(this));
126
127
  this.worker.on('error', this.errorHandler.bind(this));
127
128
  process.on('SIGTERM', () => {
128
- this.worker && this.worker.kill();
129
+ var _a;
130
+ (_a = this.worker) === null || _a === void 0 ? void 0 : _a.kill();
129
131
  });
130
132
  });
131
133
  }
@@ -277,17 +279,18 @@ class Ew2Server {
277
279
  }
278
280
  this.stop();
279
281
  }
280
- closeHandler(code, signal) {
282
+ closeHandler() {
281
283
  if (this.restarting) {
282
284
  this.restarting = false;
283
285
  return;
284
286
  }
285
287
  this.stop().then(() => {
288
+ var _a;
286
289
  logger.log(t('dev_server_closed').d('Worker server closed'));
287
290
  logger.info('Worker server closed');
288
291
  // @ts-ignore
289
292
  global.port = undefined;
290
- this.onClose && this.onClose();
293
+ (_a = this.onClose) === null || _a === void 0 ? void 0 : _a.call(this);
291
294
  });
292
295
  }
293
296
  parseCacheBody(req) {
@@ -343,7 +346,7 @@ class Ew2Server {
343
346
  resolve(false);
344
347
  return;
345
348
  }
346
- const onExit = (code, signal) => {
349
+ const onExit = () => {
347
350
  this.worker = null;
348
351
  resolve(true);
349
352
  };