Skip to content

Commit

Permalink
feat(katzencore): Removed console.logs and added update check into se…
Browse files Browse the repository at this point in the history
…tup function
  • Loading branch information
maxlkatze committed Jul 20, 2024
1 parent 7596b0c commit afe9faf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _Feel free to contribute to this project by creating a pull request.🐱❤️_

## Quick Setup

1. Install using: `npm install @maxlkate/cms`
1. Install using: `npm install @maxlkate/cms@latest`
2. Add `@maxlkate/cms` to the `modules` section of `nuxt.config.js`

```js
Expand Down
37 changes: 31 additions & 6 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
addComponentsDir,
addImportsDir, addLayout,
addImportsDir,
addLayout,
addPlugin,
addRouteMiddleware,
addServerHandler,
Expand All @@ -12,6 +13,8 @@ import {
import { createStorage } from 'unstorage'
import fsDriver from 'unstorage/drivers/fs'

import pkg from '../package.json'

export interface CmsUser {
name: string
password: string
Expand Down Expand Up @@ -41,8 +44,14 @@ export default defineNuxtModule<ModuleOptions>({
},
async setup(_options, _nuxt) {
const { resolve } = createResolver(import.meta.url)

console.info('[KATZE] Module installed;')
updateCheck().then(
(latestVersion) => {
console.warn('\x1B[41m There is a new version of KatzeCMS available \x1B[0m')
console.info('\x1B[42m Please update your package with \x1B[0m npm i @maxlkatze/cms@latest')
console.info('\x1B[42m If you\'re already on the @latest version run: \x1B[0m npm update @maxlkatze/cms')
console.info('\x1B[42m Current version: ' + pkg.version + ' Latest version: ' + latestVersion + '\x1B[0m')
},
)

await installModules()
await addImports()
Expand Down Expand Up @@ -79,7 +88,7 @@ export default defineNuxtModule<ModuleOptions>({
})
const content = await storage.hasItem('content.katze.json') ? await storage.getItem('content.katze.json') as object : {}
_nuxt.options.runtimeConfig.public.content = content
console.info('[KATZE] Content loaded from storage with ' + Object.entries(content).length + ' entries')
console.info('Katze loaded ' + Object.entries(content).length + ' entries from content storage')

addRouteMiddleware({
name: 'auth',
Expand Down Expand Up @@ -125,8 +134,6 @@ const addImports = async () => {

const installModules = async () => {
const { resolve } = createResolver(import.meta.url)
console.log('Make sure to install the following modules:')
console.log('npm install @nuxtjs/tailwindcss @nuxt/image @pinia/nuxt')

await installModule('@nuxtjs/tailwindcss', {
// module configuration
Expand All @@ -150,3 +157,21 @@ const installModules = async () => {
],
})
}
const updateCheck = async () => {
const version = pkg.version
const https = await import('node:https')
return new Promise<string>((resolve) => {
https.get('https://registry.npmjs.org/@maxlkatze/cms/latest', (res) => {
let data = ''
res.on('data', (chunk) => {
data += chunk
})
res.on('end', () => {
const latestVersion = JSON.parse(data).version
if (version !== latestVersion) {
resolve(latestVersion)
}
})
})
})
}
1 change: 0 additions & 1 deletion src/runtime/middleware/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const serverSideAuthentication = async () => {
}

const clientSideAuthentication = async () => {
console.log('Client side authentication')
const token = useCookie('token')
if (!token.value) return false
interface VerifyResponse {
Expand Down

0 comments on commit afe9faf

Please sign in to comment.