some updates

main
Antonio De Lucreziis 3 months ago
parent e76f3abea0
commit e5143c515a

@ -0,0 +1,4 @@
Dockerfile
node_modules
.git
*.local*

@ -0,0 +1,24 @@
FROM node:20-alpine AS base
WORKDIR /app
COPY package.json package-lock.json ./
FROM base AS prod-deps
RUN npm install --omit=dev
FROM base AS build-deps
RUN npm install
FROM build-deps AS build
COPY . .
RUN npm run build
FROM base AS runtime
COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
CMD node ./dist/server/entry.mjs # Start the app

@ -8,10 +8,8 @@ import preact from '@astrojs/preact'
// https://astro.build/config
export default defineConfig({
output: 'server',
integrations: [preact()],
adapter: node({
mode: 'standalone',
}),
integrations: [preact()],
})

@ -0,0 +1,13 @@
services:
ggwp:
build:
context: .
image: ggwp
container_name: ggwp-container
restart: unless-stopped
ports:
- "4321:4321"
volumes:
- /usr/share/ggwp:/app/database.local
environment:
- DATABASE_FILE=database.local/ggwp.db

7411
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,7 +1,7 @@
import { requestJSON, sendJSON } from '@/client/utils'
import type { Room, RoomData } from '@/db/model'
import { sendJSON } from '@/client/utils'
import type { Room } from '@/db/model'
import type { Action, ActionAnswer, ActionJolly } from '@/ggwp'
import { useEffect, useState, type Dispatch, type StateUpdater } from 'preact/hooks'
import { type Dispatch, type StateUpdater } from 'preact/hooks'
type ActionCardProps = {
moveUp: () => void

@ -1,4 +1,3 @@
import { LiveLeaderboard } from '@/components/LiveLeaderboard'
import { SubmitAction } from '@/components/SubmitAction'
import { ActionRegistry } from '@/components/ActionRegistry'
import { useEffect, useRef, useState } from 'preact/hooks'

@ -1,7 +1,7 @@
import { requestJSON, sendJSON } from '@/client/utils'
import { sendJSON } from '@/client/utils'
import type { Room, RoomData } from '@/db/model'
import { type Action, type ActionAnswer, type ActionJolly } from '@/ggwp'
import { useEffect, useState } from 'preact/hooks'
import { useState } from 'preact/hooks'
type Outcome = 'correct' | 'partial' | 'wrong'

@ -4,7 +4,7 @@ import type { Room, RoomData } from './model'
import type { Question } from '@/ggwp'
import { emitRoomUpdate } from './events'
const db = new Database('ggwp.db')
const db = new Database(process.env.DATABASE_FILE ?? './database.local/ggwp.db')
db.pragma('journal_mode = WAL')
db.pragma('foreign_keys = ON')

@ -18,19 +18,22 @@ describe('ggwp simple game', () => {
{ type: 'answer', team: 'B', question: 'Q2-2', outcome: 'partial' },
{ type: 'answer', team: 'A', question: 'Q1-1', outcome: 'correct' },
{ type: 'answer', team: 'A', question: 'Q1-2', outcome: 'correct' },
{ type: 'jolly', team: 'A', groupId: 'P1' },
{ type: 'jolly', team: 'A', group: 'P1' },
{ type: 'answer', team: 'C', question: 'Q1-1', outcome: 'correct' },
{ type: 'answer', team: 'D', question: 'Q1-1', outcome: 'correct' },
] satisfies Action[]
const scoreboard = computeScoreboardState(game, actions)
expect(scoreboard).toEqual([
expect(scoreboard).toEqual({
teamJollyGroup: { A: 'P1' },
board: [
{ team: 'A', totalScore: 31, questionScores: { 'Q1-1': 13, 'Q1-2': 13, 'Q2-1': 0, 'Q2-2': 0 } },
{ team: 'B', totalScore: 13, questionScores: { 'Q1-1': 5, 'Q1-2': 0, 'Q2-1': 0, 'Q2-2': 8 } },
{ team: 'C', totalScore: 12, questionScores: { 'Q1-1': 12, 'Q1-2': 0, 'Q2-1': 0, 'Q2-2': 0 } },
{ team: 'D', totalScore: 11, questionScores: { 'Q1-1': 11, 'Q1-2': 0, 'Q2-1': 0, 'Q2-2': 0 } },
])
],
})
// expect(scoreboard).toEqual({
// ['A']: 10 + 3 + 10 + 3 + 5, // = 31
// ['B']: 5 + 5 + 3, // = 13

Loading…
Cancel
Save