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

New: bun #26

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
55 changes: 23 additions & 32 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,39 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
# pull the repo
- name: Check out Git repository
uses: actions/checkout@v4
# setup node
- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
# install dependencies
- name: Install Node.js dependencies
run: npm ci
# run eslint
- name: Run linters
uses: wearerequired/lint-action@master
- uses: oven-sh/setup-bun@v1
- run: bun run ci
- uses: wearerequired/lint-action@master
with:
auto_fix: false
eslint: true
eslint_fix: false
eslint_extensions: "js,ts"
build:
runs-on: ubuntu-latest
steps:
# pull the repo
- name: Check out Git repository
uses: actions/checkout@v4
# setup node
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
# install dependencies
- name: Install Node.js dependencies
run: npm ci
# build the app
- name: Build TVBot
run: npm run build
# tsc:
# runs-on: ubuntu-latest
# steps:
# # pull the repo
# - name: Check out Git repository
# uses: actions/checkout@v2
# # setup node
# - name: Setup Node.js 18
# uses: actions/setup-node@v2
# with:
# node-version: 18
# # install dependencies
# - name: Install Node.js dependencies
# run: npm ci
# # build the app
# - name: Build TVBot
# run: npm run build
build_docker:
runs-on: ubuntu-latest
steps:
# pull the repo
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
# just check that it builds, dont push it anywhere cuz whatever
- name: Build and push
uses: docker/build-push-action@v3
Expand Down
24 changes: 11 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
FROM node:20-slim as build
WORKDIR /build
COPY . .
RUN npm ci
RUN npm run build

FROM node:20-slim as prod
FROM oven/bun:debian
WORKDIR /app
RUN apt-get update && apt-get -y install openssl
RUN npm install pm2 prisma --save-dev && npm install @prisma/client
COPY --from=build /build/prisma ./prisma
COPY --from=build /build/dist .
COPY --from=build /build/entrypoint.sh .
COPY package.json ./package.json
COPY bun.lockb ./bun.lockb
RUN bun run ci

COPY src/ /app/src/

COPY prisma/ /app/prisma/
RUN bunx prisma generate

ENV TZ="America/Chicago"
RUN npx prisma generate
COPY entrypoint.sh ./entrypoint.sh
ENTRYPOINT ["sh", "entrypoint.sh"]
Binary file added bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

set -e
# migrate the database and erorr if it fails
npx prisma db push
bunx prisma db push
set +e

# runs 'node bundle.mjs' wrapped in pm2
# runs 'bun src/app.ts' wrapped in pm2
# pm2 keeps the process alive if it crashed for some reason or something
npx pm2 start node --no-daemon --max-memory-restart 1G --restart-delay 1000 -- --enable-source-maps bundle.mjs
bunx pm2 start bun --no-daemon --max-memory-restart 1G --restart-delay 1000 -- src/app.ts
36 changes: 0 additions & 36 deletions esbuild.mjs

This file was deleted.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"scripts": {
"build": "node esbuild.mjs",
"dev": "export NODE_ENV=development; node --enable-source-maps esbuild.mjs",
"ci": "bun install --frozen-lockfile",
"start": "bun src/app.ts",
"dev": "bun --watch src/app.ts",
"lint": "eslint 'src/**'",
"db:migrate": "prisma migrate dev",
"db:studio": "prisma studio"
Expand All @@ -13,24 +14,23 @@
"city-timezones": "^1.2.1",
"conventional-changelog-eslint": "^6.0.0",
"discord.js": "^14.11.0",
"dotenv": "^16.1.4",
"moment-timezone": "^0.5.43",
"node-schedule": "^2.1.1",
"parse-url": "^8.1.0",
"semantic-release": "^23.1.1",
"sqlite": "^4.2.1"
},
"devDependencies": {
"@es-exec/esbuild-plugin-start": "^0.0.4",
"@types/node-schedule": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"esbuild": "^0.16.17",
"bun-types": "^1.1.3",
"eslint": "^8.42.0",
"eslint-config-standard-with-typescript": "^34.0.1",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-promise": "^6.1.1",
"prisma": "^5.0.0",
"prisma": "^5.12.1",
"pm2": "^5.3.1",
"typescript": "^4.9.5"
}
}
10 changes: 3 additions & 7 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as dotenv from 'dotenv'
import schedule from 'node-schedule'
import { ChannelType, Client, Events, GatewayIntentBits } from 'discord.js'
import { scheduleAiringMessages } from './lib/episodeNotifier'
Expand All @@ -8,8 +7,6 @@ import { type Settings, SettingsManager } from './lib/settingsManager'
import { sendMorningSummary } from './lib/morningSummary'
import { setRandomShowActivity, setTVDBLoadingActivity } from './lib/discordActivities'

dotenv.config()

/**
* The main bot application
*/
Expand All @@ -35,14 +32,12 @@ export class App {
this.client = new Client({ intents: [GatewayIntentBits.Guilds] })
this.commands = new CommandManager(this, this.clientId, this.token, this.guildId)
this.settings = new SettingsManager()

void this.init()
}

/**
* Async init function for app
*/
private readonly init = async (): Promise<void> => {
readonly init = async (): Promise<void> => {
await this.settings.refresh()
await this.commands.registerCommands()
this.startBot()
Expand Down Expand Up @@ -126,4 +121,5 @@ export class App {
}

// make an instance of the application class
(() => new App())()
const app = new App()
await app.init()
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"module": "es2022",
"target": "es2022",
"module": "esnext",
"target": "esnext",
"lib": ["ESNext"],
"esModuleInterop": true,
"strict": true,
"allowSyntheticDefaultImports": true,
Expand All @@ -11,6 +12,7 @@
"resolveJsonModule": true,
"sourceMap": true,
"baseUrl": ".",
"types": ["bun-types"],
"paths": {
"*": [
"node_modules/*",
Expand Down
Loading