@@ -9,8 +9,9 @@ import latestVersion from '@badisi/latest-version';
99import { checkPlugins } from './check-plugin' ;
1010
1111import { read } from 'read' ;
12- import { tempDir } from './constants' ;
12+ import { IS_CRESC , tempDir } from './constants' ;
1313import { depVersions } from './dep-versions' ;
14+ import { t } from './i18n' ;
1415
1516export async function question ( query : string , password ?: boolean ) {
1617 if ( NO_INTERACTIVE ) {
@@ -46,7 +47,10 @@ export async function getApkInfo(fn: string) {
4647 ) ;
4748 if ( ! bundleFile ) {
4849 throw new Error (
49- '找不到bundle文件。请确保此apk为release版本,且bundle文件名为默认的index.android.bundle' ,
50+ t ( 'bundleNotFound' , {
51+ packageType : 'apk' ,
52+ entryFile : 'index.android.bundle' ,
53+ } ) ,
5054 ) ;
5155 }
5256 const updateJsonFile = await appInfoParser . parser . getEntry (
@@ -66,21 +70,22 @@ export async function getApkInfo(fn: string) {
6670 }
6771 }
6872 if ( buildTime == 0 ) {
69- throw new Error (
70- '无法获取此包的编译时间戳。请更新 react-native-update 到最新版本后重新打包上传。' ,
71- ) ;
73+ throw new Error ( t ( 'buildTimeNotFound' ) ) ;
7274 }
7375 return { versionName, buildTime, ...appCredential } ;
7476}
7577
76- export async function getAppInfo ( fn ) {
78+ export async function getAppInfo ( fn : string ) {
7779 const appInfoParser = new AppInfoParser ( fn ) ;
7880 const bundleFile = await appInfoParser . parser . getEntryFromHarmonyApp (
7981 / r a w f i l e \/ b u n d l e .h a r m o n y .j s / ,
8082 ) ;
8183 if ( ! bundleFile ) {
8284 throw new Error (
83- '找不到bundle文件。请确保此app为release版本,且bundle文件名为默认的bundle.harmony.js' ,
85+ t ( 'bundleNotFound' , {
86+ packageType : 'app' ,
87+ entryFile : 'bundle.harmony.js' ,
88+ } ) ,
8489 ) ;
8590 }
8691 const updateJsonFile = await appInfoParser . parser . getEntryFromHarmonyApp (
@@ -103,9 +108,7 @@ export async function getAppInfo(fn) {
103108 buildTime = pushy_build_time ;
104109 }
105110 if ( buildTime == 0 ) {
106- throw new Error (
107- '无法获取此包的编译时间戳。请更新 react-native-update 到最新版本后重新打包上传。' ,
108- ) ;
111+ throw new Error ( t ( 'buildTimeNotFound' ) ) ;
109112 }
110113 return { versionName, buildTime, ...appCredential } ;
111114}
@@ -117,7 +120,10 @@ export async function getIpaInfo(fn: string) {
117120 ) ;
118121 if ( ! bundleFile ) {
119122 throw new Error (
120- '找不到bundle文件。请确保此ipa为release版本,且bundle文件名为默认的main.jsbundle' ,
123+ t ( 'bundleNotFound' , {
124+ packageType : 'ipa' ,
125+ entryFile : 'main.jsbundle' ,
126+ } ) ,
121127 ) ;
122128 }
123129 const updateJsonFile = await appInfoParser . parser . getEntry (
@@ -139,9 +145,7 @@ export async function getIpaInfo(fn: string) {
139145 ) ;
140146 }
141147 if ( ! buildTimeTxtBuffer ) {
142- throw new Error (
143- '无法获取此包的编译时间戳。请更新 react-native-update 到最新版本后重新打包上传。' ,
144- ) ;
148+ throw new Error ( t ( 'buildTimeNotFound' ) ) ;
145149 }
146150 const buildTime = buildTimeTxtBuffer . toString ( ) . replace ( '\n' , '' ) ;
147151 return { versionName, buildTime, ...appCredential } ;
@@ -168,40 +172,51 @@ async function getLatestVersion(pkgNames: string[]) {
168172}
169173
170174export async function printVersionCommand ( ) {
171- let [ latestPushyCliVersion , latestPushyVersion ] = await getLatestVersion ( [
175+ let [ latestRnuCliVersion , latestRnuVersion ] = await getLatestVersion ( [
172176 'react-native-update-cli' ,
173177 'react-native-update' ,
174178 ] ) ;
175- latestPushyCliVersion = latestPushyCliVersion
176- ? ` (最新:${ chalk . green ( latestPushyCliVersion ) } )`
179+ latestRnuCliVersion = latestRnuCliVersion
180+ ? ` ${ t ( 'latestVersionTag' , {
181+ version : chalk . green ( latestRnuCliVersion ) ,
182+ } ) } `
177183 : '' ;
178184 console . log (
179- `react-native-update-cli: ${ pkg . version } ${ latestPushyCliVersion } ` ,
185+ `react-native-update-cli: ${ pkg . version } ${ latestRnuCliVersion } ` ,
180186 ) ;
181- let pushyVersion = '' ;
182- pushyVersion = depVersions [ 'react-native-update' ] ;
183- latestPushyVersion = latestPushyVersion
184- ? ` (最新: ${ chalk . green ( latestPushyVersion ) } ) `
187+ let rnuVersion = '' ;
188+ rnuVersion = depVersions [ 'react-native-update' ] ;
189+ latestRnuVersion = latestRnuVersion
190+ ? ` ${ t ( 'latestVersionTag' , { version : chalk . green ( latestRnuVersion ) } ) } `
185191 : '' ;
186- console . log ( `react-native-update: ${ pushyVersion } ${ latestPushyVersion } ` ) ;
187- if ( pushyVersion ) {
188- if ( semverSatisfies ( pushyVersion , '<8.5.2' ) ) {
189- console . warn (
190- `当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8 .
191- 如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl` ,
192- ) ;
193- } else if ( semverSatisfies ( pushyVersion , '9.0.0 - 9.2.1' ) ) {
194- console . warn (
195- `当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动,可直接热更): npm i react-native-update@9 .
196- 如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl` ,
197- ) ;
198- } else if ( semverSatisfies ( pushyVersion , '10.0.0 - 10.17.0' ) ) {
199- console . warn (
200- '当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10' ,
201- ) ;
192+ console . log ( `react-native-update: ${ rnuVersion } ${ latestRnuVersion } ` ) ;
193+ if ( rnuVersion ) {
194+ if ( IS_CRESC ) {
195+ if ( semverSatisfies ( rnuVersion , '<10.27.0' ) ) {
196+ console . error (
197+ 'Unsupported version, please update to the latest version: npm i react-native-update@latest' ,
198+ ) ;
199+ process . exit ( 1 ) ;
200+ }
201+ } else {
202+ if ( semverSatisfies ( rnuVersion , '<8.5.2' ) ) {
203+ console . warn (
204+ `当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8 .
205+ 如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl` ,
206+ ) ;
207+ } else if ( semverSatisfies ( rnuVersion , '9.0.0 - 9.2.1' ) ) {
208+ console . warn (
209+ `当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动,可直接热更): npm i react-native-update@9 .
210+ 如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl` ,
211+ ) ;
212+ } else if ( semverSatisfies ( rnuVersion , '10.0.0 - 10.17.0' ) ) {
213+ console . warn (
214+ '当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10' ,
215+ ) ;
216+ }
202217 }
203218 } else {
204- console . log ( 'react-native-update: 无法获取版本号,请在项目目录中运行命令' ) ;
219+ console . log ( t ( 'rnuVersionNotFound' ) ) ;
205220 }
206221}
207222
0 commit comments