esa-cli 1.0.8-beta.3 β†’ 1.0.8

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.
@@ -389,57 +389,46 @@ export function waitForCodeVersionReady(name_1, codeVersion_1, env_1) {
389
389
  */
390
390
  export function displayDeploySuccess(projectName_1) {
391
391
  return __awaiter(this, arguments, void 0, function* (projectName, showDomainGuide = true, showRouteGuide = true) {
392
- var _a;
392
+ var _a, _b;
393
393
  const service = yield ApiService.getInstance();
394
394
  const res = yield service.getRoutine({ Name: projectName });
395
395
  const defaultUrl = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.DefaultRelatedRecord;
396
- const visitUrl = defaultUrl ? 'https://' + defaultUrl : '';
397
- const accent = chalk.hex('#7C3AED');
396
+ let visitUrl = defaultUrl ? 'https://' + defaultUrl : '';
397
+ // Get access token for the visit URL
398
+ let hasToken = false;
399
+ if (visitUrl) {
400
+ const tokenRes = yield service.getRoutineAccessToken({
401
+ Name: projectName
402
+ });
403
+ const token = (_b = tokenRes === null || tokenRes === void 0 ? void 0 : tokenRes.data) === null || _b === void 0 ? void 0 : _b.Token;
404
+ if (token) {
405
+ visitUrl += `?esa_er_token=${token}`;
406
+ hasToken = true;
407
+ }
408
+ }
398
409
  const label = chalk.hex('#22c55e');
399
410
  const subtle = chalk.gray;
400
- const title = `${chalk.bold('πŸš€ ')}${chalk.bold(t('init_deploy_success').d('Deploy Success'))}`;
401
- const lineUrl = `${label('URL')} ${visitUrl ? chalk.yellowBright(visitUrl) : subtle('-')}`;
402
- const lineProject = `${label('APP')} ${chalk.cyan(projectName || '-')}`;
403
- const lineCd = projectName
404
- ? `${label('TIP')} ${t('deploy_success_cd').d('Enter project directory')}: ${chalk.green(`cd ${projectName}`)}`
405
- : '';
406
- const guides = [];
411
+ const orange = chalk.hex('#FFA500');
412
+ logger.block();
413
+ logger.log(`${chalk.bold('πŸš€')} ${chalk.hex('#7C3AED').bold(t('init_deploy_success').d('Deploy Success'))}`);
414
+ logger.block();
415
+ logger.log(`${label('APP')} ${chalk.cyan(projectName || '-')}`);
416
+ if (hasToken) {
417
+ logger.log(orange(`⏰ ${t('token_validity_tip').d('Token is valid for 1 hour')}`));
418
+ }
419
+ logger.log(`${label('URL')} ${visitUrl ? chalk.yellowBright(visitUrl) : subtle('-')}`);
420
+ if (projectName) {
421
+ logger.block();
422
+ logger.log(`${label('TIP')} ${t('deploy_success_cd').d('Enter project directory')}: ${chalk.green(`cd ${projectName}`)}`);
423
+ }
407
424
  if (showDomainGuide) {
408
- guides.push(`${label('TIP')} ${t('deploy_success_guide').d('Add a custom domain')}: ${chalk.green('esa-cli domain add <DOMAIN>')}`);
425
+ logger.log(`${label('TIP')} ${t('deploy_success_guide').d('Add a custom domain')}: ${chalk.green('esa-cli domain add <DOMAIN>')}`);
409
426
  }
410
427
  if (showRouteGuide) {
411
- guides.push(`${label('TIP')} ${t('deploy_success_guide_2').d('Add routes for a site')}: ${chalk.green('esa-cli route add -r <ROUTE> -s <SITE>')}`);
428
+ logger.log(`${label('TIP')} ${t('deploy_success_guide_2').d('Add routes for a site')}: ${chalk.green('esa-cli route add -r <ROUTE> -s <SITE>')}`);
412
429
  }
413
- const tip = `${subtle(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'))}`;
414
- const lines = [
415
- accent(title),
416
- '',
417
- lineProject,
418
- lineUrl,
419
- lineCd ? '' : '',
420
- lineCd || '',
421
- guides.length ? '' : '',
422
- ...guides,
423
- guides.length ? '' : '',
424
- tip
425
- ];
426
- const stripAnsi = (s) => s.replace(/\x1B\[[0-?]*[ -\/]*[@-~]/g, '');
427
- const contentWidth = Math.max(...lines.map((l) => stripAnsi(l).length));
428
- const borderColor = chalk.hex('#00D4FF').bold;
429
- const top = `${borderColor('β•”')}${borderColor('═'.repeat(contentWidth + 2))}${borderColor('β•—')}`;
430
- const bottom = `${borderColor('β•š')}${borderColor('═'.repeat(contentWidth + 2))}${borderColor('╝')}`;
431
- const boxLines = [
432
- top,
433
- ...lines.map((l) => {
434
- const pad = ' '.repeat(contentWidth - stripAnsi(l).length);
435
- const left = borderColor('β•‘');
436
- const right = borderColor('β•‘');
437
- return `${left} ${l}${pad} ${right}`;
438
- }),
439
- bottom
440
- ];
441
430
  logger.block();
442
- boxLines.forEach((l) => logger.log(l));
431
+ logger.log(subtle(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.')));
443
432
  logger.block();
444
433
  });
445
434
  }
@@ -1322,5 +1322,17 @@
1322
1322
  "login_get_credentials_from_environment_variables": {
1323
1323
  "en": "Get credentials from environment variables",
1324
1324
  "zh_CN": ""
1325
+ },
1326
+ "main_skip_update_check": {
1327
+ "en": "Skip CLI version update check",
1328
+ "zh_CN": ""
1329
+ },
1330
+ "deploy_visit_url": {
1331
+ "en": "Visit URL (with token)",
1332
+ "zh_CN": ""
1333
+ },
1334
+ "token_validity_tip": {
1335
+ "en": "Token is valid for 1 hour",
1336
+ "zh_CN": "θ―₯ URL ζœ‰ζ•ˆζœŸδΈΊ 1 小既"
1325
1337
  }
1326
1338
  }
package/dist/index.js CHANGED
@@ -44,6 +44,9 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
44
44
  if (argv.debug) {
45
45
  logger.setLogLevel('debug');
46
46
  }
47
+ if (argv.skipUpdateCheck) {
48
+ return;
49
+ }
47
50
  try {
48
51
  // Pass current command (first positional) so version check can decide prompting behavior
49
52
  yield checkCLIVersion((argv._ && argv._[0] ? String(argv._[0]) : ''));
@@ -66,6 +69,11 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
66
69
  describe: t('dev_option_debugger').d('Output debug logs'),
67
70
  type: 'boolean',
68
71
  default: false
72
+ })
73
+ .options('skip-update-check', {
74
+ describe: t('main_skip_update_check').d('Skip CLI version update check'),
75
+ type: 'boolean',
76
+ default: false
69
77
  });
70
78
  esa.command('*', false, () => { }, (args) => {
71
79
  if (args._.length > 0) {
@@ -1100,5 +1100,51 @@ export class ApiService {
1100
1100
  return null;
1101
1101
  });
1102
1102
  }
1103
+ getRoutineAccessToken(requestParams) {
1104
+ return __awaiter(this, void 0, void 0, function* () {
1105
+ try {
1106
+ let params = {
1107
+ action: 'GetRoutineAccessToken',
1108
+ version: '2024-09-10',
1109
+ protocol: 'https',
1110
+ method: 'GET',
1111
+ authType: 'AK',
1112
+ bodyType: 'json',
1113
+ reqBodyType: 'json',
1114
+ style: 'RPC',
1115
+ pathname: '/',
1116
+ toMap: function () {
1117
+ return this;
1118
+ }
1119
+ };
1120
+ let request = new $OpenApi.OpenApiRequest({
1121
+ query: {
1122
+ Name: requestParams.Name
1123
+ }
1124
+ });
1125
+ let runtime = {
1126
+ toMap: function () {
1127
+ return this;
1128
+ }
1129
+ };
1130
+ const res = yield this.client.callApi(params, request, runtime);
1131
+ if (res.statusCode === 200 && res.body) {
1132
+ const ret = {
1133
+ code: res.statusCode.toString(),
1134
+ data: {
1135
+ RequestId: res.body.RequestId,
1136
+ Token: res.body.Token,
1137
+ DefaultRelatedRecord: res.body.DefaultRelatedRecord
1138
+ }
1139
+ };
1140
+ return ret;
1141
+ }
1142
+ }
1143
+ catch (error) {
1144
+ // Token retrieval failure is non-critical, silently return null
1145
+ }
1146
+ return null;
1147
+ });
1148
+ }
1103
1149
  }
1104
1150
  ApiService.instance = null;
@@ -49,7 +49,7 @@ export function checkCLIVersion(currentCommand) {
49
49
  const fetchTimeout = setTimeout(() => controller.abort(), 5000);
50
50
  let response;
51
51
  try {
52
- response = yield fetch('https://registry.npmjs.org/esa-cli/latest', {
52
+ response = yield fetch('https://registry.npmmirror.com/esa-cli/latest', {
53
53
  signal: controller.signal
54
54
  });
55
55
  }
@@ -16,6 +16,14 @@ import logger from '../../libs/logger.js';
16
16
  import { getDirName, getRoot } from './base.js';
17
17
  const __dirname = getDirName(import.meta.url);
18
18
  const root = getRoot();
19
+ /**
20
+ * Strip JSONC content (comments + trailing commas) to make it valid JSON
21
+ */
22
+ function stripJsonc(content) {
23
+ return content
24
+ .replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '')
25
+ .replace(/,\s*([}\]])/g, '$1');
26
+ }
19
27
  // Function to get the actual project config file path (supports both .jsonc and .toml)
20
28
  export const getProjectConfigPath = (filePath = root) => {
21
29
  const configFormats = ['esa.jsonc', 'esa.toml'];
@@ -72,7 +80,7 @@ export function updateProjectConfigFile(configUpdate_1) {
72
80
  // Detect file format based on file extension
73
81
  if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
74
82
  // Handle JSONC format
75
- const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
83
+ const jsonContent = stripJsonc(configFileContent);
76
84
  config = JSON.parse(jsonContent);
77
85
  config = Object.assign(Object.assign({}, config), configUpdate);
78
86
  updatedConfigString = JSON.stringify(config, null, 2) + '\n';
@@ -101,7 +109,7 @@ export function updateCliConfigFile(configUpdate) {
101
109
  // Detect file format based on file extension
102
110
  if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
103
111
  // Handle JSONC format
104
- const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
112
+ const jsonContent = stripJsonc(configFileContent);
105
113
  config = JSON.parse(jsonContent);
106
114
  config = Object.assign(Object.assign({}, config), configUpdate);
107
115
  updatedConfigString = JSON.stringify(config, null, 2) + '\n';
@@ -126,8 +134,8 @@ export function readConfigFile(configPath) {
126
134
  const configFileContent = fs.readFileSync(configPath, 'utf-8');
127
135
  try {
128
136
  if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
129
- // Remove comments for JSON parsing
130
- const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
137
+ // Remove comments and trailing commas for JSON parsing
138
+ const jsonContent = stripJsonc(configFileContent);
131
139
  const config = JSON.parse(jsonContent);
132
140
  return config;
133
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "1.0.8-beta.3",
3
+ "version": "1.0.8",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA Functions and Pages.",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",