style: Update .prettierrc
This commit is contained in:
parent
bc1094d70c
commit
158f9e097d
29
.prettierrc
29
.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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
# SVChat
|
||||
|
||||
A is a simple chat app built with SvelteKit, Drizzle ORM, and PostgreSQL
|
||||
|
||||
## Techstack
|
||||
|
||||

|
||||
|
@ -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',
|
||||
});
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
92
package.json
92
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"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {}
|
||||
}
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
};
|
||||
|
@ -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');
|
||||
console.log('Listening on http://0.0.0.0:3005');
|
||||
});
|
14
src/app.d.ts
vendored
14
src/app.d.ts
vendored
@ -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 {};
|
||||
|
18
src/app.html
18
src/app.html
@ -1,11 +1,11 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<!--
|
||||
|
||||
SVChat -- A is a simple chat app built with SvelteKit, Drizzle ORM, and PostgreSQL
|
||||
@ -25,7 +25,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
-->
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -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'
|
||||
});
|
||||
if (!building) {
|
||||
startupSocketIOServer(event.locals.httpServer);
|
||||
event.locals.io = io;
|
||||
}
|
||||
return resolve(event, {
|
||||
filterSerializedResponseHeaders: (name) => name === 'content-type',
|
||||
});
|
||||
}) satisfies Handle;
|
@ -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'),
|
||||
});
|
||||
|
@ -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<ExtendedWebSocket> {};
|
||||
|
@ -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})`);
|
||||
});
|
||||
});
|
||||
socket.on('disconnect', () => {
|
||||
io!.emit('message', `client disconnected (${socket.id})`);
|
||||
console.log(`[ws:kit] client disconnected (${socket.id})`);
|
||||
});
|
||||
});
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import '../app.css';
|
||||
let { children } = $props();
|
||||
import '../app.css';
|
||||
let { children } = $props();
|
||||
</script>
|
||||
|
||||
{@render children()}
|
||||
|
@ -1,44 +1,42 @@
|
||||
<script lang="ts">
|
||||
import { io } from 'socket.io-client';
|
||||
import { io } from 'socket.io-client';
|
||||
|
||||
let socket: ReturnType<typeof io> | null = null;
|
||||
let log: string[] = [];
|
||||
let socket: ReturnType<typeof io> | null = null;
|
||||
let log: string[] = [];
|
||||
|
||||
function logEvent(str: string) {
|
||||
log = [...log, str];
|
||||
}
|
||||
function logEvent(str: string) {
|
||||
log = [...log, str];
|
||||
}
|
||||
|
||||
function establishSocketIOConnection() {
|
||||
if (socket) return;
|
||||
socket = io();
|
||||
function establishSocketIOConnection() {
|
||||
if (socket) return;
|
||||
socket = io();
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log('[ws] connection open');
|
||||
logEvent('[ws] connection open');
|
||||
});
|
||||
socket.on('connect', () => {
|
||||
console.log('[ws] connection open');
|
||||
logEvent('[ws] connection open');
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('[ws] connection closed');
|
||||
logEvent('[ws] connection closed');
|
||||
});
|
||||
socket.on('disconnect', () => {
|
||||
console.log('[ws] connection closed');
|
||||
logEvent('[ws] connection closed');
|
||||
});
|
||||
|
||||
socket.on('message', (data: string) => {
|
||||
console.log('[ws] message received', data);
|
||||
logEvent(`[ws] message received: ${data}`);
|
||||
});
|
||||
}
|
||||
socket.on('message', (data: string) => {
|
||||
console.log('[ws] message received', data);
|
||||
logEvent(`[ws] message received: ${data}`);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<h1 class="text-lg"># SvelteKit with Socket.IO Integration</h1>
|
||||
<h1 class="text-lg"># SvelteKit with Socket.IO Integration</h1>
|
||||
|
||||
<button class="btn btn-primary" on:click={() => establishSocketIOConnection()}>
|
||||
Establish Socket.IO connection
|
||||
</button>
|
||||
<button class="btn btn-primary" on:click={() => establishSocketIOConnection()}> Establish Socket.IO connection </button>
|
||||
|
||||
<ul>
|
||||
{#each log as event}
|
||||
<li>{event}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
<ul>
|
||||
{#each log as event}
|
||||
<li>{event}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</main>
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
]
|
||||
plugins: [
|
||||
sveltekit(),
|
||||
{
|
||||
name: 'integratedSocketIOServer',
|
||||
configureServer(server) {
|
||||
startupSocketIOServer(server.httpServer);
|
||||
},
|
||||
configurePreviewServer(server) {
|
||||
startupSocketIOServer(server.httpServer);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
Loading…
Reference in New Issue
Block a user