Skip to content
Draft
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: 2 additions & 0 deletions .github/workflows/deploy-on-main-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:

- name: Install Dependencies
run: bun install
env:
NODE_ENV: production

- name: Build Project
run: bun run build -v
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-to-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:

- name: Build Project
run: bun run build -v
env:
NODE_ENV: production

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test-on-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ name: Run Integration Tests

on:
push:
branches: [main]
branches:
- main
- staging
pull_request:
branches:
- main
- staging

jobs:
integration-tests:
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ COPY bun.lock .

COPY package.json .

RUN bun install --frozen-lockfile --ignore-scripts
COPY packages/frontend/package.json frontend/package.json

ENV NODE_ENV=development

RUN bun install --ignore-scripts
858 changes: 778 additions & 80 deletions bun.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ services:
- .:/app
- api_node_modules:/app/node_modules
pull_policy: build
command: ['bun', '--hot', 'run', './scripts/dev']
command: >
sh -c "bun run scripts/seed.ts && bun --hot run './scripts/dev'"
extra_hosts:
- 'db.localtest.me:host-gateway'
environment:
Expand All @@ -47,16 +48,17 @@ services:
- JWT_SECRET=supersecret
frontend:
build:
context: ./frontend
context: .
dockerfile: Dockerfile
volumes:
- ./frontend:/app
- frontend_node_modules:/app/node_modules
- .:/app
- frontend_node_modules:/app/packages/frontend/node_modules
depends_on:
- api
ports:
- '5173:5173'
command: ['bun', 'run', 'scripts/dev', '--host=0.0.0.0']
command: >
sh -c "cd /app/packages/frontend && bun run scripts/dev --host=0.0.0.0"

volumes:
db_data:
Expand Down
9 changes: 0 additions & 9 deletions frontend/Dockerfile

This file was deleted.

1,386 changes: 0 additions & 1,386 deletions frontend/bun.lock

This file was deleted.

39 changes: 0 additions & 39 deletions frontend/src/app.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/src/components/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion frontend/src/types.ts

This file was deleted.

