Skip to content

Commit a259ff6

Browse files
author
sunny.luo
committed
check latest version
1 parent 3f68fa0 commit a259ff6

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

bun.lockb

7.15 KB
Binary file not shown.

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update-cli",
3-
"version": "1.33.0",
3+
"version": "1.34.0",
44
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
55
"main": "index.js",
66
"bin": {
@@ -32,6 +32,7 @@
3232
},
3333
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
3434
"dependencies": {
35+
"@badisi/latest-version": "^7.0.10",
3536
"bplist-parser": "^0.3.2",
3637
"bytebuffer": "^5.0.1",
3738
"cgbi-to-png": "^1.0.7",
@@ -53,17 +54,17 @@
5354
"tty-table": "4.2",
5455
"update-notifier": "^5.1.0",
5556
"yauzl": "^3.2.0",
56-
"yazl": "3.3.0"
57+
"yazl": "3.3.1"
5758
},
5859
"engines": {
5960
"node": ">= 10"
6061
},
6162
"devDependencies": {
62-
"@swc/cli": "^0.5.0",
63-
"@swc/core": "^1.9.2",
64-
"@types/node": "^22.9.0",
65-
"oxlint": "^0.11.1",
66-
"typescript": "^5.6.3"
63+
"@swc/cli": "^0.5.1",
64+
"@swc/core": "^1.9.3",
65+
"@types/node": "^22.9.3",
66+
"oxlint": "^0.13.1",
67+
"typescript": "^5.7.2"
6768
},
68-
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
69+
"packageManager": "yarn@1.22.22"
6970
}

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const commands = {
3131
help: printUsage,
3232
};
3333

34-
function run() {
35-
printVersionCommand();
34+
async function run() {
35+
await printVersionCommand();
3636
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
3737
process.exit();
3838
}

src/utils/index.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import path from 'node:path';
44
import pkg from '../../package.json';
55
import AppInfoParser from './app-info-parser';
66
import semverSatisfies from 'semver/functions/satisfies';
7+
import chalk from 'chalk';
8+
import latestVersion from '@badisi/latest-version';
79

810
import { 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

Comments
 (0)