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

[CHORE] Workflows + Husky #22

Merged
merged 15 commits into from
Dec 21, 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
32 changes: 32 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
env: {
browser: true,
node: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
ignorePatterns: ['.eslintrc.js', 'node_modules/', 'drizzle/'],
overrides: [
{
files: ['.eslintrc.{js,cjs}'],
env: {
node: true,
},
parserOptions: {
sourceType: 'script',
},
},
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'no-console': 'off',
'prettier/prettier': 'error',
},
};
25 changes: 25 additions & 0 deletions .github/workflows/codecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: codecheck

on:
pull_request:
branches:
- develop
types: [opened, synchronize]

jobs:
code-check:
name: Run eslint and typescript check
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Run code check
run: bun check
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bun i
bun check:write
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drizzle
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"singleQuote": true,
"arrowParens": "always",
"semi": true,
"tabWidth": 2,
"trailingComma": "all",
"endOfLine": "auto",
"importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"]
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Arkavidia 9.0 Backend

## Welcome!

Please refer ke [Guidebook IT](https://docs.google.com/document/d/1e0YsDlhmFLVOkYFQUWyq5eJnh_5tSmRwkGSmqW-j36I/edit?tab=t.3segyhsw1vo3#heading=h.tq38eiq9xfrt) untuk petunjuk cara kontribusi ke repository ini.

## Tech Stack

- Bun as Javascript runtime
- Hono as API framework
- Drizzle as Object Relational Mapper
Expand All @@ -12,12 +14,15 @@ Please refer ke [Guidebook IT](https://docs.google.com/document/d/1e0YsDlhmFLVOk
- Minio as object storage

## How To Run

To install dependencies:

```sh
bun install
```

To run:

```sh
bun run dev
```
Expand Down
36 changes: 0 additions & 36 deletions biome.json

This file was deleted.

Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
14 changes: 7 additions & 7 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
dialect: 'postgresql',
schema: './src/db/schema',
out: './drizzle',
dbCredentials: {
// biome-ignore lint/style/noNonNullAssertion: <explanation>
url: process.env.DATABASE_URL!,
},
dialect: 'postgresql',
schema: './src/db/schema',
out: './drizzle',
dbCredentials: {
// biome-ignore lint/style/noNonNullAssertion: <explanation>
url: process.env.DATABASE_URL!,
},
});
88 changes: 51 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
{
"name": "backend",
"scripts": {
"dev": "bun run --hot src/index.ts",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate && bun run src/db/migrate-trigger.ts",
"db:studio": "drizzle-kit studio",
"check": "bunx biome check src && bunx check:type",
"check:write": "bunx biome check --write",
"check:lint": "biome lint src",
"check:format": "biome format src",
"check:type": "tsc --noEmit"
},
"dependencies": {
"@hono/zod-openapi": "^0.18.3",
"@paralleldrive/cuid2": "^2.2.2",
"@scalar/hono-api-reference": "^0.5.162",
"@types/nodemailer": "^6.4.17",
"argon2": "^0.41.1",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.36.0",
"drizzle-zod": "^0.5.1",
"hono": "^4.6.12",
"minio": "^8.0.2",
"nodemailer": "^6.9.16",
"postgres": "^3.4.5",
"zod": "^3.23.8"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@softwaretechnik/dbml-renderer": "^1.0.30",
"@types/bun": "latest",
"@types/pg": "^8.11.10",
"drizzle-dbml-generator": "^0.10.0",
"drizzle-kit": "^0.27.1",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
}
"name": "backend",
"scripts": {
"dev": "bun run --hot src/index.ts",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate && bun run src/db/migrate-trigger.ts",
"db:studio": "drizzle-kit studio",
"check": "bun run typecheck && bun run codecheck",
"check:write": "bun run format && bun run pretty",
"codecheck": "eslint src --ext .ts",
"typecheck": "tsc --noEmit",
"format": "eslint src --ext .ts --fix",
"pretty": "prettier . --write",
"prepare": "husky"
},
"dependencies": {
"@hono/zod-openapi": "^0.18.3",
"@paralleldrive/cuid2": "^2.2.2",
"@scalar/hono-api-reference": "^0.5.162",
"@trivago/prettier-plugin-sort-imports": "^5.2.0",
"@types/nodemailer": "^6.4.17",
"argon2": "^0.41.1",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.36.0",
"drizzle-zod": "^0.5.1",
"hono": "^4.6.12",
"husky": "^9.1.7",
"install": "^0.13.0",
"minio": "^8.0.2",
"nodemailer": "^6.9.16",
"postgres": "^3.4.5",
"zod": "^3.23.8"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@softwaretechnik/dbml-renderer": "^1.0.30",
"@types/bun": "latest",
"@types/pg": "^8.11.10",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"drizzle-dbml-generator": "^0.10.0",
"drizzle-kit": "^0.27.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.0.0",
"prettier": "^3.2.5",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0"
}
}
50 changes: 25 additions & 25 deletions src/configs/env.config.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { z } from 'zod';

