Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Added boot and update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylankjy committed Sep 12, 2021
1 parent 85aa6aa commit 0626780
Show file tree
Hide file tree
Showing 5 changed files with 1,688 additions and 51 deletions.
11 changes: 9 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Boot
const boot = require('./app/boot/boot')

// Express
const express = require('express')
const app = express()
Expand Down Expand Up @@ -27,6 +30,8 @@ require('./app/routes/routes')(app)

// Open in browser
const open = require('open')
const chalk = require('chalk')

const webserverPort = 3000

const webserver = () => {
Expand All @@ -46,6 +51,8 @@ const webserver = () => {
}

// Load SQLize models
require('./app/models').sequelize.sync().then(() => {
webserver()
boot().then(() => {
require('./app/models').sequelize.sync().then(() => {
webserver()
})
})
21 changes: 21 additions & 0 deletions app/boot/boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const updater = require('./updater')

const chalk = require('chalk')
const packageInfo = require('../../package.json')

const boot = () => {
return new Promise((resolve) => {
console.log(chalk.blueBright('Metronami') + ' ' + chalk.whiteBright(`v${packageInfo.version}`))
console.log(chalk.gray('Repo: https://github.com/hiyamashu/Metronami | Licensed under GPL v3.0'))
if (packageInfo.version.includes('-beta') || packageInfo.version.includes('-alpha')) {
console.log(chalk.red('This is a beta/alpha version of Metronami. Always keep a backup of your data. Report any bugs if you find any.'))
}
updater().then(() => {
setTimeout(() => {
resolve()
}, 5000)
})
})
}

module.exports = boot
31 changes: 31 additions & 0 deletions app/boot/updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const semver = require('semver')
const getTagFor = require('get-github-tag')
const download = require('download')

const currentVersion = require('../../package.json').version
const chalk = require('chalk')

const updater = () => {
return new Promise((resolve) => {
getTagFor('hiyamashu', 'Metronami', '').then((tag) => {
if (semver.satisfies(currentVersion, `>=${tag}`) === true) {
return resolve()
}

console.log(chalk.greenBright(`New update found: ${tag}`))

// Url of the image
const file = `https://github.com/hiyamashu/Metronami/archive/refs/tags/${tag}.zip`
const filePath = `./updates`

download(file, filePath)
.then(() => {
console.log(chalk.whiteBright('Update downloaded into /updates. Please update Metronami at your nearest convenience.'))
})

resolve()
})
})
}

module.exports = updater
Loading

0 comments on commit 0626780

Please sign in to comment.