Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache refinement (and others) #948

Merged
merged 8 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public/missing-locales
public/images/custom
public/images/uicons
server/src/configs/
packages/types/**/*.d.ts
packages/**/*.d.ts
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"packages/*"
],
"scripts": {
"postinstall": "yarn masterfile",
"build": "vite build",
"config:check": "yarn workspace @rm/config run check",
"config:env": "yarn workspace @rm/config run generate",
Expand Down Expand Up @@ -45,7 +46,7 @@
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix"
"eslint \"**/*.{js,jsx}\" --fix"
],
"**/*": [
"prettier --write --ignore-unknown"
Expand Down Expand Up @@ -155,7 +156,7 @@
"morgan": "^1.10.0",
"mysql2": "^3.4.0",
"node-cache": "^5.1.2",
"node-fetch": "2",
"node-fetch": "2.6.7",
"node-geocoder": "^4.2.0",
"nodes2ts": "^2.0.0",
"objection": "^3.0.1",
Expand Down Expand Up @@ -186,6 +187,7 @@
"@sentry/vite-plugin": "2.10.3",
"@types/dlv": "^1.1.2",
"@types/node": "^18",
"@types/node-fetch": "2.6.1",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.0.9",
"@vitejs/plugin-react": "4.2.1",
Expand All @@ -206,6 +208,7 @@
"prettier": "^2.8.8",
"rollup-plugin-delete": "^2.0.0",
"semantic-release": "^19.0.5",
"typescript": "^5.3.3",
"vite": "5.0.12",
"vite-plugin-checker": "0.6.0"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/locales/lib/create.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @ts-check
const { default: fetch } = require('node-fetch')

const config = require('@rm/config')
const { log, HELPERS } = require('@rm/logger')

Expand Down
1 change: 1 addition & 0 deletions packages/locales/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
const { promises: fs, readdirSync } = require('fs')
const { resolve } = require('path')
const { default: fetch } = require('node-fetch')

const { log, HELPERS } = require('@rm/logger')

Expand Down
4 changes: 4 additions & 0 deletions packages/locales/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"@rm/config": "*",
"@rm/logger": "*",
"dotenv": "^16.3.1",
"node-fetch": "2.6.7",
"openai": "^4.24.1"
},
"devDependencies": {
"@types/node-fetch": "2.6.1"
}
}
1 change: 1 addition & 0 deletions packages/logger/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const HELPERS = /** @type {const} */ ({
fetch: chalk.hex('#880e4f')('[FETCH]'),
scanner: chalk.hex('#b39ddb')('[SCANNER]'),
build: chalk.hex('#ef6c00')('[BUILD]'),
ReactMap: chalk.hex('#ff3d00')('[ReactMap]'),

pokemon: chalk.hex('#f44336')('[POKEMON]'),
pokestops: chalk.hex('#e91e63')('[POKESTOPS]'),
Expand Down
85 changes: 85 additions & 0 deletions packages/masterfile/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import type { AdvCategories, Rarity } from '@rm/types'

export interface MasterfileForm {
name: string
rarity?: string
isCostume?: boolean
category?: AdvCategories
}

export interface MasterfilePokemon {
name: string
pokedexId: number
defaultFormId: number
types: number[]
quickMoves: number[]
chargedMoves: number[]
genId: number
forms: {
[formId: string]: MasterfileForm
}
height?: number
weight?: number
family?: number
legendary?: boolean
mythical?: boolean
ultraBeast?: boolean
rarity?: string
historic?: string
tempEvolutions?: {
[evolutionId: string]: {}
}
}

export interface MasterfileObject {
[typeId: string]: string
}

export interface MasterfileMove {
name: string
type: number
}

export interface InvasionPokemon {
id: number
form: number
}

export interface InvasionRewards {
first: InvasionPokemon[]
second: InvasionPokemon[]
third: InvasionPokemon[]
}

export interface Invasion {
type: string
gender: number
grunt: string
firstReward: boolean
secondReward: boolean
thirdReward: boolean
encounters: InvasionRewards
}

export interface MasterfileWeather {
name: string
types: number[]
}

export interface Masterfile {
pokemon: Record<string, MasterfilePokemon>
types: MasterfileObject
items: MasterfileObject
questRewardTypes: MasterfileObject
moves: Record<string, MasterfileMove>
invasions: Record<string, Invasion>
weather: Record<string, MasterfileWeather>
}

export declare function generate(
save?: boolean,
historicRarity?: Rarity,
dbRarity?: Rarity,
): Promise<Masterfile>

export declare function read(): Masterfile
12 changes: 4 additions & 8 deletions packages/masterfile/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
const fs = require('fs')
const { resolve } = require('path')
const { default: fetch } = require('node-fetch')

const config = require('@rm/config')
const { log, HELPERS } = require('@rm/logger')
Expand All @@ -20,13 +21,7 @@ Object.entries(defaultRarity).forEach(([tier, pokemon]) => {
}
})

/**
*
* @param {boolean} save
* @param {import('@rm/types').Rarity} historicRarity
* @param {import('@rm/types').Rarity} dbRarity
* @returns
*/
/** @type {import('.').generate} */
const generate = async (save = false, historicRarity = {}, dbRarity = {}) => {
log.info(HELPERS.masterfile, 'generating masterfile')
try {
Expand Down Expand Up @@ -91,6 +86,7 @@ if (require.main === module) {
generate(true).then(() => log.info(HELPERS.masterfile, 'OK'))
}

/** @type {import('.').read} */
const read = () => {
try {
return JSON.parse(
Expand All @@ -101,7 +97,7 @@ const read = () => {
HELPERS.masterfile,
'Unable to read masterfile, generating a new one for you now',
)
return generate(true)
generate(true)
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/masterfile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"generate": "node ./lib",
"sort": "npx sort-package-json",
Expand All @@ -15,6 +16,10 @@
"dependencies": {
"@rm/config": "*",
"@rm/logger": "*",
"@rm/types": "*"
"@rm/types": "*",
"node-fetch": "2.6.7"
},
"devDependencies": {
"@types/node-fetch": "2.6.1"
}
}
9 changes: 8 additions & 1 deletion packages/types/lib/augmentations.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ButtonProps } from '@mui/material'
import { Config, GetSafeConfig } from './config'
import { ExpressUser } from './server'
import { ExpressUser, Permissions } from './server'
import { Request } from 'express'

declare module 'config' {
Expand Down Expand Up @@ -50,6 +50,13 @@ declare module '@mui/material/styles' {
}
}

declare module 'express-session' {
interface SessionData {
cooldown?: number
perms?: Permissions
}
}

// TODO
// declare module '@mui/material/Button' {
// interface ExtendButtonTypeMap {
Expand Down
7 changes: 1 addition & 6 deletions packages/types/lib/general.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ export type RMGeoJSON = {
features: RMFeature[]
}

import masterfile = require('packages/masterfile/lib/data/masterfile.json')
import { Config } from './config'
import { SliderProps } from '@mui/material'

export type Masterfile = typeof masterfile

export type Strategy = 'discord' | 'telegram' | 'local'

export type S2Polygon = [number, number][]
Expand Down Expand Up @@ -88,9 +85,7 @@ export interface UICONS {
egg: UiconImage[]
}
reward: {
[
key: Masterfile['questRewardTypes'][keyof Masterfile['questRewardTypes']]
]: UiconImage[]
[key: string]: UiconImage[]
}
spawnpoint: UiconImage[]
team: UiconImage[]
Expand Down
57 changes: 32 additions & 25 deletions packages/vite-plugins/lib/favicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,43 @@
const { resolve } = require('path')
const fs = require('fs')

const { log, HELPERS } = require('@rm/logger')

/**
* @param {boolean} isDevelopment
* @returns {import('vite').Plugin}
*/
const faviconPlugin = (isDevelopment) => {
const favicon = fs.existsSync(
resolve(__dirname, '../../../public/favicon/favicon.ico'),
)
? resolve(__dirname, '../../../public/favicon/favicon.ico')
: resolve(__dirname, '../../../public/favicon/fallback.ico')
return {
name: 'vite-plugin-locales',
generateBundle() {
if (isDevelopment) return
this.emitFile({
type: 'asset',
fileName: 'favicon.ico',
source: fs.readFileSync(favicon),
})
},
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url === '/favicon.ico') {
res.writeHead(200, { 'Content-Type': 'image/x-icon' })
res.end(fs.readFileSync(favicon))
return
}
next()
})
},
try {
const favicon = fs.existsSync(
resolve(__dirname, '../../../public/favicon/favicon.ico'),
)
? resolve(__dirname, '../../../public/favicon/favicon.ico')
: resolve(__dirname, '../../../public/favicon/fallback.ico')
return {
name: 'vite-plugin-favicon',
generateBundle() {
if (isDevelopment) return
this.emitFile({
type: 'asset',
fileName: 'favicon.ico',
source: fs.readFileSync(favicon),
})
},
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url === '/favicon.ico') {
res.writeHead(200, { 'Content-Type': 'image/x-icon' })
res.end(fs.readFileSync(favicon))
return
}
next()
})
},
}
} catch (e) {
log.error(HELPERS.build, 'Error loading favicon', e)
return { name: 'vite-plugin-favicon' }
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugins/lib/muteWarnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const muteWarningsPlugin = (warningsToIgnore) => {
const mutedMessages = new Set()
return {
name: 'mute-warnings',
name: 'vite-mute-warnings',
enforce: 'pre',
config: (userConfig) => ({
build: {
Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"prettier:fix": "prettier --write \"**/*.{css,html,js,jsx,yml}\""
},
"dependencies": {
"@rm/locales": "*"
"@rm/locales": "*",
"@rm/logger": "*"
},
"devDependencies": {
"vite": "5.0.12"
Expand Down
Loading
Loading