55 changes: 36 additions & 19 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ components:
type: http
scheme: bearer
bearerFormat: JWT
responses:
BadRequestResponse:
description: Bad Request
content:
application/json:
schema:
$ref: "#/components/schemas/BaseResponseModel"
UnauthorizedResponse:
description: Unauthorized
content:
application/json:
schema:
$ref: "#/components/schemas/BaseResponseModel"
ForbiddenResponse:
description: Forbidden
content:
application/json:
schema:
$ref: "#/components/schemas/BaseResponseModel"
schemas:
AuthRequestModel:
type: object
Expand Down Expand Up @@ -141,32 +160,30 @@ paths:
schema:
$ref: "#/components/schemas/LoginResponseModel"
"400":
description: Invalid request
content:
application/json:
schema:
$ref: "#/components/schemas/BaseResponseModel"
$ref: "#/components/responses/BadRequestResponse"
"401":
$ref: "#/components/responses/UnauthorizedResponse"
"403":
$ref: "#/components/responses/ForbiddenResponse"
/meals:
post:
security:
- JWTAuth: []
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/PostMealsRequestModel"
responses:
"200":
"201":
description: Meal posted successfully
content:
application/json:
schema:
$ref: "#/components/schemas/PostMealsResponseModel"
"400":
description: Invalid request
content:
application/json:
schema:
$ref: "#/components/schemas/BaseResponseModel"
/refresh:
$ref: "#/components/responses/BadRequestResponse"
/refresh-token:
post:
requestBody:
content:
Expand All @@ -181,11 +198,9 @@ paths:
schema:
$ref: "#/components/schemas/RefreshResponseModel"
"400":
description: Invalid request
content:
application/json:
schema:
$ref: "#/components/schemas/BaseResponseModel"
$ref: "#/components/responses/BadRequestResponse"
"401":
$ref: "#/components/responses/UnauthorizedResponse"
/register:
post:
requestBody:
Expand All @@ -194,14 +209,16 @@ paths:
schema:
$ref: "#/components/schemas/AuthRequestModel"
responses:
"200":
"201":
description: Registration successful
content:
application/json:
schema:
$ref: "#/components/schemas/RegisterResponseModel"
"400":
description: Invalid request
$ref: "#/components/responses/BadRequestResponse"
"409":
description: User already exists
content:
application/json:
schema:
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@
"yargs": "^17.7.2"
},
"scripts": {
"build": "NODE_ENV=production bun run scripts/build.ts",
"build": "NODE_ENV=production bun run scripts/build",
"deploy": "bun run scripts/deploy",
"format": "bun run prettier --write .",
"gen-spec": "bun run scripts/gen-spec-json.ts",
"integration-tests": "bun run scripts/integration-tests.ts",
"postinstall": "bun run scripts/postinstall",
"postinstall": "NODE_ENV=development bun run scripts/postinstall",
"push-schema": "DATABASE_URL=postgres://postgres:[email protected]:5432 bunx drizzle-kit push"
}
},
"workspaces": [
"packages/*"
],
"trustedDependencies": [
"esbuild",
"frontend",
"msw"
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/frontend/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { build } from './scripts/build';
export { postinstall } from './scripts/postinstall';
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const createConfigParams = (cfgOverrides?: CreateOrvalConfigParams): Conf
target: './sdk.ts',
schemas: './schemas',
},
input: { target: path.resolve(__dirname, '../openapi.yaml') },
input: { target: path.resolve(__dirname, '../../openapi.yaml') },
},
};
};
Expand Down
5 changes: 3 additions & 2 deletions frontend/package.json → packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"private": true,
"version": "0.0.0",
"type": "module",
"main": "scripts/build.ts",
"main": "lib.ts",
"scripts": {
"build": "bun run scripts/build.ts",
"gen-client": "bun run scripts/gen-client.ts -- --reschema"
"gen-client": "bun run scripts/gen-client.ts -- --reschema",
"postinstall": "bun run scripts/postinstall.ts"
},
"devDependencies": {
"@tailwindcss/vite": "^4.1.7",
Expand Down
File renamed without changes
15 changes: 2 additions & 13 deletions frontend/scripts/build.ts → packages/frontend/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { hideBin } from 'yargs/helpers';
import ViteConfig from '../vite.config.js';

type BuildConfig = {
genClient?: boolean;
genClientBaseUrl?: string | null;
outDir?: string;
verbose?: boolean;
};
Expand All @@ -15,20 +13,12 @@ export const build = async (configOverride: BuildConfig) => {
console.log('Starting build process...');

const defaults: Required<BuildConfig> = {
genClient: false,
genClientBaseUrl: null,
outDir: 'dist',
verbose: false,
};

const config = { ...defaults, ...configOverride };
const { genClient, genClientBaseUrl, outDir, verbose } = config;

if (genClient) {
if (verbose) console.log('Generating API client from OpenAPI schema...');
const { default: generateAPIClient } = await import('./gen-client.js');
await generateAPIClient({ baseUrl: genClientBaseUrl, verbose });
}
const { outDir, verbose } = config;

try {
await viteBuild({
Expand Down Expand Up @@ -78,6 +68,5 @@ if (import.meta.main) {
.strict()
.parseSync();
const { outDir, verbose } = argv;
const genClient = argv['gen-client'];
await build({ genClient, outDir, verbose });
await build({ outDir, verbose });
}
13 changes: 1 addition & 12 deletions frontend/scripts/dev.ts → packages/frontend/scripts/dev.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import generateAPIClient from './gen-client';
import { createServer } from 'vite';
import { createConfig } from '../vite.config';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

export type DevOptions = {
baseUrl?: string;
host?: string;
verbose?: boolean;
};

const defaults: Required<DevOptions> = {
baseUrl: 'http://localhost:3000/api',
host: 'localhost',
verbose: false,
};

export default async function dev(opts: DevOptions) {
const { baseUrl, host, verbose } = { ...defaults, ...opts };

if (verbose) console.log('Generating API client...');
await generateAPIClient({ baseUrl, verbose });
const { host, verbose } = { ...defaults, ...opts };

if (verbose) console.log('Starting development server...');
const server = await createServer(createConfig(host));
Expand All @@ -30,11 +24,6 @@ export default async function dev(opts: DevOptions) {

if (import.meta.main) {
const argv = yargs(hideBin(process.argv))
.option('base-url', {
type: 'string',
description: 'Base URL for the API',
default: defaults.baseUrl,
})
.option('host', {
type: 'string',
description: 'Host to bind the development server to',
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions packages/frontend/scripts/postinstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import yargs from 'yargs';
import generateAPIClient from './gen-client';
import { hideBin } from 'yargs/helpers';

const defaults = {
verbose: false,
};

export const postinstall = async (overrides: { verbose?: boolean }) => {
const { verbose } = { ...defaults, ...overrides };
// generate client
console.log('Generating API client from OpenAPI schema...');

await generateAPIClient({
baseUrl: process.env.NODE_ENV === 'development' ? 'http://localhost:3000/api' : '/api',
verbose,
});
};
if (import.meta.main) {
const argv = await yargs(hideBin(process.argv))
.option('verbose', {
type: 'boolean',
description: 'Enable verbose output',
default: defaults.verbose,
})
.parse();

await postinstall(argv);
}
Loading