Skip to content

Commit a01c873

Browse files
committed
feat: update function basic
1 parent 739b924 commit a01c873

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

common/utils/etc/update.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import https from "https";
2+
import {rootPath} from "#common/utils/file/getRootPath.js";
3+
import fs from "fs";
4+
import path from "path";
5+
6+
/**
7+
* 更新脚本 - 更新自己
8+
*/
9+
export const getRemoteVersion = ()=>{
10+
return new Promise((resolve, reject) => {
11+
const url = `https://registry.npmjs.org/leetcode-practice`;
12+
https.get(url, (res) => {
13+
let data = '';
14+
res.on('data', (chunk) => {
15+
data += chunk;
16+
});
17+
res.on('end', () => {
18+
try {
19+
const packageInfo = JSON.parse(data);
20+
const latestVersion = packageInfo['dist-tags'].latest;
21+
resolve(latestVersion);
22+
} catch (error) {
23+
reject(error);
24+
}
25+
});
26+
}).on('error', (error) => {
27+
reject(error);
28+
});
29+
});
30+
}
31+
32+
export const getLocalVersion = ()=>{
33+
try{
34+
const {version} = JSON.parse(fs.readFileSync(path.resolve(rootPath,'package.json'),"utf-8"))
35+
return version;
36+
}
37+
catch (e){
38+
return false;
39+
}
40+
}
41+
42+
export const checkUpdate = async ()=>{
43+
const remote = await getRemoteVersion();
44+
const local = getLocalVersion();
45+
return remote === local;
46+
}

common/view/update.view.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const easyUpdateView = ()=>{
2+
const checkQuestion = {
3+
type:"confirm",
4+
name:"",
5+
message:"检测到更新"
6+
};
7+
}

scripts/create-color-font.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import inquirer from "inquirer";
44
const question = [{
55
type: 'input',
66
name: 'font',
7-
message: '请输入要渐变色的文本:',
8-
choices: ['today', 'identity', 'random'],
7+
message: '请输入要渐变色的文本:'
98
}];
109
// 第一个问题 选择的模式
1110
const {font} = await inquirer.prompt(question, null);
12-
createColorFont(font);
11+
createColorFont(font);

0 commit comments

Comments
 (0)