react-native-update-cli 2.23.1 → 2.24.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.
package/src/bin.ts CHANGED
@@ -67,11 +67,13 @@ async function run() {
67
67
  // exit on their own.
68
68
  const versionCheck = await printVersionCommand({ wait: versionOnly });
69
69
  if (versionOnly) {
70
+ versionCheck.startAutoUpdate();
70
71
  process.exit();
71
72
  }
72
73
  process.on('exit', (code) => {
73
74
  if (code === 0) {
74
75
  versionCheck.printHints();
76
+ versionCheck.startAutoUpdate();
75
77
  }
76
78
  });
77
79
 
@@ -96,6 +98,7 @@ async function run() {
96
98
  // registry request itself is unref'd, so exiting never waits on it
97
99
  await versionCheck.settle(500);
98
100
  versionCheck.printHints();
101
+ versionCheck.startAutoUpdate();
99
102
  } else {
100
103
  throw new Error(t('unknownCommand', { command: argv.command }));
101
104
  }
package/src/locales/en.ts CHANGED
@@ -35,6 +35,10 @@ export default {
35
35
  'App not selected. run `cresc selectApp --platform {{platform}}` first!',
36
36
  appUploadSuccess:
37
37
  'Successfully uploaded APP native package (id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
38
+ autoUpdatePermission:
39
+ 'CLI auto-update was skipped because the global package directory is not writable. Fix the package-manager prefix permissions, then run: {{- command}}',
40
+ autoUpdateSuccess:
41
+ 'CLI was automatically updated in the background: {{from}} -> {{to}}',
38
42
  apkUploadSuccess:
39
43
  'Successfully uploaded APK native package (id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
40
44
  boundTo: ', bound to: {{name}} ({{id}})',
package/src/locales/zh.ts CHANGED
@@ -33,6 +33,9 @@ export default {
33
33
  '尚未选择应用。请先运行 `pushy selectApp --platform {{platform}}` 来选择应用',
34
34
  appUploadSuccess:
35
35
  '已成功上传app原生包(id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
36
+ autoUpdatePermission:
37
+ 'CLI 自动更新已跳过:全局包目录不可写。请修复包管理器的全局目录权限后运行:{{- command}}',
38
+ autoUpdateSuccess: 'CLI 已在后台自动更新:{{from}} -> {{to}}',
36
39
  apkUploadSuccess:
37
40
  '已成功上传apk原生包(id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
38
41
  boundTo: ', 已绑定:{{name}} ({{id}})',
@@ -560,6 +560,8 @@ export interface VersionCheck {
560
560
  done: Promise<void>;
561
561
  /** wait for the check, but never longer than `graceMs` */
562
562
  settle: (graceMs: number) => Promise<void>;
563
+ /** launch a detached self-update after the foreground command is done */
564
+ startAutoUpdate: () => void;
563
565
  /**
564
566
  * Print the "newer version available" hints if the check has completed by
565
567
  * now; a no-op while it is still pending, when nothing is newer, and after
@@ -597,6 +599,27 @@ export async function printVersionCommand({
597
599
  console.log(
598
600
  `react-native-update-cli: ${pkg.version}${latestTag(latestCliVersion)}`,
599
601
  );
602
+ try {
603
+ const { consumeAutoUpdateNotice } =
604
+ require('../auto-update') as typeof import('../auto-update');
605
+ const notice = consumeAutoUpdateNotice(pkg.version);
606
+ if (notice?.kind === 'updated') {
607
+ console.log(
608
+ t('autoUpdateSuccess', {
609
+ from: notice.currentVersion,
610
+ to: notice.targetVersion,
611
+ }),
612
+ );
613
+ } else if (notice?.kind === 'permission') {
614
+ console.warn(
615
+ t('autoUpdatePermission', {
616
+ command: notice.command,
617
+ }),
618
+ );
619
+ }
620
+ } catch {
621
+ // A corrupt/unwritable updater cache cannot affect normal commands.
622
+ }
600
623
  if (rnuVersion) {
601
624
  console.log(
602
625
  `react-native-update: ${rnuVersion}${latestTag(latestRnuVersion)}`,
@@ -654,7 +677,22 @@ export async function printVersionCommand({
654
677
  return Promise.race([check, grace]).then(() => clearTimeout(timer));
655
678
  };
656
679
 
657
- return { done: check, settle, printHints };
680
+ let autoUpdateStarted = false;
681
+ const startAutoUpdate = () => {
682
+ if (autoUpdateStarted || !isNewer(latest?.[0], pkg.version)) {
683
+ return;
684
+ }
685
+ autoUpdateStarted = true;
686
+ try {
687
+ const { launchAutoUpdate } =
688
+ require('../auto-update') as typeof import('../auto-update');
689
+ launchAutoUpdate(pkg.version, latest?.[0]);
690
+ } catch {
691
+ // Self-update is strictly opportunistic and never affects the command.
692
+ }
693
+ };
694
+
695
+ return { done: check, settle, startAutoUpdate, printHints };
658
696
  }
659
697
 
660
698
  export { checkPlugins };