Skip to content

Instantly share code, notes, and snippets.

@joshnuss
Last active March 24, 2023 14:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshnuss/a287981b45cd88f9ec72b3db43b48052 to your computer and use it in GitHub Desktop.
Save joshnuss/a287981b45cd88f9ec72b3db43b48052 to your computer and use it in GitHub Desktop.
Bash aliases for creating a SvelteKit project with Prisma
# Create a vanilla SvelteKit project
# usage: sk <folder-name>
sk() {
pnpm create svelte@latest $1 \
&& cd $1 \
&& pnpm install \
&& git init \
&& git add . \
&& git commit -m 'Initial commit'
}
# Create a SvelteKit project with Prisma configured
# usage: sk-prisma <folder-name>
sk_prisma() {
# replace dashes with underscores and add _dev suffix
DB_NAME=$(echo "$1_dev" | sed s/-/_/g)
DB_URL="postgresql://postgres:postgres@localhost:5432/$DB_NAME?schema=public"
sk $1 \
&& pnpm install -D prisma @prisma/client \
&& pnpm prisma init --url "$DB_URL" \
&& mkdir -p src/lib \
&& echo -e "import { PrismaClient } from '@prisma/client'\n\nexport const db = new PrismaClient()" >> src/lib/db.server.js \
&& git add . \
&& git commit -m 'Added prisma'
}
# function names can't have dashes, but aliases can
alias sk-prisma=sk_prisma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment