Skip to content

Commit

Permalink
Use biome for formatting for the javascript projects (#12)
Browse files Browse the repository at this point in the history
* Add zod for types or whatever

* wip

* Remove type defs from queries/decoders

* Further cleanup

* Remove commented out code + minor code tweak

* Add basic biome setup

* wip

* Simplify

* lint & format using biome

* Refine config

* Tray once more to ignore test-content

* Use original scripts/test-content

* Add format command

* Add format command to frontend

* Remove author/license from package.json

* update pacakge-lock.json

* Use biome 1.8.0

* enable css linter

* Add linting to api

Plus fix some biome complaints

* Simplify biome.jsonc files

And format code

* Add github workflow

* Fix build

* Add build step for ci

* Oh npm, you do like the word `run`

* Skip build if no build present

---------

Co-authored-by: Brett Beutell <[email protected]>
  • Loading branch information
flenter and brettimus authored Jun 5, 2024
1 parent ca75082 commit 1833002
Show file tree
Hide file tree
Showing 71 changed files with 10,973 additions and 5,485 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build_frontends.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will be triggered by a GitHub pull-request.
---
name: Build node packages

on:
pull_request:
branches: ["*"]
push:
branches: ["main", "release-*"]

env:
CARGO_TERM_COLOR: always
FORCE_COLOR: true

jobs:
build_packages:
name: Build packages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: lts/*
cache: npm
- name: Install dependencies
run: npm ci --workspaces

- name: Lint all workspaces
run: npm run lint:ci --workspaces

- name: Build all workspaces
run: npm run build --workspaces --if-present
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ yarn-error.log

# Personal files
mizu.boots.code-workspace
.vscode
node_modules
start-dev.sh
18 changes: 18 additions & 0 deletions api/biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.0/schema.json",
"extends": ["../biome.jsonc"],
"css": {
"linter": {
"enabled": true
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"files": {
"ignore": ["meta/*.json", "test-content/*.*"]
}
}
16 changes: 8 additions & 8 deletions api/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Config } from 'drizzle-kit';
import { config } from 'dotenv';
import { config } from "dotenv";
import type { Config } from "drizzle-kit";

config({ path: '.dev.vars' });
config({ path: ".dev.vars" });

export default {
schema: './src/db/schema.ts',
out: 'drizzle',
dialect: 'sqlite',
schema: "./src/db/schema.ts",
out: "drizzle",
dialect: "sqlite",
dbCredentials: {
// biome-ignore lint/style/noNonNullAssertion: we want this to fail if not defined
url: process.env.DATABASE_URL!,
}
} satisfies Config;
},
} satisfies Config;
22 changes: 11 additions & 11 deletions api/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { createClient } from '@libsql/client';
import { config } from 'dotenv';
import { migrate } from 'drizzle-orm/libsql/migrator';
import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from "@libsql/client";
import { config } from "dotenv";
import { drizzle } from "drizzle-orm/libsql";
import { migrate } from "drizzle-orm/libsql/migrator";

config({ path: '.dev.vars' });
config({ path: ".dev.vars" });

if (!process.env.DATABASE_URL) {
console.error('DATABASE_URL not defined');
console.error("DATABASE_URL not defined");
process.exit(1);
}

const databaseUrl = process.env.DATABASE_URL;
const sql = createClient({
url: databaseUrl
})
url: databaseUrl,
});
const db = drizzle(sql);

const main = async () => {
try {
await migrate(db, { migrationsFolder: 'drizzle' });
console.log('Migration complete');
await migrate(db, { migrationsFolder: "drizzle" });
console.log("Migration complete");
} catch (error) {
console.log(error);
}
process.exit(0);
};

main();
main();
7 changes: 6 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"type": "module",
"name": "api",
"version": "0.0.1",
"scripts": {
"dev": "tsx watch src/index.node.ts",
"db:generate": "drizzle-kit generate",
"db:migrate": "tsx migrate.ts",
"db:seed": "tsx scripts/seed.ts"
"db:seed": "tsx scripts/seed.ts",
"format": "biome check . --write",
"lint": "biome lint . && tsc --noEmit",
"lint:ci": "biome ci . #api"
},
"dependencies": {
"@hono/node-server": "^1.11.1",
Expand Down
14 changes: 7 additions & 7 deletions api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Hono } from "hono";
import { env } from "hono/adapter";
import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import { Hono } from "hono";
import { env } from "hono/adapter";
import { logger } from "hono/logger";
import type { WebSocket } from "ws";

import * as schema from "./db/schema";
import { Bindings, Variables } from "./lib/types";
import type { Bindings, Variables } from "./lib/types";
import dependencies from "./routes/dependencies";
import issues from "./routes/issues";
import logs from "./routes/logs";
import openai from "./routes/openai";
import source from "./routes/source";
import { logger } from "hono/logger";
import dependencies from "./routes/dependencies";
import issues from "./routes/issues";

export function createApp(wsConnections?: Set<WebSocket>) {
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>();

// biome-ignore lint/suspicious/noExplicitAny:
// this is a bucket of any kind of errors that we just want to log
// and make available on a route
// biome-ignore lint/suspicious/noExplicitAny:
const DB_ERRORS: Array<any> = [];

// NOTE - This middleware adds `db` on the context so we don't have to initiate it every time
Expand Down
12 changes: 4 additions & 8 deletions api/src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sql } from "drizzle-orm";
import { text, integer, sqliteTable } from "drizzle-orm/sqlite-core";
import type { Endpoints } from "@octokit/types";
import { sql } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";

Expand All @@ -22,12 +22,8 @@ export const mizuLogs = sqliteTable("mizu_logs", {
ignored: integer("ignored", { mode: "boolean" }).default(false),
args: text("args", { mode: "json" }), // NOTE - Should only be present iff message is a string
callerLocation: text("caller_location", { mode: "json" }),
createdAt: text("created_at")
.notNull()
.default(sql`(CURRENT_TIMESTAMP)`),
updatedAt: text("updated_at")
.notNull()
.default(sql`(CURRENT_TIMESTAMP)`),
createdAt: text("created_at").notNull().default(sql`(CURRENT_TIMESTAMP)`),
updatedAt: text("updated_at").notNull().default(sql`(CURRENT_TIMESTAMP)`),
matchingIssues: text("matching_issues", { mode: "json" }).$type<
number[] | null
>(),
Expand Down
6 changes: 4 additions & 2 deletions api/src/index.node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createServer } from "node:http";
import { serve } from "@hono/node-server";
import { config } from "dotenv";

import { createApp } from "./app";
import { type WebSocket, WebSocketServer } from "ws";
import { createApp } from "./app";

config({ path: ".dev.vars" });

Expand All @@ -18,7 +19,8 @@ const port = 8788;
const server = serve({
fetch: app.fetch,
port,
});
createServer,
}) as ReturnType<typeof createServer>;
console.log(`Server is running: http://localhost:${port}`);

const wss = new WebSocketServer({ server });
Expand Down
Loading

0 comments on commit 1833002

Please sign in to comment.