esa-cli 0.0.2-beta.12 → 0.0.2-beta.13

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 (70) hide show
  1. package/dist/commands/commit/index.js +20 -119
  2. package/dist/commands/commit/prodBuild.js +2 -3
  3. package/dist/commands/common/routineUtils.js +276 -0
  4. package/dist/commands/config.js +1 -1
  5. package/dist/commands/deploy/helper.js +31 -36
  6. package/dist/commands/deploy/index.js +78 -165
  7. package/dist/commands/deployments/delete.js +31 -6
  8. package/dist/commands/deployments/index.js +3 -3
  9. package/dist/commands/deployments/list.js +18 -27
  10. package/dist/commands/dev/build.js +3 -3
  11. package/dist/commands/dev/doProcess.js +5 -5
  12. package/dist/commands/dev/ew2/devPack.js +17 -8
  13. package/dist/commands/dev/ew2/mock/kv.js +2 -2
  14. package/dist/commands/dev/ew2/server.js +13 -10
  15. package/dist/commands/dev/index.js +12 -12
  16. package/dist/commands/dev/mockWorker/devPack.js +16 -7
  17. package/dist/commands/dev/mockWorker/server.js +7 -6
  18. package/dist/commands/domain/add.js +3 -3
  19. package/dist/commands/domain/delete.js +3 -3
  20. package/dist/commands/domain/index.js +3 -3
  21. package/dist/commands/domain/list.js +7 -7
  22. package/dist/commands/init/helper.js +59 -9
  23. package/dist/commands/init/index.js +416 -76
  24. package/dist/commands/init/template.jsonc +34 -0
  25. package/dist/commands/lang.js +2 -2
  26. package/dist/commands/login/index.js +9 -5
  27. package/dist/commands/logout.js +6 -6
  28. package/dist/commands/route/add.js +134 -43
  29. package/dist/commands/route/delete.js +6 -6
  30. package/dist/commands/route/index.js +3 -3
  31. package/dist/commands/route/list.js +4 -4
  32. package/dist/commands/routine/delete.js +2 -2
  33. package/dist/commands/routine/index.js +3 -3
  34. package/dist/commands/routine/list.js +5 -16
  35. package/dist/commands/site/index.js +2 -2
  36. package/dist/commands/site/list.js +6 -7
  37. package/dist/commands/utils.js +55 -19
  38. package/dist/components/descriptionInput.js +1 -1
  39. package/dist/components/mutiSelectTable.js +1 -1
  40. package/dist/components/selectInput.js +2 -3
  41. package/dist/components/selectItem.js +1 -1
  42. package/dist/docs/Commands_en.md +12 -16
  43. package/dist/docs/Commands_zh_CN.md +12 -16
  44. package/dist/docs/eslint-config-en.md +1 -0
  45. package/dist/docs/eslint-config.md +73 -0
  46. package/dist/docs/init-command-quick-test.md +208 -0
  47. package/dist/docs/init-command-test-guide.md +598 -0
  48. package/dist/i18n/index.js +2 -2
  49. package/dist/i18n/locales.json +161 -9
  50. package/dist/index.js +11 -11
  51. package/dist/libs/apiService.js +177 -14
  52. package/dist/libs/git/index.js +8 -4
  53. package/dist/libs/logger.js +63 -7
  54. package/dist/libs/service.js +2 -2
  55. package/dist/libs/templates/index.js +1 -1
  56. package/dist/utils/checkAssetsExist.js +80 -0
  57. package/dist/utils/checkDevPort.js +3 -17
  58. package/dist/utils/checkEntryFileExist.js +10 -0
  59. package/dist/utils/checkIsRoutineCreated.js +17 -16
  60. package/dist/utils/checkVersion.js +1 -1
  61. package/dist/utils/compress.js +80 -0
  62. package/dist/utils/download.js +5 -5
  63. package/dist/utils/fileMd5.js +1 -1
  64. package/dist/utils/fileUtils/index.js +71 -22
  65. package/dist/utils/installDeno.js +3 -3
  66. package/dist/utils/installEw2.js +7 -7
  67. package/dist/utils/openInBrowser.js +1 -1
  68. package/package.json +9 -3
  69. package/dist/docs/Dev_en.md +0 -0
  70. package/dist/docs/Dev_zh_CN.md +0 -0
@@ -10,21 +10,21 @@ 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
30
  const EW2OS = [Platforms.AppleArm, Platforms.AppleIntel, Platforms.LinuxX86];
