This commit is contained in:
nomadics9 2024-06-13 00:30:13 +03:00
commit 32a0ec3e77
24 changed files with 378 additions and 0 deletions

13
.gitignore vendored Normal file
View file

@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
pb_data
pb_migrations
.vscode

1
.npmrc Normal file
View file

@ -0,0 +1 @@
engine-strict=true

4
.prettierignore Normal file
View file

@ -0,0 +1,4 @@
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

8
.prettierrc Normal file
View file

@ -0,0 +1,8 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}

65
README.md Normal file
View file

@ -0,0 +1,65 @@
# Spock - Svelte + Pocketbase
My boilerplate for
<img src="./git_assets/spock.jpg" align="center" height="64" width="48" ></a>
1. Sveltekit + Pocketbase DB
2. Tailwindcss
3. SkeletonUI
# Auth Ready
### Snippet from login.svelete component - populating name and avatar from Google provider
```typescript
<script lang="ts">
import { currentUser, pb } from '$lib/pocketbase';
async function login() {
try {
const authData = await pb.collection('users').authWithOAuth2({ provider: 'google' });
const meta = authData.meta;
console.log(meta)
if (meta?.isNew) {
const formData = new FormData();
const response = await fetch(meta.avatarUrl);
if (response.ok) {
const file = await response.blob();
formData.append('avatar', file);
}
formData.append('name', meta.name);
await pb.collection('users').update(authData.record.id, formData);
}
} catch (err) {
console.error(err);
}
}
function signOut() {
pb.authStore.clear();
}
</script>
```
### currentUser as a store to use example ``` $currentUser.avatar ```
```ts
import { env } from '$env/dynamic/public'
import PocketBase from 'pocketbase'
import { writable } from 'svelte/store'
export const pb = new PocketBase(env.PUBLIC_DB_URL)
export const currentUser = writable(pb.authStore.model)
pb.authStore.onChange((auth) => {
//console.log('auth changed ', auth)
currentUser.set(pb.authStore.model)
})
```
### use .env for pocketbase URL
```sh
PUBLIC_DB_URL=http://localhost:8090
```

BIN
bun.lockb Executable file

Binary file not shown.

33
eslint.config.js Normal file
View file

@ -0,0 +1,33 @@
import js from '@eslint/js';
import ts from 'typescript-eslint';
import svelte from 'eslint-plugin-svelte';
import prettier from 'eslint-config-prettier';
import globals from 'globals';
/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
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
}
}
},
{
ignores: ['build/', '.svelte-kit/', 'dist/']
}
];

BIN
git_assets/spock.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

47
package.json Normal file
View file

@ -0,0 +1,47 @@
{
"name": "pocketbaseapp",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "^8.56.7",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.36.0",
"globals": "^15.0.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"typescript-eslint": "^8.0.0-alpha.20",
"vite": "^5.0.3",
"postcss": "8.4.38",
"autoprefixer": "10.4.19",
"tailwindcss": "3.4.4",
"@skeletonlabs/skeleton": "2.10.0",
"@skeletonlabs/tw-plugin": "0.4.0",
"vite-plugin-tailwind-purgecss": "0.3.3",
"@tailwindcss/typography": "0.5.13",
"@tailwindcss/forms": "0.5.7",
"@types/node": "20.14.2"
},
"type": "module",
"dependencies": {
"@floating-ui/dom": "1.6.5",
"highlight.js": "11.9.0",
"pocketbase": "^0.21.3"
}
}

6
postcss.config.cjs Normal file
View file

@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

9
src/app.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {
// interface Locals {}
// interface PageData {}
// interface Error {}
// interface Platform {}
}

12
src/app.html Normal file
View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover" data-theme="skeleton">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

11
src/app.postcss Normal file
View file

@ -0,0 +1,11 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind variants;
/* gold-nouveau theme */
@font-face {
font-family: 'Quicksand';
src: url('/fonts/Quicksand.ttf');
font-display: swap;
}

1
src/lib/index.ts Normal file
View file

@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.

42
src/lib/login.svelte Normal file
View file

