esa-cli 0.0.2-beta.2 → 0.0.2-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/commands/commit/index.js +45 -117
  2. package/dist/commands/commit/prodBuild.js +2 -3
  3. package/dist/commands/common/constant.js +0 -19
  4. package/dist/commands/common/utils.js +419 -0
  5. package/dist/commands/config.js +1 -1
  6. package/dist/commands/deploy/helper.js +51 -72
  7. package/dist/commands/deploy/index.js +48 -187
  8. package/dist/commands/deployments/delete.js +32 -22
  9. package/dist/commands/deployments/index.js +3 -3
  10. package/dist/commands/deployments/list.js +22 -38
  11. package/dist/commands/dev/build.js +3 -3
  12. package/dist/commands/dev/doProcess.js +5 -5
  13. package/dist/commands/dev/ew2/cacheService.js +33 -0
  14. package/dist/commands/dev/ew2/devEntry.js +2 -1
  15. package/dist/commands/dev/ew2/devPack.js +30 -34
  16. package/dist/commands/dev/ew2/kvService.js +46 -0
  17. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  18. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  19. package/dist/commands/dev/ew2/server.js +165 -28
  20. package/dist/commands/dev/index.js +16 -16
  21. package/dist/commands/dev/mockWorker/devPack.js +32 -21
  22. package/dist/commands/dev/mockWorker/server.js +7 -6
  23. package/dist/commands/domain/add.js +3 -3
  24. package/dist/commands/domain/delete.js +7 -7
  25. package/dist/commands/domain/index.js +3 -3
  26. package/dist/commands/domain/list.js +10 -10
  27. package/dist/commands/init/helper.js +761 -0
  28. package/dist/commands/init/index.js +88 -220
  29. package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
  30. package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
  31. package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
  32. package/dist/commands/init/template.jsonc +84 -0
  33. package/dist/commands/init/types.js +1 -0
  34. package/dist/commands/lang.js +2 -2
  35. package/dist/commands/login/index.js +74 -34
  36. package/dist/commands/logout.js +6 -6
  37. package/dist/commands/route/add.js +138 -49
  38. package/dist/commands/route/delete.js +33 -27
  39. package/dist/commands/route/helper.js +124 -0
  40. package/dist/commands/route/index.js +3 -3
  41. package/dist/commands/route/list.js +56 -17
  42. package/dist/commands/routine/delete.js +2 -2
  43. package/dist/commands/routine/index.js +3 -3
  44. package/dist/commands/routine/list.js +9 -21
  45. package/dist/commands/site/index.js +2 -2
  46. package/dist/commands/site/list.js +6 -7
  47. package/dist/commands/utils.js +55 -19
  48. package/dist/components/descriptionInput.js +1 -1
  49. package/dist/components/mutiLevelSelect.js +43 -55
  50. package/dist/components/mutiSelectTable.js +1 -1
  51. package/dist/components/selectInput.js +2 -3
  52. package/dist/components/selectItem.js +1 -1
  53. package/dist/docs/Commands_en.md +142 -131
  54. package/dist/docs/Commands_zh_CN.md +139 -127
  55. package/dist/i18n/index.js +2 -2
  56. package/dist/i18n/locales.json +401 -21
  57. package/dist/index.js +27 -20
  58. package/dist/libs/api.js +32 -9
  59. package/dist/libs/apiService.js +262 -84
  60. package/dist/libs/git/index.js +86 -9
  61. package/dist/libs/interface.js +0 -1
  62. package/dist/libs/logger.js +162 -10
  63. package/dist/libs/service.js +2 -2
  64. package/dist/libs/templates/index.js +3 -2
  65. package/dist/utils/checkAssetsExist.js +80 -0
  66. package/dist/utils/checkDevPort.js +3 -17
  67. package/dist/utils/checkEntryFileExist.js +10 -0
  68. package/dist/utils/checkIsRoutineCreated.js +27 -26
  69. package/dist/utils/checkVersion.js +119 -1
  70. package/dist/utils/command.js +149 -0
  71. package/dist/utils/compress.js +136 -0
  72. package/dist/utils/download.js +182 -0
  73. package/dist/utils/fileMd5.js +1 -1
  74. package/dist/utils/fileUtils/base.js +1 -1
  75. package/dist/utils/fileUtils/index.js +69 -28
  76. package/dist/utils/installDeno.js +8 -8
  77. package/dist/utils/installEw2.js +7 -7
  78. package/dist/utils/openInBrowser.js +1 -1
  79. package/dist/utils/prompt.js +97 -0
  80. package/package.json +20 -12
