esa-cli 0.0.2-beta.1 โ†’ 0.0.2-beta.12

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 (51) hide show
  1. package/dist/commands/commit/index.js +34 -25
  2. package/dist/commands/common/constant.js +0 -19
  3. package/dist/commands/deploy/helper.js +10 -26
  4. package/dist/commands/deploy/index.js +49 -60
  5. package/dist/commands/deployments/delete.js +1 -16
  6. package/dist/commands/deployments/index.js +1 -1
  7. package/dist/commands/deployments/list.js +8 -15
  8. package/dist/commands/dev/ew2/cacheService.js +33 -0
  9. package/dist/commands/dev/ew2/devEntry.js +2 -1
  10. package/dist/commands/dev/ew2/devPack.js +13 -26
  11. package/dist/commands/dev/ew2/kvService.js +27 -0
  12. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  13. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  14. package/dist/commands/dev/ew2/server.js +152 -19
  15. package/dist/commands/dev/index.js +4 -4
  16. package/dist/commands/dev/mockWorker/devPack.js +16 -14
  17. package/dist/commands/domain/add.js +1 -1
  18. package/dist/commands/domain/delete.js +4 -4
  19. package/dist/commands/domain/index.js +1 -1
  20. package/dist/commands/domain/list.js +3 -3
  21. package/dist/commands/init/helper.js +137 -0
  22. package/dist/commands/init/index.js +183 -187
  23. package/dist/commands/login/index.js +49 -3
  24. package/dist/commands/logout.js +1 -1
  25. package/dist/commands/route/add.js +50 -52
  26. package/dist/commands/route/delete.js +29 -23
  27. package/dist/commands/route/helper.js +124 -0
  28. package/dist/commands/route/index.js +1 -1
  29. package/dist/commands/route/list.js +53 -14
  30. package/dist/commands/routine/index.js +1 -1
  31. package/dist/commands/routine/list.js +4 -5
  32. package/dist/commands/site/index.js +1 -1
  33. package/dist/commands/utils.js +5 -5
  34. package/dist/components/mutiLevelSelect.js +44 -55
  35. package/dist/docs/Commands_en.md +27 -13
  36. package/dist/docs/Commands_zh_CN.md +14 -0
  37. package/dist/docs/Dev_en.md +0 -0
  38. package/dist/docs/Dev_zh_CN.md +0 -0
  39. package/dist/i18n/locales.json +144 -12
  40. package/dist/index.js +6 -9
  41. package/dist/libs/api.js +32 -9
  42. package/dist/libs/apiService.js +88 -78
  43. package/dist/libs/interface.js +0 -1
  44. package/dist/libs/logger.js +1 -1
  45. package/dist/libs/templates/index.js +2 -1
  46. package/dist/utils/checkIsRoutineCreated.js +7 -12
  47. package/dist/utils/checkVersion.js +1 -1
  48. package/dist/utils/download.js +182 -0
  49. package/dist/utils/fileUtils/base.js +1 -1
  50. package/dist/utils/installDeno.js +7 -7
  51. package/package.json +5 -5
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { getProjectConfig, readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
11
11
  import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
12
- import { displaySelectSpec } from '../deploy/index.js';
13
12
  import { descriptionInput } from '../../components/descriptionInput.js';
14
13
  import { ApiService } from '../../libs/apiService.js';
15
14
  import prodBuild from './prodBuild.js';
@@ -18,7 +17,7 @@ import t from '../../i18n/index.js';
18
17
  import { exit } from 'process';
19
18
  const commit = {
20
19
  command: 'commit [entry]',
21
- describe: `๐Ÿ“ฅ ${t('commit_describe').d('Commit your code, save as a new version')}`,
20
+ describe: `๐Ÿ“ฆ ${t('commit_describe').d('Commit your code, save as a new version')}`,
22
21
  builder: (yargs) => {
23
22
  return yargs
24
23
  .option('minify', {
@@ -26,6 +25,11 @@ const commit = {
26
25
  describe: t('commit_option_minify').d('Minify code before committing'),
27
26
  type: 'boolean',
28
27
  default: false
28
+ })
29
+ .option('description', {
30
+ alias: 'd',
31
+ describe: t('commit_option_description').d('Description for the routine/version (skip interactive input)'),
32
+ type: 'string'
29
33
  })
30
34
  .positional('entry', {
31
35
  describe: t('dev_entry_describe').d('Entry file of the Routine'),
@@ -34,13 +38,13 @@ const commit = {
34
38
  });
35
39
  },
36
40
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
37
- handleCommit(argv);
41
+ yield handleCommit(argv);
42
+ exit();
38
43
  })
39
44
  };
40
45
  export default commit;
41
46
  export function handleCommit(argv) {
42
47
  return __awaiter(this, void 0, void 0, function* () {
43
- var _a, _b, _c;
44
48
  if (!checkDirectory())
45
49
  return;
46
50
  const projectConfig = getProjectConfig();
@@ -53,41 +57,45 @@ export function handleCommit(argv) {
53
57
  const server = yield ApiService.getInstance();
54
58
  const req = { Name: projectConfig.name };
55
59
  const response = yield server.getRoutine(req, false);
56
- let specName = (_a = response === null || response === void 0 ? void 0 : response.data.Envs[0].SpecName) !== null && _a !== void 0 ? _a : '50ms';
57
60
  let action = 'Creating';
58
61
  let description;
59
62
  if (!response) {
60
63
  logger.log(`๐Ÿ™… ${t('commit_er_not_exist').d('No routine found, creating a new one')}`);
61
- description = yield descriptionInput(`๐Ÿ–Š๏ธ ${t('commit_er_description').d('Enter a description for the routine')}:`, false);
62
- const specList = ((_c = (_b = (yield server.ListRoutineOptionalSpecs())) === null || _b === void 0 ? void 0 : _b.data.Specs) !== null && _c !== void 0 ? _c : []).reduce((acc, item) => {
63
- if (item.IsAvailable) {
64
- acc.push(item.SpecName);
65
- }
66
- return acc;
67
- }, []);
68
- specName = yield displaySelectSpec(specList);
64
+ if (argv.description) {
65
+ description = argv.description;
66
+ }
67
+ else {
68
+ description = yield descriptionInput(`๐Ÿ–Š๏ธ ${t('commit_er_description').d('Enter a description for the routine')}:`, false);
69
+ }
69
70
  }
70
71
  else {
71
72
  logger.log(`๐Ÿ”„ ${t('commit_er_exist').d('Routine exists, updating the code')}`);
72
- description = yield descriptionInput(`๐Ÿ–Š๏ธ ${t('commit_version_description').d('Enter a description for the version')}:`, false);
73
+ if (argv.description) {
74
+ description = argv.description;
75
+ }
76
+ else {
77
+ description = yield descriptionInput(`๐Ÿ–Š๏ธ ${t('commit_version_description').d('Enter a description for the version')}:`, false);
78
+ }
73
79
  action = 'Updating';
74
80
  }
75
81
  const code = readEdgeRoutineFile() || '';
76
- const edgeRoutine = {
82
+ if (action === 'Creating') {
83
+ const edgeRoutineProps = {
84
+ name: projectConfig.name,
85
+ code,
86
+ description: ''
87
+ };
88
+ yield createEdgeRoutine(edgeRoutineProps);
89
+ }
90
+ const versionProps = {
77
91
  name: projectConfig.name,
78
92
  code,
79
- description,
80
- specName
93
+ description: description
81
94
  };
82
- if (action === 'Creating') {
83
- yield createEdgeRoutine(edgeRoutine);
84
- }
85
- else {
86
- if (!(yield uploadEdgeRoutineCode(edgeRoutine)))
87
- return;
88
- yield releaseOfficialVersion(edgeRoutine);
95
+ const uploadResult = yield uploadEdgeRoutineCode(versionProps);
96
+ if (uploadResult) {
97
+ yield releaseOfficialVersion(versionProps);
89
98
  }
90
- exit(0);
91
99
  }
92
100
  catch (error) {
93
101
  logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
@@ -126,6 +134,7 @@ export function uploadEdgeRoutineCode(edgeRoutine) {
126
134
  return true;
127
135
  }
128
136
  catch (error) {
137
+ logger.error('123');
129
138
  logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
130
139
  process.exit(0);
131
140
  }
@@ -1,23 +1,4 @@
1
1
  import t from '../../i18n/index.js';
2
- export const SUMMARIES_LIST = [
3
- {
4
- title: t('summery_cd').d('Enter your routine project folder'),
5
- command: '๐Ÿ’ก cd [Your Routine Name]'
6
- },
7
- {
8
- title: t('summery_dev').d('Start a local development server for your project'),
9
- command: '๐Ÿ’ก esa dev'
10
- },
11
- {
12
- title: t('summery_commit').d('Save a new version of code'),
13
- command: '๐Ÿ’ก esa commit'
14
- },
15
- // Use Deploy or Release?
16
- {
17
- title: t('summery_deploy').d('Deploy your project to different environments'),
18
- command: '๐Ÿ’ก esa deploy'
19
- }
20
- ];
21
2
  export const getSummary = (routineName) => {
22
3
  return [
23
4
  {
@@ -13,7 +13,6 @@ import { PublishType } from '../../libs/interface.js';
13
13
  import { ApiService } from '../../libs/apiService.js';
14
14
  import { descriptionInput } from '../../components/descriptionInput.js';
15
15
  import { readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
16
- import { displaySelectSpec } from './index.js';
17
16
  import { createEdgeRoutine, releaseOfficialVersion, uploadEdgeRoutineCode } from '../commit/index.js';
18
17
  import logger from '../../libs/logger.js';
19
18
  import t from '../../i18n/index.js';
@@ -33,11 +32,14 @@ export function yesNoPromptAndExecute(message, execute) {
33
32
  }
34
33
  export function promptSelectVersion(versionList) {
35
34
  const items = versionList
36
- .filter((version) => version.CodeVersion !== 'unstable')
37
- .map((version, index) => ({
38
- label: version.CodeVersion,
39
- value: String(index)
40
- }));
35
+ .filter((version) => version.codeVersion !== 'unstable')
36
+ .map((version, index) => {
37
+ var _a;
38
+ return ({
39
+ label: (_a = version.codeVersion) !== null && _a !== void 0 ? _a : '',
40
+ value: String(index)
41
+ });
42
+ });
41
43
  return new Promise((resolve) => {
42
44
  const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () {
43
45
  resolve(item.label);
@@ -52,8 +54,7 @@ export function displaySelectDeployType() {
52
54
  {
53
55
  label: t('deploy_env_production').d('Production'),
54
56
  value: PublishType.Production
55
- },
56
- { label: t('deploy_env_canary').d('Canary'), value: PublishType.Canary }
57
+ }
57
58
  ];
58
59
  return new Promise((resolve) => {
59
60
  const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () {
@@ -64,7 +65,6 @@ export function displaySelectDeployType() {
64
65
  }
65
66
  export function createAndDeployVersion(projectConfig_1) {
66
67
  return __awaiter(this, arguments, void 0, function* (projectConfig, createUnstable = false, customEntry) {
67
- var _a, _b, _c, _d;
68
68
  try {
69
69
  const server = yield ApiService.getInstance();
70
70
  const description = yield descriptionInput(createUnstable
@@ -72,26 +72,10 @@ export function createAndDeployVersion(projectConfig_1) {
72
72
  : `๐Ÿ–Š๏ธ ${t('deploy_description_version').d('Enter the description of the code version')}:`, false);
73
73
  yield prodBuild(false, customEntry);
74
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
75
  const edgeRoutine = {
91
76
  name: projectConfig.name,
92
77
  code: code || '',
93
- description: description,
94
- specName: specName
78
+ description: description
95
79
  };
96
80
  if (createUnstable) {
97
81
  return yield createEdgeRoutine(edgeRoutine);
@@ -9,12 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import chalk from 'chalk';
11
11
  import { getProjectConfig, readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
12
- import SelectItems from '../../components/selectInput.js';
13
12
  import { Environment, PublishType } from '../../libs/interface.js';
14
13
  import logger from '../../libs/logger.js';
15
14
  import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
16
- import { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
17
- import { Base64 } from 'js-base64';
18
15
  import { ApiService } from '../../libs/apiService.js';
19
16
  import { createAndDeployVersion, displaySelectDeployType, promptSelectVersion, yesNoPromptAndExecute } from './helper.js';
20
17
  import t from '../../i18n/index.js';
@@ -34,12 +31,25 @@ const deploy = {
34
31
  })
35
32
  .option('quick', {
36
33
  alias: 'q',
34
+ describe: t('deploy_quick_describe').d('Quick deploy the routine to production environment'),
37
35
  type: 'boolean'
36
+ })
37
+ .option('version', {
38
+ alias: 'v',
39
+ describe: t('deploy_option_version').d('Version to deploy (skip interactive selection)'),
40
+ type: 'string'
41
+ })
42
+ .option('environment', {
43
+ alias: 'e',
44
+ describe: t('deploy_option_environment').d('Environment to deploy to: staging or production (skip interactive selection)'),
45
+ type: 'string',
46
+ choices: ['staging', 'production']
38
47
  });
39
48
  },
40
49
  describe: `๐Ÿš€ ${t('deploy_describe').d('Deploy your project')}`,
41
50
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
42
- handleDeploy(argv);
51
+ yield handleDeploy(argv);
52
+ exit();
43
53
  })
44
54
  };
45
55
  export default deploy;
@@ -59,13 +69,13 @@ export function quickDeploy(entry, projectConfig) {
59
69
  }
60
70
  else {
61
71
  logger.error(t('quick_deploy_failed').d('Quick deploy failed'));
62
- process.exit(0);
72
+ throw Error(t('quick_deploy_failed').d('Quick deploy failed'));
63
73
  }
64
74
  });
65
75
  }
66
76
  export function handleDeploy(argv) {
67
77
  return __awaiter(this, void 0, void 0, function* () {
68
- var _a, _b, _c, _d, _e;
78
+ var _a, _b, _c, _d;
69
79
  if (!checkDirectory()) {
70
80
  return;
71
81
  }
@@ -80,10 +90,10 @@ export function handleDeploy(argv) {
80
90
  yield checkRoutineExist(projectConfig.name, entry);
81
91
  const req = { Name: projectConfig.name };
82
92
  const routineDetail = yield server.getRoutine(req, false);
83
- const versionList = ((_a = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _a === void 0 ? void 0 : _a.CodeVersions) || [];
93
+ const versionList = yield getRoutineVersionList(projectConfig.name);
84
94
  const customEntry = argv.entry;
85
- const stagingVersion = (_c = (_b = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _b === void 0 ? void 0 : _b.Envs[1]) === null || _c === void 0 ? void 0 : _c.CodeVersion;
86
- const productionVersion = (_e = (_d = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _d === void 0 ? void 0 : _d.Envs[0]) === null || _e === void 0 ? void 0 : _e.CodeVersion;
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;
87
97
  if (argv.quick) {
88
98
  yield quickDeploy(customEntry, projectConfig);
89
99
  exit(0);
@@ -94,27 +104,33 @@ export function handleDeploy(argv) {
94
104
  }
95
105
  else {
96
106
  yield displayVersionList(versionList, stagingVersion, productionVersion);
97
- logger.log(chalk.bold(`${t('deploy_version_select').d('Select the version you want to publish')}:`));
98
- const selectedVersion = yield promptSelectVersion(versionList);
99
- const selectedType = yield displaySelectDeployType();
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
+ }
100
130
  yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
101
131
  }
102
132
  });
103
133
  }
104
- export function displaySelectSpec(specList) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- logger.log(`๐Ÿ“ƒ ${t('deploy_spec_select').d('Please select the spec of the routine you want to create')}`);
107
- const selectItems = specList.map((spec) => {
108
- return { label: spec, value: spec };
109
- });
110
- return new Promise((resolve) => {
111
- const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () {
112
- resolve(item.value);
113
- });
114
- SelectItems({ items: selectItems, handleSelect: handleSelection });
115
- });
116
- });
117
- }
118
134
  function handleNoVersionsFound(projectConfig, customEntry) {
119
135
  return __awaiter(this, void 0, void 0, function* () {
120
136
  logger.log(`๐Ÿ˜„ ${t('deploy_first_time').d("This is first time to deploy. Let's create a version first!")}`);
@@ -134,20 +150,6 @@ function promptAndDeployVersion(projectConfig) {
134
150
  yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
135
151
  });
136
152
  }
137
- const specialAreaTransfer = (canaryAreaSelectList) => {
138
- return canaryAreaSelectList.map((item) => {
139
- if (item.label === 'HongKong') {
140
- return { label: 'HongKong(China)' };
141
- }
142
- if (item.label === 'Macau') {
143
- return { label: 'Macau(China)' };
144
- }
145
- if (item.label === 'Taiwan') {
146
- return { label: 'Taiwan(China)' };
147
- }
148
- return { label: item.label };
149
- });
150
- };
151
153
  export function handleOnlyUnstableVersionFound(projectConfig, customEntry) {
152
154
  return __awaiter(this, void 0, void 0, function* () {
153
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));
@@ -158,7 +160,6 @@ export function handleOnlyUnstableVersionFound(projectConfig, customEntry) {
158
160
  }
159
161
  export function deploySelectedCodeVersion(name, selectedType, version) {
160
162
  return __awaiter(this, void 0, void 0, function* () {
161
- var _a;
162
163
  const server = yield ApiService.getInstance();
163
164
  const param = {
164
165
  Name: name,
@@ -166,20 +167,7 @@ export function deploySelectedCodeVersion(name, selectedType, version) {
166
167
  ? Environment.Staging
167
168
  : Environment.Production
168
169
  };
169
- if (selectedType === PublishType.Canary) {
170
- const res = yield server.listRoutineCanaryAreas();
171
- const canaryList = (_a = res === null || res === void 0 ? void 0 : res.CanaryAreas) !== null && _a !== void 0 ? _a : [];
172
- logger.log(`๐Ÿ“ƒ ${t('deploy_select_canary').d('Please select the canary area(s) you want to deploy to')}`);
173
- const canaryAreaSelectList = canaryList.map((area) => {
174
- return { label: area };
175
- });
176
- const selectedCanaryList = yield displayMultiSelectTable(specialAreaTransfer(canaryAreaSelectList));
177
- param.CanaryAreaList = selectedCanaryList;
178
- param.CanaryCodeVersion = version;
179
- }
180
- else {
181
- param.CodeVersion = version;
182
- }
170
+ param.CodeVersion = version;
183
171
  try {
184
172
  const res = yield server.publishRoutineCodeVersion(param);
185
173
  if (res) {
@@ -194,20 +182,21 @@ export function deploySelectedCodeVersion(name, selectedType, version) {
194
182
  }
195
183
  export function displayVersionList(versionList_1) {
196
184
  return __awaiter(this, arguments, void 0, function* (versionList, stagingVersion = 'unstable', productionVersion = 'unstable') {
185
+ var _a;
197
186
  logger.log(`${chalk.bgYellow('Active')} ${t('deploy_env_staging').d('Staging')}`);
198
187
  logger.log(`${chalk.bgGreen('Active')} ${t('deploy_env_production').d('Production')}`);
199
188
  const data = [];
200
189
  for (let i = 0; i < versionList.length; i++) {
201
190
  const version = versionList[i];
202
- const createTime = moment(version.CreateTime).format('YYYY/MM/DD HH:mm:ss');
191
+ const createTime = moment(version.createTime).format('YYYY/MM/DD HH:mm:ss');
203
192
  const tags = [
204
- version.CodeVersion === stagingVersion ? chalk.bgYellow('Active') : '',
205
- version.CodeVersion === productionVersion ? chalk.bgGreen('Active') : ''
193
+ version.codeVersion === stagingVersion ? chalk.bgYellow('Active') : '',
194
+ version.codeVersion === productionVersion ? chalk.bgGreen('Active') : ''
206
195
  ];
207
196
  data.push([
208
- `${version.CodeVersion} ${tags.join(' ')}`,
197
+ `${version.codeVersion} ${tags.join(' ')}`,
209
198
  createTime,
210
- Base64.decode(version.CodeDescription)
199
+ (_a = version.codeDescription) !== null && _a !== void 0 ? _a : ''
211
200
  ]);
212
201
  }
213
202
  logger.table([
@@ -13,7 +13,6 @@ import { ApiService } from '../../libs/apiService.js';
13
13
  import t from '../../i18n/index.js';
14
14
  import logger from '../../libs/logger.js';
15
15
  import { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
16
- import { Base64 } from 'js-base64';
17
16
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
18
17
  const deploymentsDelete = {
19
18
  command: 'delete [deploymentId..]',
@@ -49,27 +48,13 @@ export function handleDeleteDeployments(argv) {
49
48
  yield validRoutine(projectConfig.name);
50
49
  const server = yield ApiService.getInstance();
51
50
  let versions = argv.deploymentId;
52
- // const req: DeleteRoutineCodeVersionReq = {
53
- // Name: projectConfig.name,
54
- // CodeVersion: version
55
- // };
56
- // const res = await server.deleteRoutineCodeVersion(req);
57
- // if (res?.Status === 'OK') {
58
- // logger.success(
59
- // `${t('deployments_delete_success').d('Delete success')}: ${version}`
60
- // );
61
- // } else {
62
- // logger.error(
63
- // `๐Ÿ™… ${t('deployments_delete_failed').d('Delete failed')}: ${version}`
64
- // );
65
- // }
66
51
  const isInteractive = argv.i;
67
52
  if (isInteractive) {
68
53
  const versionList = yield getRoutineVersionList(projectConfig.name);
69
54
  logger.log(t('delete_deployments_table_title').d(' Version ID Description'));
70
55
  const selectList = versionList.map((item) => {
71
56
  return {
72
- label: item.CodeVersion + ' ' + Base64.decode(item.CodeDescription)
57
+ label: item.codeVersion + ' ' + item.codeDescription
73
58
  };
74
59
  });
75
60
  versions = (yield displayMultiSelectTable(selectList, 1, 100)).map((item) => item.slice(0, item.indexOf(' ')));
@@ -4,7 +4,7 @@ import t from '../../i18n/index.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
@@ -52,21 +52,17 @@ export function handleListDeployments(argv) {
52
52
  }
53
53
  function displayListPrompt(routineDetail) {
54
54
  return __awaiter(this, void 0, void 0, function* () {
55
- var _a, _b, _c, _d, _e;
56
- const isCanary = ((_a = routineDetail.data.Envs[0].CanaryAreaList) !== null && _a !== void 0 ? _a : []).length !== 0;
57
- const canaryEnv = routineDetail.data.Envs[0];
55
+ var _a, _b;
58
56
  const stagingEnv = routineDetail.data.Envs[1];
57
+ const prodEnv = routineDetail.data.Envs[0];
59
58
  const server = yield ApiService.getInstance();
60
59
  const res = yield server.getRoutineStagingEnvIp();
61
- const stagingIpList = (_c = (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.IPV4) !== null && _c !== void 0 ? _c : [];
60
+ 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 : [];
62
61
  const coloredStagingIpList = stagingIpList.map((ip) => {
63
62
  return chalk.green(ip);
64
63
  });
65
- const showEnvTable = (version, spec, region) => {
66
- const data = [
67
- { Version: version },
68
- { Specification: spec }
69
- ];
64
+ const showEnvTable = (version, region) => {
65
+ const data = [{ Version: version }];
70
66
  if (region) {
71
67
  data.push({ Region: region });
72
68
  }
@@ -76,13 +72,10 @@ function displayListPrompt(routineDetail) {
76
72
  if (stagingIpList.length > 0) {
77
73
  logger.log(`Staging IP: ${coloredStagingIpList.join(', ')}`);
78
74
  }
79
- showEnvTable(stagingEnv.CodeVersion, stagingEnv.SpecName);
75
+ showEnvTable(stagingEnv.CodeVersion);
80
76
  logger.block();
81
- logger.log(`${chalk.bold(`${t('deploy_env_production').d('Production')} ${!isCanary ? chalk.green('โ—') : ''}`)}`);
82
- showEnvTable(canaryEnv.CodeVersion, canaryEnv.SpecName);
83
- logger.block();
84
- logger.log(`${chalk.bold(`${t('deploy_env_canary').d('Canary')} ${isCanary ? chalk.green('โ—') : ''}`)}`);
85
- showEnvTable((_d = canaryEnv.CanaryCodeVersion) !== null && _d !== void 0 ? _d : '', canaryEnv.SpecName, (_e = canaryEnv.CanaryAreaList) === null || _e === void 0 ? void 0 : _e.join(', '));
77
+ logger.log(`${chalk.bold(`${t('deploy_env_production').d('Production')} ${chalk.green('โ—')}`)}`);
78
+ showEnvTable(prodEnv.CodeVersion);
86
79
  logger.log(`${t('show_default_url').d(`You can visit:`)} ${chalk.yellowBright(routineDetail.data.DefaultRelatedRecord)}`);
87
80
  logger.info(routineDetail.data.DefaultRelatedRecord);
88
81
  logger.block();
@@ -0,0 +1,33 @@
1
+ class CacheService {
2
+ constructor() {
3
+ this.store = new Map();
4
+ this.maxQuota = 100 * 1024 * 1024;
5
+ }
6
+ put(key, serializedResponse) {
7
+ const expires = serializedResponse.ttl === 0
8
+ ? Infinity
9
+ : Date.now() + serializedResponse.ttl * 1000;
10
+ this.store.set(key, {
11
+ serializedResponse,
12
+ expires: expires,
13
+ lastUsed: Date.now()
14
+ });
15
+ }
16
+ get(key) {
17
+ const entry = this.store.get(key);
18
+ if (!entry || Date.now() > entry.expires) {
19
+ return null;
20
+ }
21
+ entry.lastUsed = Date.now();
22
+ return entry;
23
+ }
24
+ delete(key) {
25
+ return this.deleteEntry(key);
26
+ }
27
+ deleteEntry(key) {
28
+ if (!this.store.has(key))
29
+ return false;
30
+ return this.store.delete(key);
31
+ }
32
+ }
33
+ export default CacheService;
@@ -2,8 +2,9 @@ import worker from '$userPath';
2
2
  import Cache from './mock/cache.js';
3
3
  import mockKV from './mock/kv.js';
4
4
 
5
- var mock_cache = await Cache.init('mock');
5
+ var mock_cache = new Cache($userPort);
6
6
  globalThis.mockCache = mock_cache;
7
+ mockKV.port = $userPort;
7
8
  globalThis.mockKV = mockKV;
8
9
 
9
10
  export default worker;
@@ -61,7 +61,7 @@ conf_path = "${erConfPath}"
61
61
  ]);
62
62
  };
63
63
  // ็”Ÿๆˆๅ…ฅๅฃๆ–‡ไปถ
64
- const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
64
+ const generateEntry = (id, projectEntry, userRoot, port) => __awaiter(void 0, void 0, void 0, function* () {
65
65
  const __dirname = getDirName(import.meta.url);
66
66
  const devDir = path.resolve(userRoot, '.dev');
67
67
  const devEntry = path.resolve(devDir, `devEntry-${id}.js`);
@@ -81,7 +81,9 @@ const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0,
81
81
  const destPath = path.resolve(mockDevDir, file);
82
82
  yield fs.promises.copyFile(srcPath, destPath);
83
83
  }
84
- return fs.promises.writeFile(devEntry, devEntryTempFile.replace(/'\$userPath'/g, `'${projectEntry}'`));
84
+ return fs.promises.writeFile(devEntry, devEntryTempFile
85
+ .replace(/'\$userPath'/g, `'${projectEntry.replace(/\\/g, '/')}'`)
86
+ .replace(/\$userPort/g, `${port}`));
85
87
  });
86
88
  // ๅ‰ๆœŸๅ‡†ๅค‡
87
89
  const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
@@ -92,7 +94,7 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
92
94
  // @ts-ignore
93
95
  global.id = id;
94
96
  // ็”Ÿๆˆๅ…ฅๅฃๆ–‡ไปถ
95
- yield generateEntry(id, entry, userRoot);
97
+ yield generateEntry(id, entry, userRoot, port);
96
98
  // ็”Ÿๆˆ Ew2 ้…็ฝฎ
97
99
  const ew2port = yield generateEw2Port();
98
100
  yield writeEw2config(id, ew2port, userRoot);
@@ -106,27 +108,13 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
106
108
  if (currentIds[0] && /^\d+$/.test(currentIds[0])) {
107
109
  // ๅˆ ้™คๆฒกๆœ‰็”จๅˆฐ็š„ๅ…ฅๅฃ
108
110
  for (let currentId of currentIds) {
109
- const useful = yield checkPort(currentConfigObj[currentId].port);
110
- if (useful) {
111
- const unusedEntry = path.resolve(userRoot, `.dev/index-${currentId}.js`);
112
- const unusedTemp = path.resolve(userRoot, `.dev/devEntry-${currentId}.js`);
113
- const unusedConfig = path.resolve(userRoot, `.dev/config-${currentId}.toml`);
114
- if (fs.existsSync(unusedEntry)) {
115
- fs.rmSync(unusedEntry, {
116
- force: true,
117
- recursive: true,
118
- maxRetries: 5
119
- });
120
- }
121
- if (fs.existsSync(unusedTemp)) {
122
- fs.rmSync(unusedTemp, {
123
- force: true,
124
- recursive: true,
125
- maxRetries: 5
126
- });
127
- }
128
- if (fs.existsSync(unusedConfig)) {
129
- fs.rmSync(unusedConfig, {
111
+ const unused = yield checkPort(currentConfigObj[currentId].port);
112
+ if (unused) {
113
+ const devDir = path.resolve(userRoot, '.dev');
114
+ const files = fs.readdirSync(devDir);
115
+ const filesToDelete = files.filter((file) => file.includes(currentId));
116
+ for (const file of filesToDelete) {
117
+ fs.rmSync(path.resolve(devDir, file), {
130
118
  force: true,
131
119
  recursive: true,
132
120
  maxRetries: 5
@@ -164,8 +152,7 @@ const devPack = (...args_1) => __awaiter(void 0, [...args_1], void 0, function*
164
152
  .then(() => {
165
153
  logger.ora.succeed(t('dev_pack_config_success').d('Config created successfully'));
166
154
  return devBuild({
167
- minify,
168
- isNode: true
155
+ minify
169
156
  });
170
157
  })
171
158
  .then(() => {
@@ -0,0 +1,27 @@
1
+ class EdgeKV {
2
+ constructor() { }
3
+ get(key, namespace) {
4
+ const store = EdgeKV.store.get(namespace);
5
+ if (!store || !store.has(key)) {
6
+ return;
7
+ }
8
+ return store.get(key);
9
+ }
10
+ put(key, value, namespace) {
11
+ let store = EdgeKV.store.get(namespace);
12
+ if (!store) {
13
+ EdgeKV.store.set(namespace, new Map([[key, value]]));
14
+ }
15
+ else {
16
+ store.set(key, value);
17
+ }
18
+ }
19
+ delete(key, namespace) {
20
+ const store = EdgeKV.store.get(namespace);
21
+ if (!store)
22
+ return false;
23
+ return store.delete(key);
24
+ }
25
+ }
26
+ EdgeKV.store = new Map();
27
+ export default EdgeKV;