esa-cli 0.0.1-beta.9 → 0.0.2-beta.0

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 (44) hide show
  1. package/README.md +4 -6
  2. package/bin/enter.cjs +0 -1
  3. package/dist/README.md +4 -6
  4. package/dist/bin/enter.cjs +0 -1
  5. package/dist/commands/commit/index.js +2 -2
  6. package/dist/commands/deploy/index.js +4 -2
  7. package/dist/commands/deployments/list.js +2 -1
  8. package/dist/commands/dev/build.js +57 -0
  9. package/dist/commands/dev/doProcess.js +10 -2
  10. package/dist/commands/dev/ew2/devEntry.js +9 -0
  11. package/dist/commands/dev/ew2/devPack.js +185 -0
  12. package/dist/commands/dev/ew2/mock/cache.js +32 -0
  13. package/dist/commands/dev/ew2/mock/kv.js +45 -0
  14. package/dist/commands/dev/ew2/server.js +234 -0
  15. package/dist/commands/dev/index.js +111 -49
  16. package/dist/commands/dev/{config → mockWorker}/devEntry.js +3 -2
  17. package/dist/commands/dev/{devPack.js → mockWorker/devPack.js} +10 -8
  18. package/dist/commands/dev/{server.js → mockWorker/server.js} +43 -37
  19. package/dist/commands/init/index.js +117 -42
  20. package/dist/commands/login/index.js +2 -2
  21. package/dist/commands/logout.js +0 -4
  22. package/dist/commands/route/list.js +2 -1
  23. package/dist/commands/routine/list.js +6 -4
  24. package/dist/components/mutiLevelSelect.js +69 -0
  25. package/dist/i18n/locales.json +120 -4
  26. package/dist/index.js +8 -0
  27. package/dist/libs/api.js +155 -0
  28. package/dist/libs/logger.js +42 -31
  29. package/dist/libs/service.js +178 -0
  30. package/dist/package.json +13 -5
  31. package/dist/utils/checkDevPort.js +19 -14
  32. package/dist/utils/checkOS.js +32 -0
  33. package/dist/utils/fileMd5.js +18 -0
  34. package/dist/utils/fileUtils/index.js +1 -1
  35. package/dist/utils/install/installEw2.sh +33 -0
  36. package/dist/utils/{installRuntime.js → installDeno.js} +15 -15
  37. package/dist/utils/installEw2.js +127 -0
  38. package/dist/utils/stepsRunner.js +33 -0
  39. package/dist/zh_CN.md +4 -5
  40. package/package.json +13 -5
  41. package/dist/commands/dev/config/devBuild.js +0 -26
  42. package/dist/libs/request.js +0 -98
  43. /package/dist/commands/dev/{config → mockWorker}/mock/cache.js +0 -0
  44. /package/dist/commands/dev/{config → mockWorker}/mock/kv.js +0 -0