@ -0,0 +1,42 @@
<script lang="ts">
import { currentUser, pb } from '$lib/pocketbase';
async function login() {
try {
const authData = await pb.collection('users').authWithOAuth2({ provider: 'google' });
const meta = authData.meta;
console.log(meta)
if (meta?.isNew) {
const formData = new FormData();
const response = await fetch(meta.avatarUrl);
if (response.ok) {
const file = await response.blob();
formData.append('avatar', file);
}
formData.append('name', meta.name);
await pb.collection('users').update(authData.record.id, formData);
}
} catch (err) {
console.error(err);
}
}
function signOut() {
pb.authStore.clear();
}
</script>
{#if $currentUser}
<h1>Signed in as {$currentUser.name}</h1>
<img src={pb.files.getUrl($currentUser, $currentUser.avatar)} alt={$currentUser.name} class="mx-auto rounded-xl shadow-lg" />
<button on:click={signOut} class="btn variant-filled-warning">Log out</button>
{:else}
<h1>Please Login</h1>
<button class="btn variant-outline-primary" on:click={login}> Login using Google </button>
{/if}

12
src/lib/pocketbase.ts Normal file
View file

@ -0,0 +1,12 @@
import { env } from '$env/dynamic/public'
import PocketBase from 'pocketbase'
import { writable } from 'svelte/store'
export const pb = new PocketBase(env.PUBLIC_DB_URL)
export const currentUser = writable(pb.authStore.model)
pb.authStore.onChange((auth) => {
//console.log('auth changed ', auth)
currentUser.set(pb.authStore.model)
})

28
src/routes/+layout.svelte Normal file
View file

@ -0,0 +1,28 @@
<script lang="ts">
import '../app.postcss';
// Highlight JS
import hljs from 'highlight.js/lib/core';
import 'highlight.js/styles/github-dark.css';
import { storeHighlightJs } from '@skeletonlabs/skeleton';
import xml from 'highlight.js/lib/languages/xml'; // for HTML
import css from 'highlight.js/lib/languages/css';
import javascript from 'highlight.js/lib/languages/javascript';
import typescript from 'highlight.js/lib/languages/typescript';
hljs.registerLanguage('xml', xml); // for HTML
hljs.registerLanguage('css', css);
hljs.registerLanguage('javascript', javascript);
hljs.registerLanguage('typescript', typescript);
storeHighlightJs.set(hljs);
// Floating UI for Popups
import { computePosition, autoUpdate, flip, shift, offset, arrow } from '@floating-ui/dom';
import { storePopup } from '@skeletonlabs/skeleton';
storePopup.set({ computePosition, autoUpdate, flip, shift, offset, arrow });
</script>
<div class="h-screen flex justify-center mx-auto items-center">
<div class="card variant-soft-surface p-6 mx-auto items-center text-center space-y-4">
<slot />
</div>
</div>

7
src/routes/+page.svelte Normal file
View file

@ -0,0 +1,7 @@
<script lang="ts">
import Login from '$lib/login.svelte';
</script>
<Login></Login>

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
static/fonts/Quicksand.ttf Normal file

Binary file not shown.

18
svelte.config.js Normal file
View file

@ -0,0 +1,18 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte'],
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: [vitePreprocess()],
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;

35
tailwind.config.ts Normal file
View file

@ -0,0 +1,35 @@
import { join } from 'path'
import type { Config } from 'tailwindcss'
import forms from '@tailwindcss/forms';
import typography from '@tailwindcss/typography';
import { skeleton } from '@skeletonlabs/tw-plugin'
export default {
darkMode: 'class',
content: ['./src/**/*.{html,js,svelte,ts}', join(require.resolve('@skeletonlabs/skeleton'), '../**/*.{html,js,svelte,ts}')],
theme: {
extend: {},
},
plugins: [
forms,
typography,
skeleton({
themes: {
preset: [
{
name: 'skeleton',
enhancements: true,
},
{
name: 'wintry',
enhancements: true,
},
{
name: 'gold-nouveau',
enhancements: true,
},
],
},
}),
],
} satisfies Config;

19
tsconfig.json Normal file
View file

@ -0,0 +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://kit.svelte.dev/docs/configuration#alias
// except $lib which is handled by https://kit.svelte.dev/docs/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
}

7
vite.config.ts Normal file
View file

@ -0,0 +1,7 @@
import { purgeCss } from 'vite-plugin-tailwind-purgecss';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit(), purgeCss()]
});