const EnvSchema = z.object({
PORT: z.coerce.number().default(5000),
DATABASE_URL: z.string().url(),
ALLOWED_ORIGINS: z
.string()
.default('["http://localhost:5173"]')
.transform((value) => JSON.parse(value))
.pipe(z.array(z.string().url())),
ACCESS_TOKEN_SECRET: z.string(),
ACCESS_TOKEN_EXPIRATION: z.coerce.number(),
REFRESH_TOKEN_SECRET: z.string(),
REFRESH_TOKEN_EXPIRATION: z.coerce.number(),
SMTP_HOST: z.string(),
SMTP_USER: z.string(),
SMTP_PASSWORD: z.string(),
SMTP_PORT: z.coerce.number().default(465),
SMTP_SECURE: z.coerce.boolean().default(true),
GOOGLE_CLIENT_ID: z.string(),
GOOGLE_CLIENT_SECRET: z.string(),
GOOGLE_CALLBACK_URL: z.string(),
S3_ENDPOINT: z.string(),
S3_ACCESS_KEY_ID: z.string(),
S3_SECRET_ACCESS_KEY: z.string(),
PORT: z.coerce.number().default(5000),
DATABASE_URL: z.string().url(),
ALLOWED_ORIGINS: z
.string()
.default('["http://localhost:5173"]')
.transform((value) => JSON.parse(value))
.pipe(z.array(z.string().url())),
ACCESS_TOKEN_SECRET: z.string(),
ACCESS_TOKEN_EXPIRATION: z.coerce.number(),
REFRESH_TOKEN_SECRET: z.string(),
REFRESH_TOKEN_EXPIRATION: z.coerce.number(),
SMTP_HOST: z.string(),
SMTP_USER: z.string(),
SMTP_PASSWORD: z.string(),
SMTP_PORT: z.coerce.number().default(465),
SMTP_SECURE: z.coerce.boolean().default(true),
GOOGLE_CLIENT_ID: z.string(),
GOOGLE_CLIENT_SECRET: z.string(),
GOOGLE_CALLBACK_URL: z.string(),
S3_ENDPOINT: z.string(),
S3_ACCESS_KEY_ID: z.string(),
S3_SECRET_ACCESS_KEY: z.string(),
});

const result = EnvSchema.safeParse(process.env);
if (!result.success) {
console.error('Invalid environment variables: ');
console.error(result.error.flatten().fieldErrors);
process.exit(1);
console.error('Invalid environment variables: ');
console.error(result.error.flatten().fieldErrors);
process.exit(1);
}

export const env = result.data;
3 changes: 2 additions & 1 deletion src/controllers/api.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { OpenAPIHono } from '@hono/zod-openapi';

import { authProtectedRouter, authRouter } from './auth.controller';
import { competitionProtectedRouter } from './competition.controller';
import { healthRouter } from './health.controller';
import { mediaRouter } from './media.controller';
import { teamMemberProtectedRouter } from './team-member.controller';
import { teamProtectedRouter } from './team.controller';
import { userProtectedRouter } from './user.controller';
import { competitionProtectedRouter } from './competition.controller';

const unprotectedApiRouter = new OpenAPIHono();
unprotectedApiRouter.route('/', healthRouter);
Expand Down
Loading
Loading