@@ -0,0 +1,234 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as http from 'http';
11
+ import spawn from 'cross-spawn';
12
+ import fetch from 'node-fetch';
13
+ import logger from '../../../libs/logger.js';
14
+ import { getRoot } from '../../../utils/fileUtils/base.js';
15
+ 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
+ import sleep from '../../../utils/sleep.js';
20
+ const getColorForStatusCode = (statusCode, message) => {
21
+ if (statusCode >= 100 && statusCode < 200) {
22
+ return chalk.blue(`${statusCode} ${message}`);
23
+ }
24
+ else if (statusCode >= 200 && statusCode < 300) {
25
+ return chalk.green(`${statusCode} ${message}`);
26
+ }
27
+ else if (statusCode >= 300 && statusCode < 400) {
28
+ return chalk.yellow(`${statusCode} ${message}`);
29
+ }
30
+ else if (statusCode >= 400 && statusCode < 500) {
31
+ return chalk.red(`${statusCode} ${message}`);
32
+ }
33
+ else if (statusCode >= 500) {
34
+ return chalk.magenta(chalk.bold(`${statusCode} ${message}`));
35
+ }
36
+ else {
37
+ return `${statusCode} ${message}`;
38
+ }
39
+ };
40
+ class Ew2Server {
41
+ constructor(props) {
42
+ this.worker = null;
43
+ this.startingWorker = false;
44
+ this.workerStartTimeout = undefined;
45
+ this.server = null;
46
+ this.restarting = false;
47
+ this.port = 18080;
48
+ // @ts-ignore
49
+ if (global.port)
50
+ this.port = global.port;
51
+ if (props.port)
52
+ this.port = props.port;
53
+ if (props.onClose)
54
+ this.onClose = props.onClose;
55
+ }
56
+ start() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ this.startingWorker = true;
59
+ const result = yield this.openEdgeWorker();
60
+ if (!result) {
61
+ throw new Error('Worker start failed');
62
+ }
63
+ this.createServer();
64
+ });
65
+ }
66
+ openEdgeWorker() {
67
+ if (this.worker) {
68
+ return Promise.resolve();
69
+ }
70
+ const root = getRoot();
71
+ // @ts-ignore
72
+ const id = global.id || '';
73
+ return new Promise((resolve, reject) => {
74
+ var _a, _b, _c;
75
+ this.worker = spawn(EW2BinPath, [
76
+ '--config_file',
77
+ `${root}/.dev/config-${id}.toml`,
78
+ '--log_stdout',
79
+ '-v'
80
+ ], {
81
+ stdio: ['pipe', 'pipe', 'pipe']
82
+ });
83
+ this.workerStartTimeout = setTimeout(() => {
84
+ reject(new Error(t('dev_worker_timeout').d('Worker start timeout')));
85
+ this.worker && this.worker.kill();
86
+ }, 60000);
87
+ const sendToRuntime = () => {
88
+ return new Promise((resolveStart) => {
89
+ // @ts-ignore
90
+ const ew2Port = global.ew2Port;
91
+ const options = {
92
+ hostname: '127.0.0.1',
93
+ port: ew2Port,
94
+ method: 'GET'
95
+ };
96
+ const req = http.get(options, (res) => {
97
+ resolveStart(res.statusCode);
98
+ });
99
+ req.on('error', (err) => {
100
+ resolveStart(null);
101
+ });
102
+ req.end();
103
+ });
104
+ };
105
+ const checkRuntimeStart = () => __awaiter(this, void 0, void 0, function* () {
106
+ while (this.startingWorker) {
107
+ const [result] = yield Promise.all([sendToRuntime(), sleep(500)]);
108
+ if (result) {
109
+ this.startingWorker = false;
110
+ this.clearTimeout();
111
+ resolve(result);
112
+ }
113
+ }
114
+ });
115
+ checkRuntimeStart();
116
+ (_a = this.worker.stdout) === null || _a === void 0 ? void 0 : _a.setEncoding('utf8');
117
+ (_b = this.worker.stdout) === null || _b === void 0 ? void 0 : _b.on('data', this.stdoutHandler.bind(this));
118
+ (_c = this.worker.stderr) === null || _c === void 0 ? void 0 : _c.on('data', this.stderrHandler.bind(this));
119
+ this.worker.on('close', this.closeHandler.bind(this));
120
+ this.worker.on('error', this.errorHandler.bind(this));
121
+ process.on('SIGTERM', () => {
122
+ this.worker && this.worker.kill();
123
+ });
124
+ });
125
+ }
126
+ clearTimeout() {
127
+ clearTimeout(this.workerStartTimeout);
128
+ }
129
+ createServer() {
130
+ this.server = http.createServer((req, res) => __awaiter(this, void 0, void 0, function* () {
131
+ var _a;
132
+ try {
133
+ const host = req.headers.host;
134
+ const url = req.url;
135
+ // @ts-ignore
136
+ const ew2Port = global.ew2Port;
137
+ // @ts-ignore
138
+ const localUpstream = global.localUpstream;
139
+ 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
+ },
145
+ agent: new HttpProxyAgent(`http://127.0.0.1:${ew2Port}`)
146
+ });
147
+ const workerHeaders = Object.fromEntries(workerRes.headers.entries());
148
+ // 解决 gzip 兼容性问题,防止net::ERR_CONTENT_DECODING_FAILED
149
+ workerHeaders['content-encoding'] = 'identity';
150
+ 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
+ }
163
+ logger.log(`[ESA Dev] ${req.method} ${url} ${getColorForStatusCode(workerRes.status, workerRes.statusText)}`);
164
+ }
165
+ else {
166
+ res.writeHead(500, { 'Content-Type': 'text/plain' });
167
+ res.end('EW2 return null');
168
+ }
169
+ }
170
+ catch (err) {
171
+ console.log(err);
172
+ }
173
+ }));
174
+ this.server.listen(this.port, () => {
175
+ logger.log(`listening on port ${this.port}`);
176
+ });
177
+ }
178
+ stdoutHandler(chunk) {
179
+ logger.log(`${chalk.bgGreen('[Worker]')} ${chunk.toString().trim()}`);
180
+ }
181
+ stderrHandler(chunk) {
182
+ logger.subError(`${chalk.bgGreen('[Worker Error]')} ${chunk.toString().trim()}`);
183
+ }
184
+ errorHandler(error) {
185
+ logger.error(error.message ? error.message : error);
186
+ if (error.code && error.code === 'EACCES') {
187
+ logger.pathEacces(EW2BinPath);
188
+ }
189
+ this.stop();
190
+ }
191
+ closeHandler(code, signal) {
192
+ if (this.restarting) {
193
+ this.restarting = false;
194
+ return;
195
+ }
196
+ this.stop().then(() => {
197
+ logger.log(t('dev_server_closed').d('Worker server closed'));
198
+ logger.info('Worker server closed');
199
+ // @ts-ignore
200
+ global.port = undefined;
201
+ this.onClose && this.onClose();
202
+ });
203
+ }
204
+ runCommand(command) {
205
+ var _a, _b;
206
+ (_b = (_a = this.worker) === null || _a === void 0 ? void 0 : _a.stdin) === null || _b === void 0 ? void 0 : _b.write(command);
207
+ }
208
+ stop() {
209
+ return new Promise((resolve) => {
210
+ var _a;
211
+ if (!this.worker) {
212
+ resolve(false);
213
+ return;
214
+ }
215
+ const onExit = (code, signal) => {
216
+ this.worker = null;
217
+ resolve(true);
218
+ };
219
+ this.worker.on('exit', onExit);
220
+ this.worker.kill('SIGTERM');
221
+ (_a = this.server) === null || _a === void 0 ? void 0 : _a.close();
222
+ });
223
+ }
224
+ restart() {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ this.restarting = true;
227
+ yield this.stop();
228
+ this.start();
229
+ logger.log(t('dev_server_restart').d('Worker server restarted'));
230
+ logger.info('Worker server restarted');
231
+ });
232
+ }
233
+ }
234
+ export default Ew2Server;
@@ -8,29 +8,46 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { exec } from 'child_process';
11
+ import { isIP } from 'net';
11
12
  import chokidar from 'chokidar';