@@ -8,15 +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';
18
- import t from '../../../i18n/index.js';
19
19
  import sleep from '../../../utils/sleep.js';
20
+ import CacheService from './cacheService.js';
21
+ import EdgeKV from './kvService.js';
20
22
  const getColorForStatusCode = (statusCode, message) => {
21
23
  if (statusCode >= 100 && statusCode < 200) {
22
24
  return chalk.blue(`${statusCode} ${message}`);
@@ -40,6 +42,8 @@ const getColorForStatusCode = (statusCode, message) => {
40
42
  class Ew2Server {
41
43
  constructor(props) {
42
44
  this.worker = null;
45
+ this.cache = null;
46
+ this.kv = null;
43
47
  this.startingWorker = false;
44
48
  this.workerStartTimeout = undefined;
45
49
  this.server = null;
@@ -57,6 +61,8 @@ class Ew2Server {
57
61
  return __awaiter(this, void 0, void 0, function* () {
58
62
  this.startingWorker = true;
59
63
  const result = yield this.openEdgeWorker();
64
+ this.cache = new CacheService();
65
+ this.kv = new EdgeKV();
60
66
  if (!result) {
61
67
  throw new Error('Worker start failed');
62
68
  }
@@ -81,8 +87,9 @@ class Ew2Server {
81
87
  stdio: ['pipe', 'pipe', 'pipe']
82
88
  });
83
89
  this.workerStartTimeout = setTimeout(() => {
90
+ var _a;
84
91
  reject(new Error(t('dev_worker_timeout').d('Worker start timeout')));
85
- this.worker && this.worker.kill();
92
+ (_a = this.worker) === null || _a === void 0 ? void 0 : _a.kill();
86
93
  }, 60000);
87
94
  const sendToRuntime = () => {
88
95
  return new Promise((resolveStart) => {
@@ -96,7 +103,7 @@ class Ew2Server {
96
103
  const req = http.get(options, (res) => {
97
104
  resolveStart(res.statusCode);
98
105
  });
99
- req.on('error', (err) => {
106
+ req.on('error', () => {
100
107
  resolveStart(null);
101
108
  });
102
109
  req.end();
@@ -119,7 +126,8 @@ class Ew2Server {
119
126
  this.worker.on('close', this.closeHandler.bind(this));
120
127
  this.worker.on('error', this.errorHandler.bind(this));
121
128
  process.on('SIGTERM', () => {
122
- this.worker && this.worker.kill();
129
+ var _a;
130
+ (_a = this.worker) === null || _a === void 0 ? void 0 : _a.kill();
123
131
  });
124
132
  });
125
133
  }
@@ -128,38 +136,62 @@ class Ew2Server {
128
136
  }
129
137
  createServer() {
130
138
  this.server = http.createServer((req, res) => __awaiter(this, void 0, void 0, function* () {
131
- var _a;
139
+ var _a, _b, _c;
140
+ if (req.url === '/favicon.ico') {
141
+ res.writeHead(204, {
142
+ 'Content-Type': 'image/x-icon',
143
+ 'Content-Length': 0
144
+ });
145
+ return res.end();
146
+ }
147
+ if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/mock_cache')) {
148
+ const cacheResult = yield this.handleCache(req);
149
+ return res.end(JSON.stringify(cacheResult));
150
+ }
151
+ if ((_b = req.url) === null || _b === void 0 ? void 0 : _b.includes('/mock_kv')) {
152
+ const kvResult = yield this.handleKV(req);
153
+ if ((_c = req.url) === null || _c === void 0 ? void 0 : _c.includes('/get')) {
154
+ if (kvResult.success) {
155
+ return res.end(kvResult.value);
156
+ }
157
+ else {
158
+ res.setHeader('Kv-Get-Empty', 'true');
159
+ return res.end();
160
+ }
161
+ }
162
+ else {
163
+ return res.end(JSON.stringify(kvResult));
164
+ }
165
+ }
132
166
  try {
133
167
  const host = req.headers.host;
134
168
  const url = req.url;
169
+ const method = req.method;
170
+ const headers = Object.entries(req.headers).reduce((acc, [key, value]) => {
171
+ if (Array.isArray(value)) {
172
+ acc[key] = value.join(', ');
173
+ }
174
+ else {
175
+ acc[key] = value;
176
+ }
177
+ return acc;
178
+ }, {});
135
179
  // @ts-ignore
136
180
  const ew2Port = global.ew2Port;
137
181
  // @ts-ignore
138
182
  const localUpstream = global.localUpstream;
139
183
  const workerRes = yield fetch(`http://${localUpstream ? localUpstream : host}${url}`, {
140
- method: 'GET',
141
- headers: {
142
- 'x-er-context': 'eyJzaXRlX2lkIjogIjYyMjcxODQ0NjgwNjA4IiwgInNpdGVfbmFtZSI6ICJjb21wdXRlbHguYWxpY2RuLXRlc3QuY29tIiwgInNpdGVfcmVjb3JkIjogIm1vY2hlbi1uY2RuLmNvbXB1dGVseC5hbGljZG4tdGVzdC5jb20iLCAiYWxpdWlkIjogIjEzMjI0OTI2ODY2NjU2MDgiLCAic2NoZW1lIjoiaHR0cCIsICAiaW1hZ2VfZW5hYmxlIjogdHJ1ZX0=',
143
- 'x-er-id': 'a.bA'
144
- },
184
+ method,
185
+ headers: Object.assign(Object.assign({}, headers), { 'x-er-context': 'eyJzaXRlX2lkIjogIjYyMjcxODQ0NjgwNjA4IiwgInNpdGVfbmFtZSI6ICJjb21wdXRlbHguYWxpY2RuLXRlc3QuY29tIiwgInNpdGVfcmVjb3JkIjogIm1vY2hlbi1uY2RuLmNvbXB1dGVseC5hbGljZG4tdGVzdC5jb20iLCAiYWxpdWlkIjogIjEzMjI0OTI2ODY2NjU2MDgiLCAic2NoZW1lIjoiaHR0cCIsICAiaW1hZ2VfZW5hYmxlIjogdHJ1ZX0=', 'x-er-id': 'a.bA' }),
186
+ body: req.method === 'GET' ? undefined : req,
145
187
  agent: new HttpProxyAgent(`http://127.0.0.1:${ew2Port}`)
146
188
  });
147
189
  const workerHeaders = Object.fromEntries(workerRes.headers.entries());
148
190
  // 解决 gzip 兼容性问题,防止net::ERR_CONTENT_DECODING_FAILED
149
191
  workerHeaders['content-encoding'] = 'identity';
150
192
  if (workerRes.body) {
151
- if ((_a = workerRes.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('text/')) {
152
- const text = yield workerRes.text();
153
- // 出现换行符之类会导致 content-length 不一致
154
- workerHeaders['content-length'] =
155
- Buffer.byteLength(text).toString();
156
- res.writeHead(workerRes.status, workerHeaders);
157
- res.end(text);
158
- }
159
- else {
160
- res.writeHead(workerRes.status, workerHeaders);
161
- workerRes.body.pipe(res);
162
- }
193
+ res.writeHead(workerRes.status, workerHeaders);
194
+ workerRes.body.pipe(res);
163
195
  logger.log(`[ESA Dev] ${req.method} ${url} ${getColorForStatusCode(workerRes.status, workerRes.statusText)}`);
164
196
  }
165
197
  else {
@@ -175,6 +207,66 @@ class Ew2Server {
175
207
  logger.log(`listening on port ${this.port}`);
176
208
  });
177
209
  }
210
+ handleCache(req) {
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ var _a, _b, _c, _d, _e, _f;
213
+ const body = yield this.parseCacheBody(req);
214
+ if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/put')) {
215
+ (_b = this.cache) === null || _b === void 0 ? void 0 : _b.put(body.key, body);
216
+ return { success: true };
217
+ }
218
+ if ((_c = req.url) === null || _c === void 0 ? void 0 : _c.includes('/get')) {
219
+ const res = (_d = this.cache) === null || _d === void 0 ? void 0 : _d.get(body.key);
220
+ if (!res) {
221
+ return { success: false, key: body.key };
222
+ }
223
+ return { success: true, key: body.key, data: res === null || res === void 0 ? void 0 : res.serializedResponse };
224
+ }
225
+ if ((_e = req.url) === null || _e === void 0 ? void 0 : _e.includes('/delete')) {
226
+ const res = (_f = this.cache) === null || _f === void 0 ? void 0 : _f.delete(body.key);
227
+ return { success: !!res };
228
+ }
229
+ return { success: false };
230
+ });
231
+ }
232
+ handleKV(req) {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ var _a, _b, _c, _d, _e, _f;
235
+ const url = new URL(req.url, 'http://localhost');
236
+ const key = url.searchParams.get('key');
237
+ const namespace = url.searchParams.get('namespace');
238
+ const body = yield this.parseKVBody(req);
239
+ console.log(body);
240
+ if (!key || !namespace) {
241
+ return {
242
+ success: false
243
+ };
244
+ }
245
+ if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/put')) {
246
+ (_b = this.kv) === null || _b === void 0 ? void 0 : _b.put(key, body, namespace);
247
+ return {
248
+ success: true
249
+ };
250
+ }
251
+ if ((_c = req.url) === null || _c === void 0 ? void 0 : _c.includes('/get')) {
252
+ const res = (_d = this.kv) === null || _d === void 0 ? void 0 : _d.get(key, namespace);
253
+ const params = { success: true, value: res };
254
+ if (!res) {
255
+ params.success = false;
256
+ }
257
+ return params;
258
+ }
259
+ if ((_e = req.url) === null || _e === void 0 ? void 0 : _e.includes('/delete')) {
260
+ const res = (_f = this.kv) === null || _f === void 0 ? void 0 : _f.delete(key, namespace);
261
+ return {
262
+ success: res
263
+ };
264
+ }
265
+ return {
266
+ success: false
267
+ };
268
+ });
269
+ }
178
270
  stdoutHandler(chunk) {
179
271
  logger.log(`${chalk.bgGreen('[Worker]')} ${chunk.toString().trim()}`);
180
272
  }
@@ -188,17 +280,60 @@ class Ew2Server {
188
280
  }
189
281
  this.stop();
190
282
  }
191
- closeHandler(code, signal) {
283
+ closeHandler() {
192
284
  if (this.restarting) {
193
285
  this.restarting = false;
194
286
  return;
195
287
  }
196
288
  this.stop().then(() => {
289
+ var _a;
197
290
  logger.log(t('dev_server_closed').d('Worker server closed'));
198
291
  logger.info('Worker server closed');
199
292
  // @ts-ignore
200
293
  global.port = undefined;
201
- this.onClose && this.onClose();
294
+ (_a = this.onClose) === null || _a === void 0 ? void 0 : _a.call(this);
295
+ });
296
+ }
297
+ parseCacheBody(req) {
298
+ return new Promise((resolve, reject) => {
299
+ const chunks = [];
300
+ let totalLength = 0;
301
+ req.on('data', (chunk) => {
302
+ chunks.push(chunk);
303
+ totalLength += chunk.length;
304
+ });
305
+ req.on('end', () => {
306
+ try {
307
+ const buffer = Buffer.concat(chunks, totalLength);
308
+ const rawBody = buffer.toString('utf8');
309
+ resolve(rawBody ? JSON.parse(rawBody) : {});
310
+ }
311
+ catch (err) {
312
+ reject(new Error(`Invalid JSON: ${err.message}`));
313
+ }
314
+ });
315
+ req.on('error', reject);
316
+ });
317
+ }
318
+ parseKVBody(req) {
319
+ return new Promise((resolve, reject) => {
320
+ const chunks = [];
321
+ let totalLength = 0;
322
+ req.on('data', (chunk) => {
323
+ chunks.push(chunk);
324
+ totalLength += chunk.length;
325
+ });
326
+ req.on('end', () => {
327
+ try {
328
+ const buffer = Buffer.concat(chunks, totalLength);
329
+ const rawBody = buffer.toString();
330
+ resolve(rawBody);
331
+ }
332
+ catch (err) {
333
+ reject(new Error(`Invalid JSON: ${err.message}`));
334
+ }
335
+ });
336
+ req.on('error', reject);
202
337
  });
203
338
  }
204
339
  runCommand(command) {
@@ -212,7 +347,7 @@ class Ew2Server {
212
347
  resolve(false);
213
348
  return;
214
349
  }
215
- const onExit = (code, signal) => {
350
+ const onExit = () => {
216
351
  this.worker = null;
217
352
  resolve(true);
218
353
  };
@@ -221,10 +356,12 @@ class Ew2Server {
221
356
  (_a = this.server) === null || _a === void 0 ? void 0 : _a.close();
222
357
  });
223
358
  }
224
- restart() {
359
+ restart(devPack) {
225
360
  return __awaiter(this, void 0, void 0, function* () {
226
361
  this.restarting = true;
362
+ console.clear();
227
363
  yield this.stop();
364
+ yield devPack();
228
365
  this.start();
229
366
  logger.log(t('dev_server_restart').d('Worker server restarted'));
230
367
  logger.info('Worker server restarted');
@@ -10,24 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { exec } from 'child_process';
11
11
  import { isIP } from 'net';
12
12
  import chokidar from 'chokidar';
13
- import doProcess from './doProcess.js';
14
- import { getProjectConfig, generateConfigFile, getDevConf } from '../../utils/fileUtils/index.js';
15
- import { getRoot } from '../../utils/fileUtils/base.js';
16
13
  import SelectItems from '../../components/selectInput.js';
17
- import logger from '../../libs/logger.js';
18
- import MockServer from './mockWorker/server.js';
19
- import mockPack from './mockWorker/devPack.js';
20
- import Ew2Server from './ew2/server.js';
21
- import ew2Pack from './ew2/devPack.js';
22
- import { preCheckDeno } from '../../utils/installDeno.js';
23
- import { preCheckEw2 } from '../../utils/installEw2.js';
24
- import debounce from '../../utils/debounce.js';
25
14
  import t from '../../i18n/index.js';
15
+ import logger from '../../libs/logger.js';
26
16
  import checkAndInputPort from '../../utils/checkDevPort.js';
27
17
  import { checkOS, Platforms } from '../../utils/checkOS.js';
18
+ import debounce from '../../utils/debounce.js';
19
+ import { getRoot } from '../../utils/fileUtils/base.js';
20
+ import { getProjectConfig, generateConfigFile, getDevConf } from '../../utils/fileUtils/index.js';
21
+ import { preCheckDeno } from '../../utils/installDeno.js';
22
+ import { preCheckEw2 } from '../../utils/installEw2.js';
23
+ import doProcess from './doProcess.js';
24
+ import ew2Pack from './ew2/devPack.js';
25
+ import Ew2Server from './ew2/server.js';
26
+ import mockPack from './mockWorker/devPack.js';
27
+ import MockServer from './mockWorker/server.js';
28
28
  let yargsIns;
29
29
  const OS = checkOS();
30
- const useEw2 = OS === Platforms.AppleArm || Platforms.AppleIntel || Platforms.LinuxX86;
30
+ const EW2OS = [Platforms.AppleArm, Platforms.AppleIntel, Platforms.LinuxX86];
31
+ const useEw2 = EW2OS.includes(OS);
31
32
  const dev = {
32
33
  command: 'dev [entry]',
33
34
  describe: `💻 ${t('dev_describe').d('Start a local server for developing your routine')}`,
@@ -202,7 +203,7 @@ const dev = {
202
203
  userFileRepacking = false;
203
204
  return;
204
205
  }
205
- worker.restart();
206
+ worker.restart(devPack);
206
207
  return;
207
208
  }
208
209
  logger.info('Dev repack');
@@ -214,14 +215,13 @@ const dev = {
214
215
  catch (err) { }
215
216
  }
216
217
  userFileRepacking = true;
217
- yield devPack();
218
- yield worker.restart();
218
+ yield worker.restart(devPack);
219
219
  }), 500));
220
220
  var { devElement, exit } = doProcess(worker);
221
221
  const { waitUntilExit } = devElement;
222
222
  yield waitUntilExit();
223
223
  function onWorkerClosed() {
224
- exit && exit();
224
+ exit === null || exit === void 0 ? void 0 : exit();
225
225
  }
226
226
  watcher.close();
227
227
  })
@@ -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 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';
17
+ import devBuild from '../build.js';
18
18
  const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
19
19
  const __dirname = getDirName(import.meta.url);
20
20
  const devDir = path.resolve(userRoot, '.dev');
@@ -35,7 +35,7 @@ const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0,
35
35
  const destPath = path.resolve(mockDevDir, file);
36
36
  yield fs.promises.copyFile(srcPath, destPath);
37
37
  }
38
- return fs.promises.writeFile(devEntry, devEntryTempFile.replace(/'\$userPath'/g, `'${projectEntry}'`));
38
+ return fs.promises.writeFile(devEntry, devEntryTempFile.replace(/'\$userPath'/g, `'${projectEntry.replace(/\\/g, '/')}'`));
39
39
  });
40
40
  const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
41
41
  const options = {};
@@ -51,22 +51,24 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
51
51
  .readFileSync(configPath, 'utf-8')
52
52
  .replace('export default ', '');
53
53
  const currentConfigObj = JSON.parse(currentConfig);
54
- const cIds = Object.keys(currentConfigObj);
55
- if (cIds[0] && /^\d+$/.test(cIds[0])) {
56
- for (let cid of cIds) {
57
- const useful = yield checkPort(currentConfigObj[cid].port);
58
- if (useful) {
59
- const unusedEntry = path.resolve(userRoot, `.dev/index-${cid}.js`);
60
- const unusedTemp = path.resolve(userRoot, `.dev/devEntry-${cid}.js`);
61
- if (fs.existsSync(unusedEntry)) {
62
- fs.rmSync(unusedEntry);
63
- }
64
- if (fs.existsSync(unusedTemp)) {
65
- fs.rmSync(unusedTemp);
54
+ const currentIds = Object.keys(currentConfigObj);
55
+ if (currentIds[0] && /^\d+$/.test(currentIds[0])) {
56
+ for (let currentId of currentIds) {
57
+ const unused = yield checkPort(currentConfigObj[currentId].port);
58
+ if (unused) {
59
+ const devDir = path.resolve(userRoot, '.dev');
60
+ const files = fs.readdirSync(devDir);
61
+ const filesToDelete = files.filter((file) => file.includes(currentId));
62
+ for (const file of filesToDelete) {
63
+ fs.rmSync(path.resolve(devDir, file), {
64
+ force: true,
65
+ recursive: true,
66
+ maxRetries: 5
67
+ });
66
68
  }
67
69
  }
68
70
  else {
69
- options[cid] = currentConfigObj[cid];
71
+ options[currentId] = currentConfigObj[currentId];
70
72
  }
71
73
  }
72
74
  }
@@ -76,10 +78,19 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
76
78
  const devPack = () => __awaiter(void 0, void 0, void 0, function* () {
77
79
  logger.ora.start('Processing...\n');
78
80
  const userRoot = getRoot();
79
- const configPath = path.resolve(userRoot, 'esa.toml');
81
+ // Try to find config file in order of preference: .jsonc, .toml
82
+ const configFormats = ['esa.jsonc', 'esa.toml'];
83
+ let configPath = null;
84
+ for (const format of configFormats) {
85
+ const testPath = path.resolve(userRoot, format);
86
+ if (fs.existsSync(testPath)) {
87
+ configPath = testPath;
88
+ break;
89
+ }
90
+ }
80
91
  let port, minify, localUpstream, entry;
81
92
  let projectEntry = path.resolve(userRoot, 'src/index.js');
82
- if (fs.existsSync(configPath)) {
93
+ if (configPath) {
83
94
  port = getDevConf('port', 'dev', 18080);
84
95
  minify = getDevConf('minify', 'dev', false);
85
96
  localUpstream = getDevConf('localUpstream', 'dev', '');
@@ -7,12 +7,12 @@ 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 spawn from 'cross-spawn';
11
- import logger from '../../../libs/logger.js';
12
10
  import path from 'path';
11
+ import spawn from 'cross-spawn';
13
12
  import t from '../../../i18n/index.js';
14
- import { getDevConf } from '../../../utils/fileUtils/index.js';
13
+ import logger from '../../../libs/logger.js';
15
14
  import { getRoot } from '../../../utils/fileUtils/base.js';
15
+ import { getDevConf } from '../../../utils/fileUtils/index.js';
16
16
  class MockWorkerServer {
17
17
  constructor(props) {
18
18
  this.instance = null;
@@ -63,10 +63,11 @@ class MockWorkerServer {
63
63
  logger.subError(chunk.toString().trim());
64
64
  }
65
65
  errorHandler(err) {
66
+ var _a;
66
67
  logger.error(err.message ? err.message : err);
67
- this.instance && this.instance.kill();
68
+ (_a = this.instance) === null || _a === void 0 ? void 0 : _a.kill();
68
69
  }
69
- closeHandler(code, signal) {
70
+ closeHandler() {
70
71
  if (this.restarting) {
71
72
  this.restarting = false;
72
73
  return;
@@ -86,7 +87,7 @@ class MockWorkerServer {
86
87
  resolve(false);
87
88
  return;
88
89
  }
89
- const onExit = (code, signal) => {
90
+ const onExit = () => {
90
91
  this.instance = null;
91
92
  resolve(true);
92
93
  };
@@ -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 { bindRoutineWithDomain, checkDirectory, checkIsLoginSuccess, validDomain, validName } from '../utils.js';
11
- import { getProjectConfig } from '../../utils/fileUtils/index.js';
12
10
  import t from '../../i18n/index.js';
13
11
  import logger from '../../libs/logger.js';
14
12
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
13
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
14
+ import { bindRoutineWithDomain, checkDirectory, checkIsLoginSuccess, validDomain, validName } from '../utils.js';
15
15
  const addDomain = {
16
16
  command: 'add <domain>',
17
- describe: `📥 ${t('domain_add_describe').d('Bind a domain to a routine')}`,
17
+ describe: `🔗 ${t('domain_add_describe').d('Bind a domain to a routine')}`,
18
18
  builder: (yargs) => {
19
19
  return yargs
20
20
  .positional('domain', {
@@ -7,12 +7,12 @@ 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 } from '../utils.js';
12
- import { ApiService } from '../../libs/apiService.js';
13
10
  import t from '../../i18n/index.js';
11
+ import { ApiService } from '../../libs/apiService.js';
14
12
  import logger from '../../libs/logger.js';
15
13
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
14
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
15
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
16
16
  const deleteDomain = {
17
17
  command: 'delete <domain>',
18
18
  describe: `🗑 ${t('domain_delete_describe').d('Delete a related domain')}`,
@@ -31,7 +31,7 @@ const deleteDomain = {
31
31
  export default deleteDomain;
32
32
  export function handleDeleteDomain(argv) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
- var _a, _b;
34
+ var _a;
35
35
  if (!checkDirectory()) {
36
36
  return;
37
37
  }
@@ -44,10 +44,10 @@ export function handleDeleteDomain(argv) {
44
44
  yield validRoutine(projectConfig.name);
45
45
  const server = yield ApiService.getInstance();
46
46
  const req = { Name: projectConfig.name || '' };
47
- const routineDetail = yield server.getRoutine(req);
48
- if (!routineDetail)
47
+ const listRoutineRelatedRecordRes = yield server.listRoutineRelatedRecords(req);
48
+ if (!listRoutineRelatedRecordRes)
49
49
  return;
50
- const relatedRecords = (_b = (_a = routineDetail.data) === null || _a === void 0 ? void 0 : _a.RelatedRecords) !== null && _b !== void 0 ? _b : [];
50
+ const relatedRecords = ((_a = listRoutineRelatedRecordRes.data) === null || _a === void 0 ? void 0 : _a.RelatedRecords) || [];
51
51
  const relatedDomain = argv.domain;
52
52
  const matchedSite = relatedRecords.find((item) => {
53
53
  return String(item.RecordName) === relatedDomain;
@@ -1,11 +1,11 @@
1
+ import t from '../../i18n/index.js';
1
2
  import addDomain from './add.js';
2
- import listDomain from './list.js';
3
3
  import deleteDomain from './delete.js';
4
- import t from '../../i18n/index.js';
4
+ import listDomain from './list.js';
5
5
  let yargsIns;
6
6
  const domainCommand = {
7
7
  command: 'domain [script]',
8
- describe: `🚀 ${t('domain_describe').d('Manage the domain names bound to your routine')}`,
8
+ describe: `🔗 ${t('domain_describe').d('Manage the domain names bound to your routine')}`,
9
9
  builder: (yargs) => {
10
10
  yargsIns = yargs;
11
11
  return yargs
@@ -7,21 +7,21 @@ 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 { checkDirectory, checkIsLoginSuccess } from '../utils.js';
11
- import logger from '../../libs/logger.js';
12
- import { getProjectConfig } from '../../utils/fileUtils/index.js';
13
- import { ApiService } from '../../libs/apiService.js';
14
10
  import t from '../../i18n/index.js';
11
+ import { ApiService } from '../../libs/apiService.js';
12
+ import logger from '../../libs/logger.js';
15
13
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
14
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
15
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
16
16
  const listDomain = {
17
17
  command: 'list',
18
18
  describe: `🔍 ${t('domain_list_describe').d('List all related domains')}`,
19
- handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
20
- handleListDomains(argv);
19
+ handler: () => __awaiter(void 0, void 0, void 0, function* () {
20
+ handleListDomains();
21
21
  })
22
22
  };
23
23
  export default listDomain;
24
- export function handleListDomains(argv) {
24
+ export function handleListDomains() {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  var _a, _b;
27
27
  if (!checkDirectory()) {
@@ -36,10 +36,10 @@ export function handleListDomains(argv) {
36
36
  yield validRoutine(projectConfig.name);
37
37
  const server = yield ApiService.getInstance();
38
38
  const req = { Name: projectConfig.name };
39
- const routineDetail = yield server.getRoutine(req);
40
- if (!routineDetail)
39
+ const res = yield server.listRoutineRelatedRecords(req);
40
+ if (!res)
41
41
  return;
42
- const relatedRecords = (_b = (_a = routineDetail.data) === null || _a === void 0 ? void 0 : _a.RelatedRecords) !== null && _b !== void 0 ? _b : [];
42
+ const relatedRecords = (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.RelatedRecords) !== null && _b !== void 0 ? _b : [];
43
43
  if (relatedRecords.length === 0) {
44
44
  logger.log(`🙅 ${t('domain_list_empty').d('No related domains found')}`);
45
45
  return;