@@ -4,6 +4,8 @@ import path from 'node:path';
4
4
import pkg from '../../package.json' ;
5
5
import AppInfoParser from './app-info-parser' ;
6
6
import semverSatisfies from 'semver/functions/satisfies' ;
7
+ import chalk from 'chalk' ;
8
+ import latestVersion from '@badisi/latest-version' ;
7
9
8
10
import { read } from 'read' ;
9
11
@@ -131,8 +133,23 @@ export function saveToLocal(originPath, destName) {
131
133
// fs.copyFileSync(originPath, destPath);
132
134
}
133
135
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
+ ) ;
136
153
let pushyVersion = '' ;
137
154
try {
138
155
const PACKAGE_JSON_PATH = require . resolve (
@@ -142,21 +159,29 @@ export function printVersionCommand() {
142
159
} ,
143
160
) ;
144
161
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 } ` ) ;
146
167
} catch ( e ) {
147
168
console . log ( 'react-native-update: 无法获取版本号,请在项目目录中运行命令' ) ;
148
169
}
149
170
if ( pushyVersion ) {
150
- if ( semverSatisfies ( pushyVersion , '<8.5.1 ' ) ) {
171
+ if ( semverSatisfies ( pushyVersion , '<8.5.2 ' ) ) {
151
172
console . warn (
152
173
`当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8 .
153
174
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl` ,
154
175
) ;
155
- } else if ( semverSatisfies ( pushyVersion , '9.0.0 - 9.2.0 ' ) ) {
176
+ } else if ( semverSatisfies ( pushyVersion , '9.0.0 - 9.2.1 ' ) ) {
156
177
console . warn (
157
- `当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动): npm i react-native-update@9 .
178
+ `当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动,可直接热更 ): npm i react-native-update@9 .
158
179
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl` ,
159
180
) ;
181
+ } else if ( semverSatisfies ( pushyVersion , '10.0.0 - 10.15.2' ) ) {
182
+ console . warn (
183
+ `当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10` ,
184
+ ) ;
160
185
}
161
186
}
162
187
}
0 commit comments