12
13
  import doProcess from './doProcess.js';
13
14
  import { getProjectConfig, generateConfigFile, getDevConf } from '../../utils/fileUtils/index.js';
14
15
  import { getRoot } from '../../utils/fileUtils/base.js';
15
16
  import SelectItems from '../../components/selectInput.js';
16
17
  import logger from '../../libs/logger.js';
17
- import devPack from './devPack.js';
18
- import WorkerServer from './server.js';
19
- import { preCheckRuntime } from '../../utils/installRuntime.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';
20
24
  import debounce from '../../utils/debounce.js';
21
25
  import t from '../../i18n/index.js';
22
26
  import checkAndInputPort from '../../utils/checkDevPort.js';
27
+ import { checkOS, Platforms } from '../../utils/checkOS.js';
23
28
  let yargsIns;
29
+ const OS = checkOS();
30
+ const useEw2 = OS === Platforms.AppleArm || Platforms.AppleIntel || Platforms.LinuxX86;
24
31
  const dev = {
25
32
  command: 'dev [entry]',
26
33
  describe: `💻 ${t('dev_describe').d('Start a local server for developing your routine')}`,
27
34
  builder: (yargs) => {
28
- yargsIns = yargs;
29
- return yargs
35
+ yargsIns = yargs
30
36
  .positional('entry', {
31
37
  describe: t('dev_entry_describe').d('Entry file of the Routine'),
32
38
  type: 'string',
33
39
  demandOption: false
40
+ })
41
+ .option('p', {
42
+ alias: 'port',
43
+ describe: t('dev_port_describe').d('Port to listen on'),
44
+ type: 'number'
45
+ })
46
+ .option('m', {
47
+ alias: 'minify',
48
+ describe: t('dev_option_minify').d('Minify code during development'),
49
+ type: 'boolean',
50
+ default: false
34
51
  })
35
52
  .option('refresh-command', {
36
53
  describe: t('dev_refresh_command_describe').d('Provide a command to be executed before the auto-refresh on save'),
@@ -40,46 +57,47 @@ const dev = {
40
57
  describe: t('dev_option_local_upstream').d('Host to act as origin in development'),
41
58
  type: 'string'
42
59
  })
43
- .option('m', {
44
- alias: 'minify',
45
- describe: t('dev_option_minify').d('Minify code during development'),
60
+ .option('debug', {
61
+ describe: t('dev_option_debugger').d('Output debug logs'),
46
62
  type: 'boolean',
47
63
  default: false
48
- })
49
- .option('inspect-port', {
50
- describe: t('dev_inspect_port_describe').d('Chrome inspect devTool port'),
51
- type: 'number'
52
- })
53
- .option('p', {
54
- alias: 'port',
55
- describe: t('dev_port_describe').d('Port to listen on'),
56
- type: 'number'
57
64
  });
65
+ if (!useEw2) {
66
+ yargsIns.option('inspect-port', {
67
+ describe: t('dev_inspect_port_describe').d('Chrome inspect devTool port'),
68
+ type: 'number'
69
+ });
70
+ }
71
+ return yargsIns;
58
72
  },
59
73
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
60
74
  let { port, inspectPort } = argv;
61
- let userFileRepacking = false; // flag of user code repack not .dev file change
62
- const { entry, minify, refreshCommand, localUpstream, help } = argv;
75
+ let userFileRepacking = false; // Indicates that user code repacking does not change the .dev file
76
+ const { entry, minify, refreshCommand, localUpstream, help, debug } = argv;
63
77
  if (yargsIns && help) {
64
78
  yargsIns.showHelp('log');
65
- return;
79
+ process.exit(0);
66
80
  }
81
+ if (debug) {
82
+ logger.setLogLevel('debug');
83
+ }
84
+ // Get options and set global variables
67
85
  const projectConfig = getProjectConfig();
68
86
  if (!projectConfig) {
69
- if (entry) {
70
- try {
71
- yield selectToCreateConf(entry);
72
- }
73
- catch (_) {
74
- logger.notInProject();
75
- process.exit(1);
76
- }
87
+ if (!entry) {
88
+ logger.notInProject();
89
+ process.exit(1);
77
90
  }
78
- else {
79
- return logger.notInProject();
91
+ try {
92
+ // If no config is found and an entry is provided, create a new one.
93
+ yield selectToCreateConf(entry);
94
+ }
95
+ catch (_) {
96
+ logger.notInProject();
97
+ process.exit(1);
80
98
  }
81
99
  }
82
- else if (entry) {
100
+ if (entry) {
83
101
  // @ts-ignore
84
102
  global.entry = entry;
85
103
  }
@@ -95,9 +113,18 @@ const dev = {
95
113
  }
96
114
  // @ts-ignore
97
115
  global.port = port;
116
+ logger.debug(`Entered port: ${port}`);
98
117
  }
99
118
  if (inspectPort) {
100
- inspectPort = Number(inspectPort);
119
+ if (Array.isArray(inspectPort)) {
120
+ inspectPort = Number(inspectPort[0]);
121
+ }
122
+ else {
123
+ inspectPort = Number(inspectPort);
124
+ if (isNaN(inspectPort)) {
125
+ logger.warn(t('dev_import_port_invalid').d('Invalid port entered, default port will be used.'));
126
+ }
127
+ }
101
128
  // @ts-ignore
102
129
  global.inspectPort = inspectPort;
103
130
  }
@@ -105,33 +132,63 @@ const dev = {
105
132
  // @ts-ignore
106
133
  global.minify = minify;
107
134
  }
108
- if (minify) {
109
- // @ts-ignore
110
- global.minify = minify;
111
- }
112
135
  if (localUpstream) {
136
+ const url = localUpstream;
113
137
  // @ts-ignore
114
138
  global.localUpstream = localUpstream;
139
+ try {
140
+ const hostname = new URL(url).hostname;
141
+ if (isIP(hostname)) {
142
+ logger.error(t('dev_ip_not_allowed', { url }).d(`Direct access to IP addresses is not allowed when setting local-upstream: ${url}`));
143
+ process.exit(1);
144
+ }
145
+ }
146
+ catch (err) {
147
+ logger.error(t('dev_url_invalid', { url }).d(`Invalid URL: ${url}. Please enter a valid URL.`));
148
+ process.exit(1);
149
+ }
115
150
  }
116
- const runtimeCommand = yield preCheckRuntime();
117
- if (!runtimeCommand) {
118
- return;
151
+ const checkFunc = useEw2 ? preCheckEw2 : preCheckDeno;
152
+ const checkResult = yield checkFunc();
153
+ if (!checkResult) {
154
+ process.exit(1);
119
155
  }
120
- const speDenoPort = getDevConf('port', 'dev', 18080);
121
- const speInspectPort = getDevConf('inspectPort', 'dev', 9229);
122
- try {
156
+ if (useEw2) {
157
+ const speEw2Port = getDevConf('port', 'dev', 18080);
158
+ const result = yield checkAndInputPort(speEw2Port);
159
+ // @ts-ignore
160
+ global.port = result.port;
161
+ }
162
+ else {
163
+ const speDenoPort = getDevConf('port', 'dev', 18080);
164
+ const speInspectPort = getDevConf('inspectPort', 'dev', 9229);
123
165
  const result = yield checkAndInputPort(speDenoPort, speInspectPort);
124
166
  // @ts-ignore
125
- global.port = result.denoPort;
167
+ global.port = result.port;
126
168
  // @ts-ignore
127
169
  global.inspectPort = result.inspectPort;
128
170
  }
171
+ const devPack = useEw2 ? ew2Pack : mockPack;
172
+ try {
173
+ yield devPack();
174
+ }
129
175
  catch (err) {
130
176
  process.exit(1);
131
177
  }
132
- logger.info(`${t('dev_build_start').d('Starting build process')}...`);
133
- yield devPack();
134
- const worker = new WorkerServer({ command: runtimeCommand });
178
+ let worker;
179
+ if (useEw2) {
180
+ worker = new Ew2Server({ onClose: onWorkerClosed });
181
+ }
182
+ else {
183
+ worker = new MockServer({ command: checkResult });
184
+ }
185
+ try {
186
+ yield worker.start();
187
+ }
188
+ catch (err) {
189
+ console.log('Track err', err);
190
+ process.exit(1);
191
+ }
135
192
  const ignored = (path) => {
136
193
  return /(^|[\/\\])\.(?!dev($|[\/\\]))/.test(path);
137
194
  };
@@ -148,7 +205,8 @@ const dev = {
148
205
  worker.restart();
149
206
  return;
150
207
  }
151
- logger.info(`${t('dev_repacking').d('Detected local file changes, re-packaging')}...`);
208
+ logger.info('Dev repack');
209
+ logger.log(`${t('dev_repacking').d('Detected local file changes, re-packaging')}...`);
152
210
  if (refreshCommand) {
153
211
  try {
154
212
  yield execRefreshCommand(refreshCommand);
@@ -159,9 +217,12 @@ const dev = {
159
217
  yield devPack();
160
218
  yield worker.restart();
161
219
  }), 500));
162
- const { devElement } = doProcess(worker);
220
+ var { devElement, exit } = doProcess(worker);
163
221
  const { waitUntilExit } = devElement;
164
222
  yield waitUntilExit();
223
+ function onWorkerClosed() {
224
+ exit && exit();
225
+ }
165
226
  watcher.close();
166
227
  })
167
228
  };
@@ -216,7 +277,8 @@ function execRefreshCommand(cmd) {
216
277
  }
217
278
  function selectToCreateConf(entry) {
218
279
  return new Promise((resolve, reject) => {
219
- logger.info(t('dev_create_config').d('Configuration file not found. Would you like to create one?'));
280
+ logger.info('Configuration file not found');
281
+ logger.log(t('dev_create_config').d('Configuration file not found. Would you like to create one?'));
220
282
  SelectItems({
221
283
  items: [
222
284
  { label: 'Yes', value: 'yes' },
@@ -41,6 +41,7 @@ const dev = async () => {
41
41
  handler: async (request) => {
42
42
  const url = new URL(request.url);
43
43
  let nextRequest = request;
44
+ // Replace the request url with the local upstream url
44
45
  if (config.localUpstream) {
45
46
  const nextUrl = `${config.localUpstream}${url.pathname}${url.search}${url.hash}`;
46
47
  nextRequest = new Request(nextUrl, request);
@@ -49,13 +50,13 @@ const dev = async () => {
49
50
  const res = await worker.fetch(nextRequest);
50
51
  const status = res.status;
51
52
  console.log(
52
- `[Esa Dev] ${request.method} ${url.pathname} ${getColorForStatusCode(status, res.statusText)}`
53
+ `[ESA Dev] ${request.method} ${url.pathname} ${getColorForStatusCode(status, res.statusText)}`
53
54
  );
54
55
  return res;
55
56
  } catch (err) {
56
57
  console.error(err);
57
58
  console.log(
58
- `[Esa Dev] ${request.method} ${url.pathname} ${getColorForStatusCode(500, 'Internal Server Error')}`
59
+ `[ESA Dev] ${request.method} ${url.pathname} ${getColorForStatusCode(500, 'Internal Server Error')}`
59
60
  );
60
61
  return new Response('Internal Server Error', {
61
62
  status: 500
@@ -9,20 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import path from 'path';
11
11
  import fs from 'fs';
12
- import logger from '../../libs/logger.js';
13
- import devBuild from './config/devBuild.js';
14
- import t from '../../i18n/index.js';
15
- import { getDevConf } from '../../utils/fileUtils/index.js';
16
- import { getRoot, getDirName } from '../../utils/fileUtils/base.js';
17
- import { checkPort } from '../../utils/checkDevPort.js';
12
+ import logger from '../../../libs/logger.js';
13
+ import devBuild from '../build.js';
14
+ import t from '../../../i18n/index.js';
15
+ import { getDevConf } from '../../../utils/fileUtils/index.js';
16
+ import { getRoot, getDirName } from '../../../utils/fileUtils/base.js';
17
+ import { checkPort } from '../../../utils/checkDevPort.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');
21
21
  const devEntry = path.resolve(devDir, `devEntry-${id}.js`);
22
- const devEntryTemp = path.resolve(__dirname, './config/devEntry.js');
22
+ const devEntryTemp = path.resolve(__dirname, './devEntry.js');
23
23
  const devEntryTempFile = fs.readFileSync(devEntryTemp, 'utf-8');
24
24
  const mockDevDir = path.resolve(userRoot, '.dev/mock');
25
- const mockDir = path.resolve(__dirname, './config/mock');
25
+ const mockDir = path.resolve(__dirname, './mock');
26
26
  if (!fs.existsSync(devDir)) {
27
27
  yield fs.promises.mkdir(devDir);
28
28
  }
@@ -40,10 +40,12 @@ const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0,
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
44
  const id = new Date().getTime().toString();
44
45
  // @ts-ignore
45
46
  global.id = id;
46
47
  yield generateEntry(id, entry, userRoot);
48
+ // 给每一次 dev 的配置项,在一个文件中通过 id 区分
47
49
  if (fs.existsSync(configPath)) {
48
50
  const currentConfig = fs
49
51
  .readFileSync(configPath, 'utf-8')