Skip to content

Commit

Permalink
Update dependencies and use pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
statico committed Jun 15, 2024
1 parent ee201f4 commit d6e36ae
Show file tree
Hide file tree
Showing 6 changed files with 2,865 additions and 2,474 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ npm-debug.log
README.md
.next
.git
.env
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
pnpm lint-staged
54 changes: 16 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,54 +1,32 @@
FROM node:20-alpine AS base

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat

RUN yarn global add pnpm

# Install dependencies only when needed
FROM base AS deps
WORKDIR /app

# Install dependencies
COPY package.json pnpm-lock.yaml* ./
RUN pnpm install

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
FROM node:20-slim AS base

ENV NEXT_TELEMETRY_DISABLED 1
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

RUN pnpm build

# Production image, copy all the files and run next
FROM base AS runner
COPY . /app
WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build

COPY --from=builder /app/public ./public
FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=build --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=build --chown=nextjs:nodejs /app/.next/static ./.next/static

# Needed for migrations
RUN yarn global add knex
COPY --from=builder /app/knexfile.js ./
COPY --from=builder /app/migrations ./migrations

USER nextjs
COPY --from=build /app/knexfile.js ./
COPY --from=build /app/migrations ./migrations

EXPOSE 3000

ENV PORT 3000

CMD ["pnpm", "start"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Femtostats is a lightweight, tiny, privacy-focused web statistics provider with
- See below instructions on creating a Maxmind account to resolve geographic location at the country level.
- Set a `PASSWORD` env var to protect your dashboard behind a password (the username is `admin`).
- Set a `DATA_DIR` env var to store the SQLite database and Maxmind database. (Default is `/tmp`.)
1. Run `pnpm knex migrate:latest` to initialize the database.
1. Run `pnpm knex:migrate` to initialize the database.
1. Include the tag `<script defer src="https://your-femtostats.com/data.js"></script>` on the pages you want to track.
1. For custom event tracking, call `window.femtostats('event name')`

Expand All @@ -63,7 +63,7 @@ The script tag instructions used to reference `script.js`, but uBlock appears to

Requires Node.js 16+ and [pnpm](https://pnpm.io). Run `pnpm` and `pnpm install`.

The default database location is `/tmp/stats.db`. Run `pnpm exec knex seed:run` to populate the database with some sample data.
The default database location is `/tmp/stats.db`. Run `pnpm knex:seed` to populate the database with some sample data.

This project uses [Next.js](https://nextjs.org/), [React](https://reactjs.org/), [SWR](https://swr.vercel.app/), [Recoil](https://recoiljs.org/), [Chakra UI](https://chakra-ui.com/), and [Chart.js](https://www.chartjs.org/).

Expand Down
93 changes: 48 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,62 @@
"license": "GPL-3.0",
"private": true,
"scripts": {
"prepare": "husky",
"dev": "next dev",
"build": "next build",
"start": "yarn exec knex migrate:latest && node server.js",
"start": "pnpm knex:migrate && node server.js",
"lint": "next lint",
"prepare": "husky install"
"knex:migrate": "knex migrate:latest",
"knex:seed": "knex seed:run"
},
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@recoiljs/refine": "^0.1.1",
"chart.js": "^4.4.2",
"dotenv": "^16.4.5",
"framer-motion": "^11.1.9",
"glob-to-regexp": "^0.4.1",
"i18n-iso-countries": "^7.11.1",
"isomorphic-unfetch": "^4.0.2",
"knex": "^3.1.0",
"luxon": "^3.4.4",
"maxmind": "^4.3.19",
"next": "^14.2.3",
"react": "^18.3.1",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.3.1",
"react-icons": "^5.2.1",
"react-world-flags": "^1.6.0",
"recoil": "^0.7.7",
"recoil-sync": "^0.2.0",
"sqlite3": "^5.1.7",
"swr": "^2.2.5",
"tar-stream": "^3.1.7",
"ua-parser-js": "^1.0.37",
"uglify-js": "^3.17.4",
"unfetch": "^5.0.0",
"yup": "^1.4.0"
"@chakra-ui/react": "2.8.2",
"@emotion/react": "11.11.4",
"@emotion/styled": "11.11.5",
"@recoiljs/refine": "0.1.1",
"chart.js": "4.4.3",
"dotenv": "16.4.5",
"framer-motion": "11.2.10",
"glob-to-regexp": "0.4.1",
"husky": "9.0.11",
"i18n-iso-countries": "7.11.2",
"isomorphic-unfetch": "4.0.2",
"knex": "3.1.0",
"luxon": "3.4.4",
"maxmind": "4.3.20",
"next": "14.2.4",
"react": "18.3.1",
"react-chartjs-2": "5.2.0",
"react-dom": "18.3.1",
"react-icons": "5.2.1",
"react-world-flags": "1.6.0",
"recoil": "0.7.7",
"recoil-sync": "0.2.0",
"sqlite3": "5.1.7",
"swr": "2.2.5",
"tar-stream": "3.1.7",
"ua-parser-js": "1.0.38",
"uglify-js": "3.18.0",
"unfetch": "5.0.0",
"yup": "1.4.0"
},
"devDependencies": {
"@types/chart.js": "^2.9.41",
"@types/glob-to-regexp": "^0.4.4",
"@types/luxon": "^3.4.2",
"@types/node": "20.12.11",
"@types/react": "18.3.2",
"@types/react-world-flags": "^1.4.5",
"@types/tar-stream": "^3.1.3",
"@types/ua-parser-js": "^0.7.39",
"@types/uglify-js": "^3.17.5",
"husky": ">=9",
"lint-staged": ">=15",
"prettier": "^3.2.5",
"top-user-agents": "^2.1.22",
"typescript": "^5.4.5"
"@types/chart.js": "2.9.41",
"@types/glob-to-regexp": "0.4.4",
"@types/luxon": "3.4.2",
"@types/node": "20.14.2",
"@types/react": "18.3.3",
"@types/react-world-flags": "1.4.5",
"@types/tar-stream": "3.1.3",
"@types/ua-parser-js": "0.7.39",
"@types/uglify-js": "3.17.5",
"lint-staged": "15.2.7",
"prettier": "3.3.2",
"top-user-agents": "2.1.22",
"typescript": "5.4.5"
},
"lint-staged": {
"*.{js,css,md,ts,tsx}": "prettier --write"
}
},
"packageManager": "pnpm@9.3.0+sha512.ee7b93e0c2bd11409c6424f92b866f31d3ea1bef5fbe47d3c7500cdc3c9668833d2e55681ad66df5b640c61fa9dc25d546efa54d76d7f8bf54b13614ac293631"
}
Loading

0 comments on commit d6e36ae

Please sign in to comment.