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

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 (82) hide show
  1. package/dist/commands/commit/index.js +48 -115
  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 +416 -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 +50 -188
  8. package/dist/commands/deployments/delete.js +32 -22
  9. package/dist/commands/deployments/index.js +2 -2
  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 +39 -43
  16. package/dist/commands/dev/ew2/kvService.js +27 -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 -29
  20. package/dist/commands/dev/index.js +17 -17
  21. package/dist/commands/dev/mockWorker/devPack.js +35 -24
  22. package/dist/commands/dev/mockWorker/server.js +7 -6
  23. package/dist/commands/domain/add.js +2 -2
  24. package/dist/commands/domain/delete.js +7 -7
  25. package/dist/commands/domain/index.js +2 -2
  26. package/dist/commands/domain/list.js +10 -10
  27. package/dist/commands/init/helper.js +759 -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 +5 -5
  37. package/dist/commands/route/add.js +105 -49
  38. package/dist/commands/route/delete.js +33 -27
  39. package/dist/commands/route/helper.js +123 -0
  40. package/dist/commands/route/index.js +2 -2
  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 +2 -2
  44. package/dist/commands/routine/list.js +43 -37
  45. package/dist/commands/site/index.js +1 -1
  46. package/dist/commands/site/list.js +6 -7
  47. package/dist/commands/utils.js +59 -23
  48. package/dist/components/descriptionInput.js +1 -1
  49. package/dist/components/filterSelector.js +1 -1
  50. package/dist/components/mutiLevelSelect.js +43 -55
  51. package/dist/components/mutiSelectTable.js +1 -1
  52. package/dist/components/routeBuilder.js +68 -0
  53. package/dist/components/selectInput.js +2 -3
  54. package/dist/components/selectItem.js +1 -1
  55. package/dist/docs/Commands_en.md +142 -131
  56. package/dist/docs/Commands_zh_CN.md +139 -127
  57. package/dist/i18n/index.js +2 -2
  58. package/dist/i18n/locales.json +435 -23
  59. package/dist/index.js +27 -20
  60. package/dist/libs/api.js +32 -9
  61. package/dist/libs/apiService.js +267 -88
  62. package/dist/libs/git/index.js +86 -9
  63. package/dist/libs/interface.js +0 -1
  64. package/dist/libs/logger.js +162 -10
  65. package/dist/libs/service.js +2 -2
  66. package/dist/libs/templates/index.js +3 -2
  67. package/dist/utils/checkAssetsExist.js +80 -0
  68. package/dist/utils/checkDevPort.js +3 -17
  69. package/dist/utils/checkEntryFileExist.js +10 -0
  70. package/dist/utils/checkIsRoutineCreated.js +28 -27
  71. package/dist/utils/checkVersion.js +119 -1
  72. package/dist/utils/command.js +149 -0
  73. package/dist/utils/compress.js +136 -0
  74. package/dist/utils/download.js +182 -0
  75. package/dist/utils/fileMd5.js +1 -1
  76. package/dist/utils/fileUtils/base.js +1 -1
  77. package/dist/utils/fileUtils/index.js +136 -44
  78. package/dist/utils/installDeno.js +8 -8
  79. package/dist/utils/installEw2.js +7 -7
  80. package/dist/utils/openInBrowser.js +1 -1
  81. package/dist/utils/prompt.js +97 -0
  82. package/package.json +19 -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
- // 解决 gzip 兼容性问题,防止net::ERR_CONTENT_DECODING_FAILED
190
+ // Solve gzip compatibility issue, prevent 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,65 @@ 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
+ if (!key || !namespace) {
240
+ return {
241
+ success: false
242
+ };
243
+ }
244
+ if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes('/put')) {
245
+ (_b = this.kv) === null || _b === void 0 ? void 0 : _b.put(key, body, namespace);
246
+ return {
247
+ success: true
248
+ };
249
+ }
250
+ if ((_c = req.url) === null || _c === void 0 ? void 0 : _c.includes('/get')) {
251
+ const res = (_d = this.kv) === null || _d === void 0 ? void 0 : _d.get(key, namespace);
252
+ const params = { success: true, value: res };
253
+ if (!res) {
254
+ params.success = false;
255
+ }
256
+ return params;
257
+ }
258
+ if ((_e = req.url) === null || _e === void 0 ? void 0 : _e.includes('/delete')) {
259
+ const res = (_f = this.kv) === null || _f === void 0 ? void 0 : _f.delete(key, namespace);
260
+ return {
261
+ success: res
262
+ };
263
+ }
264
+ return {
265
+ success: false
266
+ };
267
+ });
268
+ }
178
269
  stdoutHandler(chunk) {
179
270
  logger.log(`${chalk.bgGreen('[Worker]')} ${chunk.toString().trim()}`);
180
271
  }
