esa-cli 0.0.2-beta.9 → 1.0.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 (85) hide show
  1. package/README.md +32 -149
  2. package/dist/commands/commit/index.js +49 -104
  3. package/dist/commands/commit/prodBuild.js +2 -3
  4. package/dist/commands/common/constant.js +4 -4
  5. package/dist/commands/common/utils.js +419 -0
  6. package/dist/commands/config.js +2 -2
  7. package/dist/commands/deploy/helper.js +51 -54
  8. package/dist/commands/deploy/index.js +51 -174
  9. package/dist/commands/deployments/delete.js +32 -22
  10. package/dist/commands/deployments/index.js +4 -4
  11. package/dist/commands/deployments/list.js +21 -34
  12. package/dist/commands/dev/build.js +3 -3
  13. package/dist/commands/dev/doProcess.js +5 -5
  14. package/dist/commands/dev/ew2/cacheService.js +33 -0
  15. package/dist/commands/dev/ew2/devEntry.js +2 -1
  16. package/dist/commands/dev/ew2/devPack.js +31 -20
  17. package/dist/commands/dev/ew2/kvService.js +50 -0
  18. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  19. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  20. package/dist/commands/dev/ew2/server.js +165 -29
  21. package/dist/commands/dev/index.js +17 -18
  22. package/dist/commands/dev/mockWorker/devPack.js +19 -10
  23. package/dist/commands/dev/mockWorker/server.js +7 -6
  24. package/dist/commands/domain/add.js +4 -4
  25. package/dist/commands/domain/delete.js +7 -7
  26. package/dist/commands/domain/index.js +4 -4
  27. package/dist/commands/domain/list.js +10 -10
  28. package/dist/commands/init/helper.js +654 -20
  29. package/dist/commands/init/index.js +88 -152
  30. package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
  31. package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
  32. package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
  33. package/dist/commands/init/template.jsonc +84 -0
  34. package/dist/commands/init/types.js +1 -0
  35. package/dist/commands/lang.js +2 -2
  36. package/dist/commands/login/index.js +74 -34
  37. package/dist/commands/logout.js +6 -6
  38. package/dist/commands/route/add.js +105 -49
  39. package/dist/commands/route/delete.js +33 -27
  40. package/dist/commands/route/helper.js +123 -0
  41. package/dist/commands/route/index.js +4 -4
  42. package/dist/commands/route/list.js +56 -17
  43. package/dist/commands/routine/delete.js +9 -8
  44. package/dist/commands/routine/index.js +6 -5
  45. package/dist/commands/routine/list.js +45 -39
  46. package/dist/commands/site/index.js +3 -3
  47. package/dist/commands/site/list.js +6 -7
  48. package/dist/commands/utils.js +61 -25
  49. package/dist/components/descriptionInput.js +1 -1
  50. package/dist/components/filterSelector.js +1 -1
  51. package/dist/components/mutiLevelSelect.js +19 -20
  52. package/dist/components/mutiSelectTable.js +1 -1
  53. package/dist/components/routeBuilder.js +68 -0
  54. package/dist/components/selectInput.js +2 -3
  55. package/dist/components/selectItem.js +1 -1
  56. package/dist/docs/Commands_en.md +164 -117
  57. package/dist/docs/Commands_zh_CN.md +155 -107
  58. package/dist/docs/Config_en.md +70 -0
  59. package/dist/docs/Config_zh_CN.md +68 -0
  60. package/dist/i18n/index.js +2 -2
  61. package/dist/i18n/locales.json +447 -71
  62. package/dist/index.js +28 -13
  63. package/dist/libs/api.js +32 -9
  64. package/dist/libs/apiService.js +294 -73
  65. package/dist/libs/git/index.js +86 -9
  66. package/dist/libs/interface.js +0 -1
  67. package/dist/libs/logger.js +162 -10
  68. package/dist/libs/service.js +2 -2
  69. package/dist/libs/templates/index.js +1 -1
  70. package/dist/utils/checkAssetsExist.js +80 -0
  71. package/dist/utils/checkDevPort.js +5 -19
  72. package/dist/utils/checkEntryFileExist.js +10 -0
  73. package/dist/utils/checkIsRoutineCreated.js +27 -21
  74. package/dist/utils/checkVersion.js +119 -1
  75. package/dist/utils/command.js +149 -0
  76. package/dist/utils/compress.js +142 -0
  77. package/dist/utils/download.js +8 -8
  78. package/dist/utils/fileMd5.js +1 -1
  79. package/dist/utils/fileUtils/index.js +136 -45
  80. package/dist/utils/installDeno.js +4 -4
  81. package/dist/utils/installEw2.js +9 -9
  82. package/dist/utils/openInBrowser.js +1 -1
  83. package/dist/utils/prompt.js +97 -0
  84. package/package.json +24 -13
  85. package/zh_CN.md +29 -154
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { execSync } from 'child_process';
11
- import { exit } from 'process';
11
+ import logger from '../../libs/logger.js';
12
12
  export function isInstalledGit() {
13
13
  try {
14
14
  execSync('git --version');
@@ -30,23 +30,100 @@ export function isGitConfigured() {
30
30
  }
31
31
  export function cloneRepository(url, path) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
+ if (!isInstalledGit()) {
34
+ logger.error('Git is not installed on your system.');
35
+ logger.info('Please install Git first:');
36
+ logger.info(' • macOS: brew install git');
37
+ logger.info(' • Ubuntu/Debian: sudo apt-get install git');
38
+ logger.info(' • Windows: Download from https://git-scm.com/');
39
+ logger.info(' • Or visit: https://git-scm.com/downloads');
40
+ return false;
41
+ }
33
42
  try {
34
43
  execSync(`git clone ${url} ${path}`, { stdio: 'inherit' });
35
- console.log('Repository cloned successfully.');
44
+ logger.log('Repository cloned successfully.');
45
+ return true;
36
46
  }
37
47
  catch (error) {
38
- console.error('Error occurred while cloning the repository:', error);
39
- exit(0);
48
+ logger.error(`Error occurred while cloning the repository: ${error}`);
49
+ return false;
40
50
  }
41
51
  });
