From 158f9e097db641f41e446275f5b84eb1db6e26c5 Mon Sep 17 00:00:00 2001 From: April Hall Date: Sat, 4 Jan 2025 16:25:58 -0500 Subject: [PATCH] style: Update .prettierrc --- .prettierrc | 29 +++++----- README.md | 2 + drizzle.config.ts | 14 ++--- eslint.config.js | 44 +++++++-------- package.json | 92 ++++++++++++++++---------------- postcss.config.js | 8 +-- prodServer.ts | 26 ++++----- src/app.d.ts | 14 ++--- src/app.html | 18 +++---- src/lib/hooks.server.ts | 16 +++--- src/lib/server/db/schema.ts | 6 +-- src/lib/server/webSocketUtils.ts | 2 +- src/lib/websocketConfig.ts | 25 +++++---- src/routes/+layout.svelte | 4 +- src/routes/+page.svelte | 62 +++++++++++---------- svelte.config.js | 18 +++---- tailwind.config.ts | 4 +- tsconfig.json | 34 ++++++------ vite.config.ts | 26 ++++----- 19 files changed, 223 insertions(+), 221 deletions(-) diff --git a/.prettierrc b/.prettierrc index 7ebb855..ffff96c 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,15 +1,18 @@ { - "useTabs": true, - "singleQuote": true, - "trailingComma": "none", - "printWidth": 100, - "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"], - "overrides": [ - { - "files": "*.svelte", - "options": { - "parser": "svelte" - } - } - ] + "tabWidth": 2, + "printWidth": 150, + "useTabs": false, + "semi": true, + "singleQuote": true, + "trailingComma": "all", + "bracketSameLine": true, + "plugins": ["prettier-plugin-svelte"], + "overrides": [ + { + "files": "*.svelte", + "options": { + "parser": "svelte" + } + } + ] } diff --git a/README.md b/README.md index 414288f..d43604e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # SVChat + A is a simple chat app built with SvelteKit, Drizzle ORM, and PostgreSQL ## Techstack + ![Techstack](https://go-skill-icons.vercel.app/api/icons?i=daisyui,postgresql,svelte,tailwindcss,ts) diff --git a/drizzle.config.ts b/drizzle.config.ts index 58c6b2f..31a3fe3 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -2,13 +2,13 @@ import { defineConfig } from 'drizzle-kit'; if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set'); export default defineConfig({ - schema: './src/lib/server/db/schema.ts', + schema: './src/lib/server/db/schema.ts', - dbCredentials: { - url: process.env.DATABASE_URL - }, + dbCredentials: { + url: process.env.DATABASE_URL, + }, - verbose: true, - strict: true, - dialect: 'postgresql' + verbose: true, + strict: true, + dialect: 'postgresql', }); diff --git a/eslint.config.js b/eslint.config.js index aa5987f..fc11e45 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -8,27 +8,27 @@ import ts from 'typescript-eslint'; const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url)); export default ts.config( - includeIgnoreFile(gitignorePath), - js.configs.recommended, - ...ts.configs.recommended, - ...svelte.configs['flat/recommended'], - prettier, - ...svelte.configs['flat/prettier'], - { - languageOptions: { - globals: { - ...globals.browser, - ...globals.node - } - } - }, - { - files: ['**/*.svelte'], + includeIgnoreFile(gitignorePath), + js.configs.recommended, + ...ts.configs.recommended, + ...svelte.configs['flat/recommended'], + prettier, + ...svelte.configs['flat/prettier'], + { + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + }, + }, + }, + { + files: ['**/*.svelte'], - languageOptions: { - parserOptions: { - parser: ts.parser - } - } - } + languageOptions: { + parserOptions: { + parser: ts.parser, + }, + }, + }, ); diff --git a/package.json b/package.json index a498d6d..cc9bf94 100644 --- a/package.json +++ b/package.json @@ -1,48 +1,48 @@ { - "name": "chatapp", - "private": true, - "version": "0.0.1", - "type": "module", - "scripts": { - "dev": "vite dev", - "build": "vite build", - "preview": "vite preview", - "start": "PORT=3005 tsm ./prodServer.ts", - "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", - "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "format": "prettier --write .", - "lint": "prettier --check . && eslint .", - "db:migrate": "drizzle-kit generate --config drizzle.config.ts && drizzle-kit push --config drizzle.config.ts", - "db:studio": "drizzle-kit studio" - }, - "devDependencies": { - "@eslint/compat": "^1.2.3", - "@sveltejs/adapter-node": "^5.2.11", - "@sveltejs/kit": "^2.0.0", - "@sveltejs/vite-plugin-svelte": "^4.0.0", - "autoprefixer": "^10.4.20", - "drizzle-kit": "^0.22.0", - "eslint": "^9.7.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-svelte": "^2.36.0", - "globals": "^15.0.0", - "prettier": "^3.3.2", - "prettier-plugin-svelte": "^3.2.6", - "prettier-plugin-tailwindcss": "^0.6.5", - "svelte": "^5.0.0", - "svelte-check": "^4.0.0", - "tailwindcss": "^3.4.9", - "typescript": "^5.0.0", - "typescript-eslint": "^8.0.0", - "vite": "^5.4.11" - }, - "dependencies": { - "daisyui": "^4.12.23", - "drizzle-orm": "^0.33.0", - "express": "^4.21.2", - "postgres": "^3.4.4", - "socket.io": "^4.8.1", - "socket.io-client": "^4.8.1", - "tsm": "^2.3.0" - } + "name": "chatapp", + "private": true, + "version": "0.0.1", + "type": "module", + "scripts": { + "dev": "vite dev", + "build": "vite build", + "preview": "vite preview", + "start": "PORT=3005 tsm ./prodServer.ts", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", + "format": "prettier --write .", + "lint": "prettier --check . && eslint .", + "db:migrate": "drizzle-kit generate --config drizzle.config.ts && drizzle-kit push --config drizzle.config.ts", + "db:studio": "drizzle-kit studio" + }, + "devDependencies": { + "@eslint/compat": "^1.2.3", + "@sveltejs/adapter-node": "^5.2.11", + "@sveltejs/kit": "^2.0.0", + "@sveltejs/vite-plugin-svelte": "^4.0.0", + "autoprefixer": "^10.4.20", + "drizzle-kit": "^0.22.0", + "eslint": "^9.7.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-svelte": "^2.36.0", + "globals": "^15.0.0", + "prettier": "^3.3.2", + "prettier-plugin-svelte": "^3.2.6", + "prettier-plugin-tailwindcss": "^0.6.5", + "svelte": "^5.0.0", + "svelte-check": "^4.0.0", + "tailwindcss": "^3.4.9", + "typescript": "^5.0.0", + "typescript-eslint": "^8.0.0", + "vite": "^5.4.11" + }, + "dependencies": { + "daisyui": "^4.12.23", + "drizzle-orm": "^0.33.0", + "express": "^4.21.2", + "postgres": "^3.4.4", + "socket.io": "^4.8.1", + "socket.io-client": "^4.8.1", + "tsm": "^2.3.0" + } } diff --git a/postcss.config.js b/postcss.config.js index 0f77216..2aa7205 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,6 +1,6 @@ export default { - plugins: { - tailwindcss: {}, - autoprefixer: {} - } + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, }; diff --git a/prodServer.ts b/prodServer.ts index 5a366ff..215b1ed 100644 --- a/prodServer.ts +++ b/prodServer.ts @@ -8,23 +8,23 @@ const server = createServer(app); const io = new Server(server); io.on('connection', (socket) => { - console.log(`[ws:kit] client connected (${socket.id})`); - io!.emit('message', `Hello from SvelteKit ${new Date().toLocaleString()} (${socket.id})`); + console.log(`[ws:kit] client connected (${socket.id})`); + io!.emit('message', `Hello from SvelteKit ${new Date().toLocaleString()} (${socket.id})`); - socket.on('disconnect', () => { - io!.emit('message', `client disconnected (${socket.id})`) - console.log(`[ws:kit] client disconnected (${socket.id})`); - }); + socket.on('disconnect', () => { + io!.emit('message', `client disconnected (${socket.id})`); + console.log(`[ws:kit] client disconnected (${socket.id})`); + }); }); app.use((req, res, next) => { - if (req.path.startsWith('/socket.io/')) { - next(); - } else { - handler(req, res); - } + if (req.path.startsWith('/socket.io/')) { + next(); + } else { + handler(req, res); + } }); server.listen(3005, () => { - console.log('Listening on http://0.0.0.0:3005'); -}); \ No newline at end of file + console.log('Listening on http://0.0.0.0:3005'); +}); diff --git a/src/app.d.ts b/src/app.d.ts index da08e6d..520c421 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,13 +1,13 @@ // See https://svelte.dev/docs/kit/types#app.d.ts // for information about these interfaces declare global { - namespace App { - // interface Error {} - // interface Locals {} - // interface PageData {} - // interface PageState {} - // interface Platform {} - } + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface PageState {} + // interface Platform {} + } } export {}; diff --git a/src/app.html b/src/app.html index 0103ada..40d2843 100644 --- a/src/app.html +++ b/src/app.html @@ -1,11 +1,11 @@ - - - - - %sveltekit.head% - + + + + + %sveltekit.head% + - -
%sveltekit.body%
- + +
%sveltekit.body%
+ diff --git a/src/lib/hooks.server.ts b/src/lib/hooks.server.ts index 58c1b02..9a29ede 100644 --- a/src/lib/hooks.server.ts +++ b/src/lib/hooks.server.ts @@ -5,11 +5,11 @@ import { startupSocketIOServer } from '$lib/websocketConfig'; let io: SocketIOServer | undefined; export const handle = (async ({ event, resolve }) => { - if (!building) { - startupSocketIOServer(event.locals.httpServer); - event.locals.io = io; - } - return resolve(event, { - filterSerializedResponseHeaders: (name) => name === 'content-type' - }); -}) satisfies Handle; \ No newline at end of file + if (!building) { + startupSocketIOServer(event.locals.httpServer); + event.locals.io = io; + } + return resolve(event, { + filterSerializedResponseHeaders: (name) => name === 'content-type', + }); +}) satisfies Handle; diff --git a/src/lib/server/db/schema.ts b/src/lib/server/db/schema.ts index 2178cd7..33778f4 100644 --- a/src/lib/server/db/schema.ts +++ b/src/lib/server/db/schema.ts @@ -1,9 +1,9 @@ import { pgTable, uuid, text } from 'drizzle-orm/pg-core'; export const users = pgTable('users', { - id: uuid('id').primaryKey(), - username: text('username'), + id: uuid('id').primaryKey(), + username: text('username'), displayname: text('display_name'), salt: text('salt'), - hash: text('hash') + hash: text('hash'), }); diff --git a/src/lib/server/webSocketUtils.ts b/src/lib/server/webSocketUtils.ts index c187bdf..1efd890 100644 --- a/src/lib/server/webSocketUtils.ts +++ b/src/lib/server/webSocketUtils.ts @@ -10,7 +10,7 @@ export const GlobalThisWSS = Symbol.for('sveltekit.wss'); export interface ExtendedWebSocket extends WebSocketBase { socketId: string; // userId: string; -}; +} // You can define server-wide functions or class instances here // export interface ExtendedServer extends Server {}; diff --git a/src/lib/websocketConfig.ts b/src/lib/websocketConfig.ts index e0695f4..c8e2583 100644 --- a/src/lib/websocketConfig.ts +++ b/src/lib/websocketConfig.ts @@ -3,18 +3,17 @@ import type { HttpServer } from 'vite'; let io: SocketIOServer | undefined; - export function startupSocketIOServer(httpServer: HttpServer | null) { - if (io) return; - console.log('[ws:kit] setup'); - io = new SocketIOServer(httpServer); - io.on('connection', (socket) => { - console.log(`[ws:kit] client connected (${socket.id})`); - io!.emit('message', `Hello from SvelteKit ${new Date().toLocaleString()} (${socket.id})`); + if (io) return; + console.log('[ws:kit] setup'); + io = new SocketIOServer(httpServer); + io.on('connection', (socket) => { + console.log(`[ws:kit] client connected (${socket.id})`); + io!.emit('message', `Hello from SvelteKit ${new Date().toLocaleString()} (${socket.id})`); - socket.on('disconnect', () => { - io!.emit('message', `client disconnected (${socket.id})`) - console.log(`[ws:kit] client disconnected (${socket.id})`); - }); - }); -} \ No newline at end of file + socket.on('disconnect', () => { + io!.emit('message', `client disconnected (${socket.id})`); + console.log(`[ws:kit] client disconnected (${socket.id})`); + }); + }); +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 9b776b7..34832d6 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,6 +1,6 @@ {@render children()} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 24def05..611d013 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,44 +1,42 @@
-

# SvelteKit with Socket.IO Integration

+

# SvelteKit with Socket.IO Integration

- + -
    - {#each log as event} -
  • {event}
  • - {/each} -
-
\ No newline at end of file + + diff --git a/svelte.config.js b/svelte.config.js index e0a641e..a9692c1 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -3,16 +3,16 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; /** @type {import('@sveltejs/kit').Config} */ const config = { - // Consult https://svelte.dev/docs/kit/integrations - // for more information about preprocessors - preprocess: vitePreprocess(), + // Consult https://svelte.dev/docs/kit/integrations + // for more information about preprocessors + preprocess: vitePreprocess(), - kit: { - // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. - // If your environment is not supported, or you settled on a specific environment, switch out the adapter. - // See https://svelte.dev/docs/kit/adapters for more information about adapters. - adapter: adapter() - } + kit: { + // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. + // If your environment is not supported, or you settled on a specific environment, switch out the adapter. + // See https://svelte.dev/docs/kit/adapters for more information about adapters. + adapter: adapter(), + }, }; export default config; diff --git a/tailwind.config.ts b/tailwind.config.ts index ba2bd18..812c5a2 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -2,6 +2,6 @@ import type { Config } from 'tailwindcss'; import daisyui from 'daisyui'; export default { - content: ['./src/**/*.{html,js,svelte,ts}'], - plugins: [daisyui] + content: ['./src/**/*.{html,js,svelte,ts}'], + plugins: [daisyui], } satisfies Config; diff --git a/tsconfig.json b/tsconfig.json index 0b2d886..f4d0a0e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,19 @@ { - "extends": "./.svelte-kit/tsconfig.json", - "compilerOptions": { - "allowJs": true, - "checkJs": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "moduleResolution": "bundler" - } - // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias - // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files - // - // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes - // from the referenced tsconfig.json - TypeScript does not merge them in + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "moduleResolution": "bundler" + } + // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias + // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files + // + // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes + // from the referenced tsconfig.json - TypeScript does not merge them in } diff --git a/vite.config.ts b/vite.config.ts index 2a9d30b..2cf57b7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,16 +3,16 @@ import { defineConfig } from 'vite'; import { startupSocketIOServer } from './src/lib/websocketConfig'; export default defineConfig({ - plugins: [ - sveltekit(), - { - name: 'integratedSocketIOServer', - configureServer(server) { - startupSocketIOServer(server.httpServer); - }, - configurePreviewServer(server) { - startupSocketIOServer(server.httpServer); - } - }, - ] -}); \ No newline at end of file + plugins: [ + sveltekit(), + { + name: 'integratedSocketIOServer', + configureServer(server) { + startupSocketIOServer(server.httpServer); + }, + configurePreviewServer(server) { + startupSocketIOServer(server.httpServer); + }, + }, + ], +});