@@ -188,17 +279,60 @@ class Ew2Server {
188
279
  }
189
280
  this.stop();
190
281
  }
191
- closeHandler(code, signal) {
282
+ closeHandler() {
192
283
  if (this.restarting) {
193
284
  this.restarting = false;
194
285
  return;
195
286
  }
196
287
  this.stop().then(() => {
288
+ var _a;
197
289
  logger.log(t('dev_server_closed').d('Worker server closed'));
198
290
  logger.info('Worker server closed');
199
291
  // @ts-ignore
200
292
  global.port = undefined;
201
- this.onClose && this.onClose();
293
+ (_a = this.onClose) === null || _a === void 0 ? void 0 : _a.call(this);
294
+ });
295
+ }
296
+ parseCacheBody(req) {
297
+ return new Promise((resolve, reject) => {
298
+ const chunks = [];
299
+ let totalLength = 0;
300
+ req.on('data', (chunk) => {
301
+ chunks.push(chunk);
302
+ totalLength += chunk.length;
303
+ });
304
+ req.on('end', () => {
305
+ try {
306
+ const buffer = Buffer.concat(chunks, totalLength);
307
+ const rawBody = buffer.toString('utf8');
308
+ resolve(rawBody ? JSON.parse(rawBody) : {});
309
+ }
310
+ catch (err) {
311
+ reject(new Error(`Invalid JSON: ${err.message}`));
312
+ }
313
+ });
314
+ req.on('error', reject);
315
+ });
316
+ }
317
+ parseKVBody(req) {
318
+ return new Promise((resolve, reject) => {
319
+ const chunks = [];
320
+ let totalLength = 0;
321
+ req.on('data', (chunk) => {
322
+ chunks.push(chunk);
323
+ totalLength += chunk.length;
324
+ });
325
+ req.on('end', () => {
326
+ try {
327
+ const buffer = Buffer.concat(chunks, totalLength);
328
+ const rawBody = buffer.toString();
329
+ resolve(rawBody);
330
+ }
331
+ catch (err) {
332
+ reject(new Error(`Invalid JSON: ${err.message}`));
333
+ }
334
+ });
335
+ req.on('error', reject);
202
336
  });
203
337
  }
204
338
  runCommand(command) {
@@ -212,7 +346,7 @@ class Ew2Server {
212
346
  resolve(false);
213
347
  return;
214
348
  }
215
- const onExit = (code, signal) => {
349
+ const onExit = () => {
216
350
  this.worker = null;
217
351
  resolve(true);
218
352
  };
@@ -221,10 +355,12 @@ class Ew2Server {
221
355
  (_a = this.server) === null || _a === void 0 ? void 0 : _a.close();
222
356
  });
223
357
  }
224
- restart() {
358
+ restart(devPack) {
225
359
  return __awaiter(this, void 0, void 0, function* () {
226
360
  this.restarting = true;
361
+ console.clear();
227
362
  yield this.stop();
363
+ yield devPack();
228
364
  this.start();
229
365
  logger.log(t('dev_server_restart').d('Worker server restarted'));
230
366
  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')}`,
@@ -186,7 +187,7 @@ const dev = {
186
187
  yield worker.start();
187
188
  }
188
189
  catch (err) {
189
- console.log('Track err', err);
190
+ logger.error(`Worker start failed: ${err}`);
190
191
  process.exit(1);
191
192
  }
192
193
  const ignored = (path) => {
@@ -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,38 +35,40 @@ 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 = {};
42
42
  const currentOptions = { entry, port, localUpstream };
43
- // 支持同时跑多个 deno
43
+ // Support running multiple deno instances simultaneously
44
44
  const id = new Date().getTime().toString();
45
45
  // @ts-ignore
46
46
  global.id = id;
47
47
  yield generateEntry(id, entry, userRoot);
48
- // 给每一次 dev 的配置项,在一个文件中通过 id 区分
48
+ // Configuration items for each dev session, distinguished by id in one file
49
49
  if (fs.existsSync(configPath)) {
50
50
  const currentConfig = fs
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', '');
@@ -90,7 +101,7 @@ const devPack = () => __awaiter(void 0, void 0, void 0, function* () {
90
101
  }
91
102
  else {
92
103
  logger.notInProject();
93
- process.exit(0);
104
+ process.exit(1);
94
105
  }
95
106
  return prepare(path.resolve(userRoot, '.dev/devConfig.js'), projectEntry, port, localUpstream, userRoot)
96
107
  .then(() => {
@@ -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,11 +7,11 @@ 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
17
  describe: `📥 ${t('domain_add_describe').d('Bind a domain to a routine')}`,
@@ -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,7 +1,7 @@
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]',
@@ -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;