Skip to content

Commit d301ff6

Browse files
committed
feat(update-checker): check new versions
1 parent db69de8 commit d301ff6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

server/plugins/0.update-checker.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import currentPackage from '~/package.json'
2+
3+
export default defineNitroPlugin(async () => {
4+
try {
5+
const latestPackage = await $fetch<typeof currentPackage>('https://raw.githubusercontent.com/hywax/mafl/main/package.json', {
6+
parseResponse: (json) => JSON.parse(json)
7+
})
8+
9+
const parseVersion = (version: string): number => parseInt(version.replace(/\./g, ''), 10);
10+
const difference = parseVersion(latestPackage.version) - parseVersion(currentPackage.version)
11+
12+
if (difference > 0) {
13+
return console.log(`⚠️ update available: ${latestPackage.version}`)
14+
}
15+
16+
console.log('✅ mafl is up-to-date')
17+
} catch (_) {
18+
console.log('❌ failed to check for an update')
19+
}
20+
})

0 commit comments

Comments
 (0)