@@ -2,12 +2,14 @@ import https from "https";
2
2
import { rootPath } from "#common/utils/file/getRootPath.js" ;
3
3
import fs from "fs" ;
4
4
import path from "path" ;
5
- import { GITHUB_HOST , GITHUB_RAW , NPM_URL , PackageName } from "#common/constants/question.const.js" ;
5
+ import { GITEE_URL , GITHUB_HOST , GITHUB_RAW , NPM_URL , PackageName } from "#common/constants/question.const.js" ;
6
6
import { url_join } from "#common/utils/http/urlJoin.js" ;
7
7
import { fetch_ } from "#common/utils/http/fetch_.js" ;
8
8
// npm 中的 包地址
9
9
const npmUrl = url_join ( NPM_URL , PackageName ) ;
10
10
const githubUrl = url_join ( GITHUB_RAW , GITHUB_HOST , PackageName , "master/package.json" ) ;
11
+ const giteeUrl = url_join ( GITEE_URL , GITHUB_HOST , PackageName , 'raw' , "master/package.json" ) ;
12
+
11
13
/**
12
14
* 获取远端npm库中的版本号
13
15
*/
@@ -28,20 +30,20 @@ export const getNpmVersion = async ()=>{
28
30
*/
29
31
export const getGithubVersion = async ( ) => {
30
32
try {
31
- const res = await fetch_ ( githubUrl , { method :"GET" } ) ;
32
- console . log ( "获取Github版本成功!======" , res ?. version )
33
- return res ?. version ;
33
+ const [ { reason :_1 , value :github } , { reason :_2 , value :gitee } ] = await Promise . allSettled ( [ fetch_ ( githubUrl , { method :"GET" } ) , fetch_ ( giteeUrl , { method :"GET" } ) ] ) ;
34
+ const ver = github ?. [ 'version' ] ?? gitee ?. [ 'version' ] ;
35
+ console . log ( "获取Github版本成功!======" , ver ) ;
36
+ return ver ;
34
37
}
35
38
catch ( e ) {
36
39
console . log ( "获取Github版本失败!" , e )
37
40
throw new Error ( e ) ;
38
41
}
39
42
}
40
43
export const getLocalVersion = ( ) => {
41
- console . log ( "开始获取本地版本号..." )
42
44
try {
43
45
const { version} = JSON . parse ( fs . readFileSync ( path . resolve ( rootPath , 'package.json' ) , "utf-8" ) )
44
- console . log ( "本地版本号获取成功!" )
46
+ console . log ( "本地版本号获取成功!======" , version )
45
47
return version ;
46
48
}
47
49
catch ( e ) {
0 commit comments