Skip to content

Commit 82e9468

Browse files
committed
feat:update version detech using gitee
1 parent 192def0 commit 82e9468

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

common/constants/question.const.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export const NPM_URL = "https://registry.npmjs.org/";
1515
export const GITHUB_RAW = "https://raw.githubusercontent.com/";
1616
// github
1717
export const GITHUB_URL = "https://github.com/";
18-
18+
// gitee
19+
export const GITEE_URL = "https://gitee.com/";
1920
//endregion

common/utils/update/update.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import https from "https";
22
import {rootPath} from "#common/utils/file/getRootPath.js";
33
import fs from "fs";
44
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";
66
import {url_join} from "#common/utils/http/urlJoin.js";
77
import {fetch_} from "#common/utils/http/fetch_.js";
88
// npm 中的 包地址
99
const npmUrl = url_join(NPM_URL,PackageName);
1010
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+
1113
/**
1214
* 获取远端npm库中的版本号
1315
*/
@@ -28,20 +30,20 @@ export const getNpmVersion = async ()=>{
2830
*/
2931
export const getGithubVersion = async ()=>{
3032
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;
3437
}
3538
catch(e){
3639
console.log("获取Github版本失败!",e)
3740
throw new Error(e);
3841
}
3942
}
4043
export const getLocalVersion = ()=>{
41-
console.log("开始获取本地版本号...")
4244
try{
4345
const {version} = JSON.parse(fs.readFileSync(path.resolve(rootPath,'package.json'),"utf-8"))
44-
console.log("本地版本号获取成功!")
46+
console.log("本地版本号获取成功!======",version)
4547
return version;
4648
}
4749
catch (e){

0 commit comments

Comments
 (0)