42
52
  }
43
- export function installGit(path) {
53
+ export function installGit(path, debug = false, autoInstall = false) {
54
+ if (!isInstalledGit()) {
55
+ if (autoInstall) {
56
+ logger.info('Git not found. Attempting to auto-install...');
57
+ if (autoInstallGit()) {
58
+ logger.info('Git installed successfully! Now initializing repository...');
59
+ }
60
+ else {
61
+ logger.error('Failed to auto-install Git.');
62
+ logger.info('Please install Git manually:');
63
+ logger.info(' • macOS: brew install git');
64
+ logger.info(' • Ubuntu/Debian: sudo apt-get install git');
65
+ logger.info(' • Windows: Download from https://git-scm.com/');
66
+ logger.info(' • Or visit: https://git-scm.com/downloads');
67
+ return false;
68
+ }
69
+ }
70
+ else {
71
+ logger.error('Git is not installed on your system.');
72
+ logger.info('Please install Git first:');
73
+ logger.info(' • macOS: brew install git');
74
+ logger.info(' • Ubuntu/Debian: sudo apt-get install git');
75
+ logger.info(' • Windows: Download from https://git-scm.com/');
76
+ logger.info(' • Or visit: https://git-scm.com/downloads');
77
+ return false;
78
+ }
79
+ }
80
+ try {
81
+ execSync('git init', { stdio: 'ignore', cwd: path });
82
+ if (debug) {
83
+ logger.log('Git repository initialized successfully.');
84
+ }
85
+ return true;
86
+ }
87
+ catch (error) {
88
+ logger.error(`Error occurred while initializing Git repository: ${error}`);
89
+ return false;
90
+ }
91
+ }
92
+ /**
93
+ * Attempt to automatically install Git on supported platforms
94
+ * @returns true if installation was successful, false otherwise
95
+ */
96
+ export function autoInstallGit() {
44
97
  try {
45
- execSync('git init', { stdio: 'inherit', cwd: path });
46
- console.log('Git has been installed successfully.');
98
+ const platform = process.platform;
99
+ if (platform === 'darwin') {
100
+ // macOS - try using Homebrew
101
+ logger.info('Attempting to install Git using Homebrew...');
102
+ execSync('brew install git', { stdio: 'inherit' });
103
+ logger.success('Git installed successfully via Homebrew!');
104
+ return true;
105
+ }
106
+ else if (platform === 'linux') {
107
+ // Linux - try using apt-get (Ubuntu/Debian)
108
+ logger.info('Attempting to install Git using apt-get...');
109
+ execSync('sudo apt-get update && sudo apt-get install -y git', {
110
+ stdio: 'inherit'
111
+ });
112
+ logger.success('Git installed successfully via apt-get!');
113
+ return true;
114
+ }
115
+ else {
116
+ logger.warn('Auto-installation is not supported on this platform.');
117
+ logger.info('Please install Git manually from: https://git-scm.com/downloads');
118
+ return false;
119
+ }
47
120
  }
48
121
  catch (error) {
49
- console.error('Error occurred during Git installation:', error);
50
- exit(0);
122
+ logger.error(`Failed to auto-install Git: ${error}`);
123
+ logger.info('Please install Git manually:');
124
+ logger.info(' • macOS: brew install git');
125
+ logger.info(' • Ubuntu/Debian: sudo apt-get install git');
126
+ logger.info(' • Windows: Download from https://git-scm.com/');
127
+ return false;
51
128
  }
52
129
  }
@@ -7,7 +7,6 @@ export var PublishType;
7
7
  (function (PublishType) {
8
8
  PublishType["Staging"] = "staging";
9
9
  PublishType["Production"] = "production";
10
- PublishType["Canary"] = "canary";
11
10
  })(PublishType || (PublishType = {}));
12
11
  var BasicType;
13
12
  (function (BasicType) {
@@ -1,10 +1,10 @@
1
+ import os from 'os';
2
+ import path from 'path';
1
3
  import chalk from 'chalk';
2
- import { format, createLogger } from 'winston';
3
- import DailyRotateFile from 'winston-daily-rotate-file';
4
4
  import Table from 'cli-table3';
5
- import path from 'path';
6
- import os from 'os';
7
5
  import ora from 'ora';
6
+ import { format, createLogger } from 'winston';
7
+ import DailyRotateFile from 'winston-daily-rotate-file';
8
8
  import t from '../i18n/index.js';
9
9
  import { getProjectConfig } from '../utils/fileUtils/index.js';
10
10
  const transport = new DailyRotateFile({
@@ -17,6 +17,7 @@ const transport = new DailyRotateFile({
17
17
  });
18
18
  class Logger {
19
19
  constructor() {
20
+ this.spinnerText = '';
20
21
  const { combine, timestamp, label, printf } = format;
21
22
  const customFormat = printf(({ level, message, label: printLabel, timestamp: printTimestamp }) => {
22
23
  var _a;
@@ -65,6 +66,60 @@ class Logger {
65
66
  setLogLevel(level) {
66
67
  this.logger.level = level;
67
68
  }
69
+ /**
70
+ * Start a sub-step: show a spinner with the provided message.
71
+ * If a spinner is already running, just update its text.
72
+ */
73
+ startSubStep(message) {
74
+ this.spinnerText = message;
75
+ this.spinner.text = message;
76
+ if (!this.spinner.isSpinning) {
77
+ this.spinner.start();
78
+ }
79
+ }
80
+ /**
81
+ * End a sub-step: stop loading and replace spinner with `├` and final message.
82
+ * This overwrites the previous spinner line with the provided message.
83
+ */
84
+ endSubStep(message) {
85
+ // console.log(chalk.gray('├') + ' ' + this.spinnerText);
86
+ try {
87
+ if (this.spinner && this.spinner.isSpinning) {
88
+ this.spinner.stop();
89
+ }
90
+ }
91
+ catch (_a) { }
92
+ console.log(chalk.gray(`│ `));
93
+ console.log(chalk.gray('├ ') + this.spinnerText);
94
+ console.log(chalk.gray(`│ ${message}`));
95
+ }
96
+ stopSpinner() {
97
+ try {
98
+ if (this.spinner && this.spinner.isSpinning) {
99
+ this.spinner.stop();
100
+ }
101
+ }
102
+ catch (_a) { }
103
+ }
104
+ /**
105
+ * Prepare terminal output just before showing an interactive prompt.
106
+ * - Stops any active spinner
107
+ * - Replaces the previous line with a clean `╰ <text>` indicator
108
+ */
109
+ prepareForPrompt(text) {
110
+ this.stopSpinner();
111
+ const content = `╰ ${text || ''}`;
112
+ this.replacePrevLine(content);
113
+ }
114
+ /**
115
+ * Consolidate interactive prompt output after completion by replacing
116
+ * the previous N lines with a concise summary line.
117
+ * Defaults to 2 lines (prompt + answer line in most cases).
118
+ */
119
+ consolidateAfterPrompt(summary, linesToReplace = 2) {
120
+ const content = `├ ${summary}`;
121
+ this.replacePrevLines(linesToReplace, content);
122
+ }
68
123
  log(message) {
69
124
  console.log(message);
70
125
  }
@@ -72,7 +127,7 @@ class Logger {
72
127
  console.log(`\t${message}`);
73
128
  }
74
129
  success(message) {
75
- console.log(`\n🎉 ${chalk.bgGreen(' SUCCESS ')} ${chalk.green(message)}`);
130
+ console.log(`🎉 ${chalk.bgGreen(' SUCCESS ')} ${chalk.green(message)}`);
76
131
  }
77
132
  debug(message) {
78
133
  this.logger.debug(message);
@@ -120,14 +175,53 @@ class Logger {
120
175
  console.log(message);
121
176
  }
122
177
  notInProject() {
123
- const initCommand = chalk.green('esa init');
124
- this.error(t('common_not_edge_project', { initCommand }).d(`You are not in an esa project, Please run ${initCommand} to initialize a project, or enter an esa project.`));
178
+ this.block();
179
+ this.error('Missing ESA project configuration (esa.jsonc or esa.toml)');
180
+ this.block();
181
+ this.log('If there is code to deploy, you can either:');
182
+ this.subLog(`- Specify an entry-point to your Routine via the command line (ex: ${chalk.green('esa-cli deploy src/index.ts')})`);
183
+ this.subLog('- Or create an "esa.jsonc" file (recommended):');
184
+ console.log('```jsonc\n' +
185
+ '{\n' +
186
+ ' "name": "my-routine",\n' +
187
+ ' "entry": "src/index.ts",\n' +
188
+ ' "dev": { "port": 18080 }\n' +
189
+ '}\n' +
190
+ '```');
191
+ this.subLog('- Or, if you prefer TOML, create an "esa.toml" file:');
192
+ console.log('```toml\n' +
193
+ 'name = "my-routine"\n' +
194
+ 'entry = "src/index.ts"\n' +
195
+ '\n' +
196
+ '[dev]\n' +
197
+ 'port = 18080\n' +
198
+ '```\n');
199
+ this.log('If you are deploying a directory of static assets, you can either:');
200
+ this.subLog(`- Create an "esa.jsonc" file (recommended) and run ${chalk.green('esa-cli deploy -a ./dist')}`);
201
+ console.log('```jsonc\n' +
202
+ '{\n' +
203
+ ' "name": "my-routine",\n' +
204
+ ' "assets": {\n' +
205
+ ' "directory": "./dist"\n' +
206
+ ' }\n' +
207
+ '}\n' +
208
+ '```');
209
+ this.subLog(`- Or create an "esa.toml" file and run ${chalk.green('esa-cli deploy -a ./dist')}`);
210
+ console.log('```toml\n' +
211
+ 'name = "my-routine"\n' +
212
+ '\n' +
213
+ '[assets]\n' +
214
+ 'directory = "./dist"\n' +
215
+ '```\n');
216
+ this.log('Alternatively, initialize a new ESA project:');
217
+ this.log(chalk.green('$ esa-cli init my-project'));
218
+ this.block();
125
219
  }
126
220
  pathEacces(localPath) {
127
221
  this.block();
128
222
  this.log(chalk.yellow(t('common_eacces_intro', { localPath }).d(`You do not have permission to ${localPath}, please use`)));
129
223
  this.block();
130
- this.log(chalk.green(`$ ${chalk.red('sudo')} esa <Command>`));
224
+ this.log(chalk.green(`$ ${chalk.red('sudo')} esa-cli <Command>`));
131
225
  this.block();
132
226
  this.subLog(chalk.yellow('OR'));
133
227
  this.block();
@@ -146,15 +240,73 @@ class Logger {
146
240
  if (messages.length === 0)
147
241
  return;
148
242
  const lines = [];
149
- lines.push(`╭─ ${messages[0]}`);
243
+ lines.push(`╭ ${messages[0]}`);
150
244
  for (let i = 1; i < messages.length - 1; i++) {
151
245
  lines.push(`│ ${messages[i]}`);
152
246
  }
153
247
  if (messages.length > 1) {
154
- lines.push(`╰─ ${messages[messages.length - 1]}`);
248
+ lines.push(`╰ ${messages[messages.length - 1]}`);
155
249
  }
156
250
  console.log(lines.join('\n'));
157
251
  }
252
+ StepHeader(title, step, total) {
253
+ console.log(`\n╭ ${title} ${chalk.green(`Step ${step} of ${total}`)}`);
254
+ console.log('│');
255
+ }
256
+ StepItem(prompt) {
257
+ console.log(`├ ${prompt}`);
258
+ }
259
+ StepStart(prompt) {
260
+ console.log(`╭ ${prompt}`);
261
+ }
262
+ StepKV(key, value) {
263
+ const orange = chalk.hex('#FFA500');
264
+ console.log(`│ ${orange(key)} ${value}`);
265
+ }
266
+ StepSpacer() {
267
+ console.log('│');
268
+ }
269
+ StepEnd(str) {
270
+ console.log(`╰ ${str || ''}`);
271
+ }
272
+ StepEndInline() {
273
+ try {
274
+ process.stdout.write('╰ ');
275
+ }
276
+ catch (_a) {
277
+ console.log('╰');
278
+ }
279
+ }
280
+ divider() {
281
+ console.log(chalk.yellow('--------------------------------------------------------'));
282
+ }
283
+ // Replace the previous single terminal line with new content
284
+ replacePrevLine(content) {
285
+ try {
286
+ // Move cursor up 1 line, clear it, carriage return, print new content
287
+ process.stdout.write('\x1b[1A');
288
+ process.stdout.write('\x1b[2K');
289
+ process.stdout.write('\r');
290
+ console.log(content);
291
+ }
292
+ catch (_a) {
293
+ console.log(content);
294
+ }
295
+ }
296
+ // Replace multiple previous lines with one consolidated line
297
+ replacePrevLines(linesToReplace, content) {
298
+ try {
299
+ for (let i = 0; i < linesToReplace; i++) {
300
+ process.stdout.write('\x1b[1A'); // move up
301
+ process.stdout.write('\x1b[2K'); // clear line
302
+ }
303
+ process.stdout.write('\r');
304
+ console.log(content);
305
+ }
306
+ catch (_a) {
307
+ console.log(content);
308
+ }
309
+ }
158
310
  }
159
311
  const logger = Logger.getInstance();
160
312
  export default logger;
@@ -7,10 +7,10 @@ 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 ora from 'ora';
11
- import chain from 'lodash';
12
10
  import FormData from 'form-data';
11
+ import chain from 'lodash';
13
12
  import fetch from 'node-fetch';
13
+ import ora from 'ora';
14
14
  import t from '../i18n/index.js';
15
15
  import api from './api.js';
16
16
  import { Environment } from './interface.js';
@@ -1,5 +1,5 @@
1
- import { getSummary } from '../../commands/common/constant.js';
2
1
  import chalk from 'chalk';
2
+ import { getSummary } from '../../commands/common/constant.js';
3
3
  import logger from '../logger.js';
4
4
  export default class Template {
5
5
  constructor(path, title) {
@@ -0,0 +1,80 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { getProjectConfig } from './fileUtils/index.js';
4
+ /**
5
+ * Check if the assets directory exists in the project config
6
+ * @returns {boolean} true if the assets directory exists, false otherwise
7
+ */
8
+ const checkConfigAssetsExist = () => {
9
+ var _a;
10
+ const projectConfig = getProjectConfig();
11
+ if (!projectConfig) {
12
+ return false;
13
+ }
14
+ const directory = (_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory;
15
+ if (!directory) {
16
+ return false;
17
+ }
18
+ return true;
19
+ };
20
+ export var EDGE_ROUTINE_TYPE;
21
+ (function (EDGE_ROUTINE_TYPE) {
22
+ EDGE_ROUTINE_TYPE["ASSETS_ONLY"] = "assets_only";
23
+ EDGE_ROUTINE_TYPE["JS_ONLY"] = "js_only";
24
+ EDGE_ROUTINE_TYPE["JS_AND_ASSETS"] = "js_and_assets";
25
+ EDGE_ROUTINE_TYPE["NOT_EXIST"] = "not_exist";
26
+ })(EDGE_ROUTINE_TYPE || (EDGE_ROUTINE_TYPE = {}));
27
+ /**
28
+ * Check if a path exists and is valid
29
+ * @param filePath - The path to check
30
+ * @param isDirectory - Whether the path should be a directory
31
+ * @returns boolean
32
+ */
33
+ const isValidPath = (filePath, isDirectory = false) => {
34
+ if (!filePath || typeof filePath !== 'string' || filePath.trim() === '') {
35
+ return false;
36
+ }
37
+ try {
38
+ const resolvedPath = path.isAbsolute(filePath)
39
+ ? filePath
40
+ : path.resolve(filePath);
41
+ const exists = fs.existsSync(resolvedPath);
42
+ if (!exists) {
43
+ return false;
44
+ }
45
+ if (isDirectory) {
46
+ return fs.statSync(resolvedPath).isDirectory();
47
+ }
48
+ else {
49
+ return fs.statSync(resolvedPath).isFile();
50
+ }
51
+ }
52
+ catch (error) {
53
+ return false;
54
+ }
55
+ };
56
+ export const checkEdgeRoutineType = (scriptEntry, assetsDirectory, projectPath) => {
57
+ var _a;
58
+ const projectConfig = getProjectConfig(projectPath);
59
+ const entry = scriptEntry || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry);
60
+ const assets = assetsDirectory || ((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory);
61
+ const entryPath = path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', entry !== null && entry !== void 0 ? entry : '');
62
+ const assetsPath = path.resolve(projectPath !== null && projectPath !== void 0 ? projectPath : '', assets !== null && assets !== void 0 ? assets : '');
63
+ const hasAssets = isValidPath(assetsPath, true) && assets;
64
+ const hasEntry = isValidPath(entryPath, false) && entry;
65
+ // Both assets and entry exist
66
+ if (hasAssets && hasEntry) {
67
+ return EDGE_ROUTINE_TYPE.JS_AND_ASSETS;
68
+ }
69
+ // Only assets exist
70
+ if (hasAssets && !hasEntry) {
71
+ return EDGE_ROUTINE_TYPE.ASSETS_ONLY;
72
+ }
73
+ // Only entry exists
74
+ if (!hasAssets && hasEntry) {
75
+ return EDGE_ROUTINE_TYPE.JS_ONLY;
76
+ }
77
+ // Neither exists
78
+ return EDGE_ROUTINE_TYPE.NOT_EXIST;
79
+ };
80
+ export default checkConfigAssetsExist;
@@ -7,12 +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 portscanner from 'portscanner';
11
- import SelectItems from '../components/selectInput.js';
10
+ import chalk from 'chalk';
12
11
  import inquirer from 'inquirer';
13
- import logger from '../libs/logger.js';
12
+ import portscanner from 'portscanner';
14
13
  import t from '../i18n/index.js';
15
- import chalk from 'chalk';
14
+ import logger from '../libs/logger.js';
16
15
  export const checkPort = (port) => {
17
16
  return new Promise((resolve) => {
18
17
  portscanner.checkPortStatus(port, '127.0.0.1', (error, status) => {
@@ -28,19 +27,6 @@ export const checkPort = (port) => {
28
27
  });
29
28
  });
30
29
  };
31
- const ask = () => {
32
- return new Promise((resolve) => {
33
- SelectItems({
34
- items: [
35
- { label: 'Yes', value: 'yes' },
36
- { label: 'No', value: 'no' }
37
- ],
38
- handleSelect: (item) => __awaiter(void 0, void 0, void 0, function* () {
39
- resolve(item.value === 'yes');
40
- })
41
- });
42
- });
43
- };
44
30
  const findAvailablePort = (startPort) => __awaiter(void 0, void 0, void 0, function* () {
45
31
  return yield portscanner.findAPortNotInUse(startPort, 65535);
46
32
  });
@@ -76,7 +62,7 @@ const checkAndInputPort = (port, inspectPort) => __awaiter(void 0, void 0, void
76
62
  }
77
63
  }
78
64
  catch (_) {
79
- const option = chalk.green('esa dev --port <port>');
65
+ const option = chalk.green('esa-cli dev --port <port>');
80
66
  logger.log(t('dev_port_used_advice', { option }).d(`You can use ${option} to specify another port.`));
81
67
  throw new Error('Specified port already in use.');
82
68
  }
@@ -102,7 +88,7 @@ const checkAndInputPort = (port, inspectPort) => __awaiter(void 0, void 0, void
102
88
  ])).port;
103
89
  }
104
90
  catch (_) {
105
- const option = chalk.green('esa dev --inspect-port <port>');
91
+ const option = chalk.green('esa-cli dev --inspect-port <port>');
106
92
  logger.log(t('dev_port_used_advice', { option }).d(`You can use ${option} to specify another port.`));
107
93
  throw new Error('Inspect port already in use.');
108
94
  }
@@ -0,0 +1,10 @@
1
+ import fs from 'fs';
2
+ import { getProjectConfig } from './fileUtils/index.js';
3
+ export const checkEntryFileExist = () => {
4
+ const projectConfig = getProjectConfig();
5
+ const entry = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry;
6
+ if (!entry) {
7
+ return true;
8
+ }
9
+ return fs.existsSync(entry);
10
+ };
@@ -7,15 +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 path from 'path';
11
- import { createEdgeRoutine } from '../commands/commit/index.js';
12
- import { ApiService } from '../libs/apiService.js';
13
- import { readEdgeRoutineFile } from './fileUtils/index.js';
14
- import logger from '../libs/logger.js';
15
- import t from '../i18n/index.js';
16
- import prodBuild from '../commands/commit/prodBuild.js';
17
10
  import { exit } from 'process';
11
+ import { log } from '@clack/prompts';
18
12
  import chalk from 'chalk';
13
+ import t from '../i18n/index.js';
14
+ import { ApiService } from '../libs/apiService.js';
15
+ import logger from '../libs/logger.js';
19
16
  export function isRoutineExist(name) {
20
17
  return __awaiter(this, void 0, void 0, function* () {
21
18
  const server = yield ApiService.getInstance();
@@ -28,29 +25,38 @@ export function validRoutine(name) {
28
25
  return __awaiter(this, void 0, void 0, function* () {
29
26
  const isCreatedRoutine = yield isRoutineExist(name);
30
27
  if (!isCreatedRoutine) {
31
- logger.warn(`${t('routine_not_exist').d('Routine does not exist, please create a new one. Run command:')} ${chalk.greenBright('esa deploy')}`);
32
- exit(0);
28
+ logger.warn(`${t('routine_not_exist').d('Project does not exist, please create a new one. Run command:')} ${chalk.greenBright('esa-cli deploy')}`);
29
+ exit(1);
33
30
  }
34
31
  });
35
32
  }
36
- export function checkRoutineExist(name, entry) {
33
+ /**
34
+ * Ensure routine exists, if not, create a new routine
35
+ * @param name - Routine name
36
+ */
37
+ export function ensureRoutineExists(name) {
37
38
  return __awaiter(this, void 0, void 0, function* () {
38
- const isCreatedRoutine = yield isRoutineExist(name);
39
- if (!isCreatedRoutine) {
40
- logger.log(t('first_deploy').d('This is the first time to deploy, we will create a new routine for you.'));
41
- const entryFile = path.resolve(entry !== null && entry !== void 0 ? entry : '', 'src/index.js');
42
- yield prodBuild(false, entryFile, entry);
43
- const code = readEdgeRoutineFile(entry) || '';
44
- const res = yield createEdgeRoutine({
39
+ const isExist = yield isRoutineExist(name);
40
+ // If routine does not exist, create a new routine
41
+ if (!isExist) {
42
+ logger.startSubStep(`Creating routine ${chalk.gray(name)}`);
43
+ const server = yield ApiService.getInstance();
44
+ const createRes = yield server.createRoutine({
45
45
  name: name,
46
- code: code
46
+ description: '',
47
+ hasAssets: true
47
48
  });
48
- if (res) {
49
- logger.success(t('routine_create_success').d('Routine created successfully.'));
49
+ const isSuccess = (createRes === null || createRes === void 0 ? void 0 : createRes.data.Status) === 'OK';
50
+ if (isSuccess) {
51
+ logger.endSubStep('Routine created successfully');
50
52
  }
51
53
  else {
52
- logger.error(t('routine_create_fail').d('Routine created failed.'));
54
+ logger.endSubStep('Routine created failed');
55
+ exit();
53
56
  }
54
57
  }
58
+ else {
59
+ log.step('Routine has already exists');
60
+ }
55
61
  });
56
62
  }