esa-cli 0.0.2-beta.14 → 0.0.2-beta.16

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.
@@ -8,9 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { exit } from 'process';
11
- import { descriptionInput } from '../../components/descriptionInput.js';
12
11
  import t from '../../i18n/index.js';
13
- import { validateAndInitializeProject, generateCodeVersion } from '../common/routineUtils.js';
12
+ import { validateAndInitializeProject, generateCodeVersion } from '../common/utils.js';
13
+ import { intro, outro } from '@clack/prompts';
14
+ import promptParameter from '../../utils/prompt.js';
15
+ import logger from '../../libs/logger.js';
16
+ import chalk from 'chalk';
14
17
  const commit = {
15
18
  command: 'commit [entry]',
16
19
  describe: `📥 ${t('commit_describe').d('Commit your code, save as a new version')}`,
@@ -46,6 +49,8 @@ const commit = {
46
49
  export default commit;
47
50
  export function handleCommit(argv) {
48
51
  return __awaiter(this, void 0, void 0, function* () {
52
+ var _a, _b;
53
+ intro(`Commit an application with ESA`);
49
54
  const projectInfo = yield validateAndInitializeProject(argv === null || argv === void 0 ? void 0 : argv.name);
50
55
  if (!projectInfo)
51
56
  return;
@@ -55,8 +60,21 @@ export function handleCommit(argv) {
55
60
  description = argv.description;
56
61
  }
57
62
  else {
58
- description = yield descriptionInput(`🖊️ ${t('commit_version_description').d('Enter a description for the version')}:`, false);
63
+ description = (yield promptParameter({
64
+ type: 'text',
65
+ question: t('commit_version_description').d('Enter a description for the version'),
66
+ label: 'Description',
67
+ defaultValue: ''
68
+ }));
59
69
  }
60
- yield generateCodeVersion(projectName, description, argv === null || argv === void 0 ? void 0 : argv.entry, argv === null || argv === void 0 ? void 0 : argv.assets, argv === null || argv === void 0 ? void 0 : argv.minify);
70
+ logger.startSubStep('Generating code version');
71
+ const res = yield generateCodeVersion(projectName, description, argv === null || argv === void 0 ? void 0 : argv.entry, argv === null || argv === void 0 ? void 0 : argv.assets, argv === null || argv === void 0 ? void 0 : argv.minify);
72
+ const codeVersion = (_b = (_a = res === null || res === void 0 ? void 0 : res.res) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.CodeVersion;
73
+ if (!codeVersion) {
74
+ logger.endSubStep('Missing CodeVersion in response');
75
+ return false;
76
+ }
77
+ logger.endSubStep(`Version generated: ${codeVersion}`);
78
+ outro(`Code version ${chalk.bold(codeVersion)} generated successfully`);
61
79
  });
62
80
  }
@@ -11,11 +11,20 @@ import chalk from 'chalk';
11
11
  import t from '../../i18n/index.js';
12
12
  import { ApiService } from '../../libs/apiService.js';
13
13
  import logger from '../../libs/logger.js';
14
- import { ensureRoutineExists } from '../../utils/checkIsRoutineCreated.js';
15
14
  import compress from '../../utils/compress.js';
16
15
  import { getProjectConfig } from '../../utils/fileUtils/index.js';
17
16
  import sleep from '../../utils/sleep.js';
17
+ import { ensureRoutineExists } from '../../utils/checkIsRoutineCreated.js';
18
18
  import { checkIsLoginSuccess } from '../utils.js';
19
+ function normalizeNotFoundStrategy(value) {
20
+ if (!value)
21
+ return undefined;
22
+ const lower = value.toLowerCase();
23
+ if (lower === 'singlepageapplication') {
24
+ return 'SinglePageApplication';
25
+ }
26
+ return value;
27
+ }
19
28
  export function commitRoutineWithAssets(requestParams, zipBuffer) {
20
29
  return __awaiter(this, void 0, void 0, function* () {
21
30
  try {
@@ -71,18 +80,21 @@ export function commitRoutineWithAssets(requestParams, zipBuffer) {
71
80
  * 通用的项目验证和初始化函数
72
81
  * 包含目录检查、项目配置获取、登录检查、routine存在性检查
73
82
  */
74
- export function validateAndInitializeProject(name) {
83
+ export function validateAndInitializeProject(name, projectPath) {
75
84
  return __awaiter(this, void 0, void 0, function* () {
76
- const projectConfig = getProjectConfig();
85
+ const projectConfig = getProjectConfig(projectPath);
77
86
  if (!projectConfig) {
78
87
  logger.notInProject();
79
88
  return null;
80
89
  }
81
90
  const projectName = name || projectConfig.name;
91
+ logger.startSubStep('Checking login status abc');
82
92
  const isSuccess = yield checkIsLoginSuccess();
83
93
  if (!isSuccess) {
94
+ logger.endSubStep('You are not logged in');
84
95
  return null;
85
96
  }
97
+ logger.endSubStep('Logged in');
86
98
  yield ensureRoutineExists(projectName);
87
99
  return { projectConfig, projectName };
88
100
  });
@@ -103,20 +115,28 @@ export function getRoutineDetails(projectName) {
103
115
  */
104
116
  export function generateCodeVersion(projectName_1, description_1, entry_1, assets_1) {
105
117
  return __awaiter(this, arguments, void 0, function* (projectName, description, entry, assets, minify = false, projectPath) {
118
+ var _a;
106
119
  const zip = yield compress(entry, assets, minify, projectPath);
107
- const res = yield commitRoutineWithAssets({
120
+ const projectConfig = getProjectConfig(projectPath);
121
+ const notFoundStrategy = normalizeNotFoundStrategy((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.notFoundStrategy);
122
+ const requestParams = {
108
123
  Name: projectName,
109
- CodeDescription: description
110
- }, zip === null || zip === void 0 ? void 0 : zip.toBuffer());
124
+ CodeDescription: description,
125
+ ExtraInfo: JSON.stringify({ Source: 'CLI' })
126
+ };
127
+ if (notFoundStrategy) {
128
+ requestParams.ConfOptions = {
129
+ NotFoundStrategy: notFoundStrategy
130
+ };
131
+ }
132
+ const res = yield commitRoutineWithAssets(requestParams, zip === null || zip === void 0 ? void 0 : zip.toBuffer());
111
133
  if (res === null || res === void 0 ? void 0 : res.isSuccess) {
112
- logger.success('Your code has been successfully committed');
113
134
  return {
114
135
  isSuccess: true,
115
136
  res: res === null || res === void 0 ? void 0 : res.res
116
137
  };
117
138
  }
118
139
  else {
119
- logger.error('Generate code version failed');
120
140
  return {
121
141
  isSuccess: false,
122
142
  res: null
@@ -141,27 +161,37 @@ export function deployToEnvironments(name, codeVersion, env) {
141
161
  * 通用的快速部署函数
142
162
  * 结合了压缩、提交和部署的完整流程
143
163
  */
144
- export function commitAndDeployVersion(projectConfig_1, scriptEntry_1, assets_1) {
145
- return __awaiter(this, arguments, void 0, function* (projectConfig, scriptEntry, assets, description = '', projectPath, env = 'production', minify = false, version) {
164
+ export function commitAndDeployVersion(projectName_1, scriptEntry_1, assets_1) {
165
+ return __awaiter(this, arguments, void 0, function* (projectName, scriptEntry, assets, description = '', projectPath, env = 'production', minify = false, version) {
146
166
  var _a, _b, _c;
167
+ const projectInfo = yield validateAndInitializeProject(projectName, projectPath);
168
+ if (!projectInfo || !projectInfo.projectConfig) {
169
+ return false;
170
+ }
171
+ const { projectConfig } = projectInfo;
172
+ // 2) Use existing version or generate a new one
147
173
  if (version) {
148
- return yield deployToEnvironments(projectConfig.name, version, env);
174
+ logger.startSubStep(`Using existing version ${version}`);
175
+ const deployed = yield deployToEnvironments(projectConfig.name, version, env);
176
+ logger.endSubStep(deployed ? 'Deploy finished' : 'Deploy failed');
177
+ return deployed;
149
178
  }
150
- else {
151
- const res = yield generateCodeVersion(projectConfig.name, description, scriptEntry || projectConfig.entry, assets || ((_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory), minify || projectConfig.minify, projectPath);
152
- const isCommitSuccess = res === null || res === void 0 ? void 0 : res.isSuccess;
153
- if (isCommitSuccess) {
154
- const codeVersion = (_c = (_b = res === null || res === void 0 ? void 0 : res.res) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.CodeVersion;
155
- if (!codeVersion) {
156
- logger.error('Failed to read CodeVersion from response.');
157
- return false;
158
- }
159
- return yield deployToEnvironments(projectConfig.name, codeVersion, env);
160
- }
161
- else {
162
- return false;
163
- }
179
+ logger.startSubStep('Generating code version');
180
+ const res = yield generateCodeVersion(projectConfig.name, description, scriptEntry || projectConfig.entry, assets || ((_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory), minify || projectConfig.minify, projectPath);
181
+ const isCommitSuccess = res === null || res === void 0 ? void 0 : res.isSuccess;
182
+ if (!isCommitSuccess) {
183
+ logger.endSubStep('Generate version failed');
184
+ return false;
185
+ }
186
+ const codeVersion = (_c = (_b = res === null || res === void 0 ? void 0 : res.res) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.CodeVersion;
187
+ if (!codeVersion) {
188
+ logger.endSubStep('Missing CodeVersion in response');
189
+ return false;
164
190
  }
191
+ logger.endSubStep(`Version generated: ${codeVersion}`);
192
+ // 3) Deploy to specified environment(s)
193
+ const deployed = yield deployToEnvironments(projectConfig.name, codeVersion, env);
194
+ return deployed;
165
195
  });
166
196
  }
167
197
  /**
@@ -171,7 +201,7 @@ export function deployCodeVersion(name, codeVersion, environment) {
171
201
  return __awaiter(this, void 0, void 0, function* () {
172
202
  const server = yield ApiService.getInstance();
173
203
  // Ensure the committed code version is ready before deploying
174
- const isReady = yield waitForCodeVersionReady(name, codeVersion);
204
+ const isReady = yield waitForCodeVersionReady(name, codeVersion, environment);
175
205
  if (!isReady) {
176
206
  logger.error('The code version is not ready for deployment.');
177
207
  return false;
@@ -183,11 +213,9 @@ export function deployCodeVersion(name, codeVersion, environment) {
183
213
  Env: environment
184
214
  });
185
215
  if (res) {
186
- logger.success(`Your code has been successfully deployed to ${chalk.cyan(environment)}`);
187
216
  return true;
188
217
  }
189
218
  else {
190
- logger.error('Your code has not been deployed');
191
219
  return false;
192
220
  }
193
221
  });
@@ -195,15 +223,15 @@ export function deployCodeVersion(name, codeVersion, environment) {
195
223
  /**
196
224
  * Poll routine code version status until it becomes ready
197
225
  */
198
- export function waitForCodeVersionReady(name_1, codeVersion_1) {
199
- return __awaiter(this, arguments, void 0, function* (name, codeVersion, timeoutMs = 5 * 60 * 1000, intervalMs = 1000) {
226
+ export function waitForCodeVersionReady(name_1, codeVersion_1, env_1) {
227
+ return __awaiter(this, arguments, void 0, function* (name, codeVersion, env, timeoutMs = 5 * 60 * 1000, intervalMs = 1000) {
200
228
  var _a, _b;
201
229
  if (!name || !codeVersion) {
202
230
  return false;
203
231
  }
204
232
  const server = yield ApiService.getInstance();
205
233
  const start = Date.now();
206
- logger.log(`⏳ Waiting for code version ${chalk.cyan(codeVersion)} to be ready...`);
234
+ logger.startSubStep(`Waiting for code version ${codeVersion} to be ready...`);
207
235
  while (Date.now() - start < timeoutMs) {
208
236
  try {
209
237
  const info = yield server.getRoutineCodeVersionInfo({
@@ -216,7 +244,7 @@ export function waitForCodeVersionReady(name_1, codeVersion_1) {
216
244
  continue;
217
245
  }
218
246
  else if (status === 'available') {
219
- logger.log(`✅ Code version ${chalk.cyan(codeVersion)} is ready.`);
247
+ logger.endSubStep(`Code version ${chalk.cyan(codeVersion)} is deployed to ${env}.`);
220
248
  return true;
221
249
  }
222
250
  else {
@@ -226,7 +254,6 @@ export function waitForCodeVersionReady(name_1, codeVersion_1) {
226
254
  }
227
255
  catch (e) {
228
256
  // swallow and retry until timeout
229
- console.log(e);
230
257
  }
231
258
  }
232
259
  logger.error(`⏰ Waiting for code version ${chalk.cyan(codeVersion)} timed out.`);
@@ -243,34 +270,53 @@ export function displayDeploySuccess(projectName_1) {
243
270
  const service = yield ApiService.getInstance();
244
271
  const res = yield service.getRoutine({ Name: projectName });
245
272
  const defaultUrl = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.DefaultRelatedRecord;
246
- const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
273
+ const visitUrl = defaultUrl ? 'https://' + defaultUrl : '';
274
+ const accent = chalk.hex('#7C3AED');
275
+ const label = chalk.hex('#22c55e');
276
+ const subtle = chalk.gray;
277
+ const title = `${chalk.bold('🚀 ')}${chalk.bold(t('init_deploy_success').d('Deploy Success'))}`;
278
+ const lineUrl = `${label('URL')} ${visitUrl ? chalk.yellowBright(visitUrl) : subtle('-')}`;
279
+ const lineProject = `${label('APP')} ${chalk.cyan(projectName || '-')}`;
280
+ const lineCd = projectName
281
+ ? `${label('TIP')} ${t('deploy_success_cd').d('Enter project directory')}: ${chalk.green(`cd ${projectName}`)}`
282
+ : '';
283
+ const guides = [];
247
284
  if (showDomainGuide) {
248
- logger.log(`👉 ${t('deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
285
+ guides.push(`${label('TIP')} ${t('deploy_success_guide').d('Add a custom domain')}: ${chalk.green('esa domain add <DOMAIN>')}`);
249
286
  }
250
287
  if (showRouteGuide) {
251
- logger.log(`👉 ${t('deploy_success_guide_2').d('Run this command to add routes')}: ${chalk.green('esa route add -r <ROUTE> -s <SITE>')}`);
252
- }
253
- logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
254
- logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
255
- });
256
- }
257
- /**
258
- * 通用的快速部署函数(用于init命令)
259
- * 结合了登录检查、routine创建、代码提交和部署的完整流程
260
- */
261
- export function quickDeployForInit(targetPath_1, projectConfig_1) {
262
- return __awaiter(this, arguments, void 0, function* (targetPath, projectConfig, description = 'Quick deploy from init') {
263
- var _a, _b;
264
- const isLoginSuccess = yield checkIsLoginSuccess();
265
- if (!isLoginSuccess) {
266
- logger.log(chalk.yellow(t('not_login_auto_deploy').d('You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.')));
267
- return false;
268
- }
269
- yield ensureRoutineExists(projectConfig.name);
270
- const isProdSuccess = yield commitAndDeployVersion(projectConfig, projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry, (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory, description, targetPath, 'all');
271
- if (isProdSuccess) {
272
- yield displayDeploySuccess((_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '');
288
+ guides.push(`${label('TIP')} ${t('deploy_success_guide_2').d('Add routes for a site')}: ${chalk.green('esa route add -r <ROUTE> -s <SITE>')}`);
273
289
  }
274
- return isProdSuccess;
290
+ const tip = `${subtle(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'))}`;
291
+ const lines = [
292
+ accent(title),
293
+ '',
294
+ lineProject,
295
+ lineUrl,
296
+ lineCd ? '' : '',
297
+ lineCd || '',
298
+ guides.length ? '' : '',
299
+ ...guides,
300
+ guides.length ? '' : '',
301
+ tip
302
+ ];
303
+ const stripAnsi = (s) => s.replace(/\x1B\[[0-?]*[ -\/]*[@-~]/g, '');
304
+ const contentWidth = Math.max(...lines.map((l) => stripAnsi(l).length));
305
+ const borderColor = chalk.hex('#00D4FF').bold;
306
+ const top = `${borderColor('╔')}${borderColor('═'.repeat(contentWidth + 2))}${borderColor('╗')}`;
307
+ const bottom = `${borderColor('╚')}${borderColor('═'.repeat(contentWidth + 2))}${borderColor('╝')}`;
308
+ const boxLines = [
309
+ top,
310
+ ...lines.map((l) => {
311
+ const pad = ' '.repeat(contentWidth - stripAnsi(l).length);
312
+ const left = borderColor('║');
313
+ const right = borderColor('║');
314
+ return `${left} ${l}${pad} ${right}`;
315
+ }),
316
+ bottom
317
+ ];
318
+ logger.block();
319
+ boxLines.forEach((l) => logger.log(l));
320
+ logger.block();
275
321
  });
276
322
  }
@@ -9,7 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { exit } from 'process';
11
11
  import t from '../../i18n/index.js';
12
- import { validateAndInitializeProject, commitAndDeployVersion, displayDeploySuccess } from '../common/routineUtils.js';
12
+ import { getRoot } from '../../utils/fileUtils/base.js';
13
+ import { commitAndDeployVersion, displayDeploySuccess } from '../common/utils.js';
14
+ import { intro, outro } from '@clack/prompts';
15
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
13
16
  const deploy = {
14
17
  command: 'deploy [entry]',
15
18
  builder: (yargs) => {
@@ -64,58 +67,15 @@ const deploy = {
64
67
  };
65
68
  export function handleDeploy(argv) {
66
69
  return __awaiter(this, void 0, void 0, function* () {
67
- var _a;
68
- const projectInfo = yield validateAndInitializeProject(argv === null || argv === void 0 ? void 0 : argv.name);
69
- if (!projectInfo)
70
- return;
71
- const { projectConfig, projectName } = projectInfo;
72
- const entry = argv.entry || projectConfig.entry;
73
- const assets = argv.assets || ((_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory);
74
- const success = yield commitAndDeployVersion(projectConfig, entry, assets, argv.description || '', undefined, argv.environment, argv.minify, argv.version);
70
+ const entry = argv.entry;
71
+ const assets = argv.assets;
72
+ intro(`Deploy an application with ESA`);
73
+ const success = yield commitAndDeployVersion(argv.name || undefined, entry, assets, argv.description || '', getRoot(), argv.environment || 'all', argv.minify, argv.version);
74
+ outro(success ? 'Deploy finished' : 'Deploy failed');
75
75
  if (success) {
76
- yield displayDeploySuccess(projectName, true, false);
76
+ const projectConfig = getProjectConfig(getRoot());
77
+ yield displayDeploySuccess(argv.name || (projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) || '', true, true);
77
78
  }
78
- // if (allVersions.length === 0) {
79
- // logger.log(
80
- // t('no_formal_version_found').d(
81
- // 'No formal version found, you need to create a version first.'
82
- // )
83
- // );
84
- // const commitRes = await generateCodeVersion(projectName, '', entry, assets);
85
- // if (!commitRes?.isSuccess) {
86
- // exit(0);
87
- // }
88
- // }
89
- // const {
90
- // allVersions: committedVersionList,
91
- // stagingVersions,
92
- // productionVersions
93
- // } = await getRoutineCodeVersions(projectName);
94
- // await displayVersionList(
95
- // committedVersionList,
96
- // stagingVersions,
97
- // productionVersions
98
- // );
99
- // const selectedVersion =
100
- // (argv.version as string) ||
101
- // (await promptSelectVersion(committedVersionList));
102
- // const selectedEnvironment =
103
- // (argv.environment as string) || (await displaySelectDeployEnv());
104
- // if (
105
- // selectedEnvironment !== PublishType.Staging &&
106
- // selectedEnvironment !== PublishType.Production
107
- // ) {
108
- // logger.error(t('deploy_invalid_environment').d('Invalid environment'));
109
- // exit(0);
110
- // }
111
- // const success = await deployCodeVersion(
112
- // projectName,
113
- // selectedVersion,
114
- // selectedEnvironment as PublishType
115
- // );
116
- // if (success) {
117
- // await displayDeploySuccess(projectName, true, true);
118
- // }
119
79
  });
120
80
  }
121
81
  export default deploy;