@@ -4,6 +4,8 @@ import path from 'node:path';
44import pkg from '../../package.json' ;
55import AppInfoParser from './app-info-parser' ;
66import semverSatisfies from 'semver/functions/satisfies' ;
7+ import chalk from 'chalk' ;
8+ import latestVersion from '@badisi/latest-version' ;
79
810import { read } from 'read' ;
911
@@ -131,8 +133,23 @@ export function saveToLocal(originPath, destName) {
131133 // fs.copyFileSync(originPath, destPath);
132134}
133135
134- export function printVersionCommand ( ) {
135- console . log ( 'react-native-update-cli: ' + pkg . version ) ;
136+ async function getLatestVersion ( pkgName ) {
137+ return Promise . race ( [
138+ latestVersion ( pkgName )
139+ . then ( ( p ) => p . latest )
140+ . catch ( ( ) => '' ) ,
141+ new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( '' ) , 2000 ) ) ,
142+ ] ) ;
143+ }
144+
145+ export async function printVersionCommand ( ) {
146+ let latestPushyCliVersion = await getLatestVersion ( 'react-native-update-cli' ) ;
147+ latestPushyCliVersion = latestPushyCliVersion
148+ ? ` (最新:${ chalk . green ( latestPushyCliVersion ) } )`
149+ : '' ;
150+ console . log (
151+ `react-native-update-cli: ${ pkg . version } ${ latestPushyCliVersion } ` ,
152+ ) ;
136153 let pushyVersion = '' ;
137154 try {
138155 const PACKAGE_JSON_PATH = require . resolve (
@@ -142,21 +159,29 @@ export function printVersionCommand() {
142159 } ,
143160 ) ;
144161 pushyVersion = require ( PACKAGE_JSON_PATH ) . version ;
145- console . log ( 'react-native-update: ' + pushyVersion ) ;
162+ let latestPushyVersion = await getLatestVersion ( 'react-native-update' ) ;
163+ latestPushyVersion = latestPushyVersion
164+ ? ` (最新:${ chalk . green ( latestPushyVersion ) } )`
165+ : '' ;
166+ console . log ( `react-native-update: ${ pushyVersion } ${ latestPushyVersion } ` ) ;
146167 } catch ( e ) {
147168 console . log ( 'react-native-update: 无法获取版本号,请在项目目录中运行命令' ) ;
148169 }
149170 if ( pushyVersion ) {
150- if ( semverSatisfies ( pushyVersion , '<8.5.1 ' ) ) {
171+ if ( semverSatisfies ( pushyVersion , '<8.5.2 ' ) ) {
151172 console . warn (
152173 `当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8 .
153174 如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl` ,
154175 ) ;
155- } else if ( semverSatisfies ( pushyVersion , '9.0.0 - 9.2.0 ' ) ) {
176+ } else if ( semverSatisfies ( pushyVersion , '9.0.0 - 9.2.1 ' ) ) {
156177 console . warn (
157- `当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动): npm i react-native-update@9 .
178+ `当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动,可直接热更 ): npm i react-native-update@9 .
158179 如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl` ,
159180 ) ;
181+ } else if ( semverSatisfies ( pushyVersion , '10.0.0 - 10.15.2' ) ) {
182+ console . warn (
183+ `当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10` ,
184+ ) ;
160185 }
161186 }
162187}
0 commit comments