@@ -221,7 +221,7 @@ const dev = {
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');
@@ -78,10 +78,19 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
78
78
  const devPack = () => __awaiter(void 0, void 0, void 0, function* () {
79
79
  logger.ora.start('Processing...\n');
80
80
  const userRoot = getRoot();
81
- 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
+ }
82
91
  let port, minify, localUpstream, entry;
83
92
  let projectEntry = path.resolve(userRoot, 'src/index.js');
84
- if (fs.existsSync(configPath)) {
93
+ if (configPath) {
85
94
  port = getDevConf('port', 'dev', 18080);
86
95
  minify = getDevConf('minify', 'dev', false);
87
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')}`,
@@ -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()) {
@@ -7,16 +7,16 @@ 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 fs from 'fs-extra';
11
- import path from 'path';
12
- import Template from '../../libs/templates/index.js';
13
- import { getProjectConfig } from '../../utils/fileUtils/index.js';
14
- import logger from '../../libs/logger.js';
15
10
  import { execSync } from 'child_process';
16
- import t from '../../i18n/index.js';
11
+ import path from 'path';
17
12
  import chalk from 'chalk';
13
+ import fs from 'fs-extra';
18
14
  import inquirer from 'inquirer';
15
+ import t from '../../i18n/index.js';
16
+ import logger from '../../libs/logger.js';
17
+ import Template from '../../libs/templates/index.js';
19
18
  import { getDirName } from '../../utils/fileUtils/base.js';
19
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
20
20
  export const getTemplateInstances = (templateHubPath) => {
21
21
  return fs
22
22
  .readdirSync(templateHubPath)
@@ -66,11 +66,34 @@ export const preInstallDependencies = (targetPath) => __awaiter(void 0, void 0,
66
66
  else {
67
67
  logger.log(t('no_build_script').d('No build script found in package.json, skipping build step.'));
68
68
  }
69
+ // After build, try to infer assets directory if not explicitly known
70
+ try {
71
+ const candidates = ['dist', 'build', 'out'];
72
+ for (const dir of candidates) {
73
+ const abs = path.join(targetPath, dir);
74
+ if (fs.existsSync(abs) && fs.statSync(abs).isDirectory()) {
75
+ // Update config file if present and assets not set
76
+ const projectConfig = getProjectConfig(targetPath);
77
+ if (projectConfig) {
78
+ const { updateProjectConfigFile } = yield import('../../utils/fileUtils/index.js');
79
+ if (!projectConfig.assets || !projectConfig.assets.directory) {
80
+ yield updateProjectConfigFile({ assets: { directory: dir } }, targetPath);
81
+ logger.success(`Detected build output "${dir}" and updated assets.directory`);
82
+ }
83
+ }
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ catch (_a) { }
69
89
  }
70
90
  });
71
91
  export function checkAndUpdatePackage(packageName) {
72
92
  return __awaiter(this, void 0, void 0, function* () {
73
93
  try {
94
+ const spinner = logger.ora;
95
+ spinner.text = t('checking_template_update').d('Checking esa-template updates...');
96
+ spinner.start();
74
97
  // 获取当前安装的版本
75
98
  const __dirname = getDirName(import.meta.url);
76
99
  const packageJsonPath = path.join(__dirname, '../../../');
@@ -81,6 +104,7 @@ export function checkAndUpdatePackage(packageName) {
81
104
  }).toString();
82
105
  }
83
106
  catch (e) {
107
+ spinner.text = t('template_updating').d('Updating templates to latest...');
84
108
  execSync(`rm -rf node_modules/${packageName}`, {
85
109
  cwd: packageJsonPath
86
110
  });
@@ -88,6 +112,8 @@ export function checkAndUpdatePackage(packageName) {
88
112
  cwd: packageJsonPath,
89
113
  stdio: 'inherit'
90
114
  });
115
+ spinner.stop();
116
+ logger.log(`├ ${t('template_updated_to_latest').d('Templates updated to latest.')}`);
91
117
  return;
92
118
  }
93
119
  const match = versionInfo.match(new RegExp(`(${packageName})@([0-9.]+)`));
@@ -99,6 +125,7 @@ export function checkAndUpdatePackage(packageName) {
99
125
  .toString()
100
126
  .trim();
101
127
  if (currentVersion !== latestVersion) {
128
+ spinner.stop();
102
129
  logger.log(t('display_current_esa_template_version').d(`Current esa-template version:`) +
103
130
  chalk.green(currentVersion) +
104
131
  ' ' +
@@ -110,6 +137,7 @@ export function checkAndUpdatePackage(packageName) {
110
137
  message: t('is_update_to_latest_version').d('Do you want to update templates to latest version?')
111
138
  });
112
139
  if (isUpdate) {
140
+ spinner.start(t('template_updating').d('Updating templates to latest...'));
113
141
  execSync(`rm -rf node_modules/${packageName}`, {
114
142
  cwd: packageJsonPath
115
143
  });
@@ -120,18 +148,40 @@ export function checkAndUpdatePackage(packageName) {
120
148
  cwd: packageJsonPath,
121
149
  stdio: 'inherit'
122
150
  });
123
- logger.log(t('updated_esa_template_to_latest_version', { packageName }).d(`${packageName} updated successfully`));
151
+ spinner.stop();
152
+ logger.log(`├ ${t('updated_esa_template_to_latest_version', { packageName }).d(`${packageName} updated successfully`)}`);
124
153
  }
125
154
  }
126
155
  else {
127
- logger.log(t('esa_template_is_latest_version', { packageName }).d(`${packageName} is latest.`));
156
+ spinner.stop();
157
+ logger.log(` ${t('checking_esa_template_finished').d(`Checking esa-template finished.`)}`);
158
+ t('esa_template_is_latest_version', { packageName }).d(`${packageName} is latest.`);
159
+ logger.divider();
128
160
  }
129
161
  }
130
162
  catch (error) {
131
163
  console.log(error);
132
164
  if (error instanceof Error) {
133
- logger.error('检测和更新包时发生错误,跳过更新模版');
165
+ logger.ora.fail(t('check_and_update_package_error').d('Error: An error occurred while checking and updating the package, skipping template update'));
134
166
  }
135
167
  }
136
168
  });
137
169
  }
170
+ export const getFrameworkConfig = (framework) => {
171
+ // 从init目录读取template.jsonc
172
+ const templatePath = path.join(getDirName(import.meta.url), 'template.jsonc');
173
+ const jsonc = fs.readFileSync(templatePath, 'utf-8');
174
+ const json = JSON.parse(jsonc);
175
+ return json[framework];
176
+ };
177
+ /**
178
+ * 获取框架全部配置
179
+ * @returns 框架全部配置
180
+ */
181
+ export const getAllFrameworkConfig = () => {
182
+ // 从init目录读取template.jsonc
183
+ const templatePath = path.join(getDirName(import.meta.url), 'template.jsonc');
184
+ const jsonc = fs.readFileSync(templatePath, 'utf-8');
185
+ const json = JSON.parse(jsonc);
186
+ return json;
187
+ };