Skip to content

Commit

Permalink
프로젝트 셋업
Browse files Browse the repository at this point in the history
  • Loading branch information
devunt committed Jul 19, 2024
0 parents commit 442dddd
Show file tree
Hide file tree
Showing 62 changed files with 723 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv_if_exists .env.local
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store

node_modules/
.turbo/

.env.local
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bun run lint-staged
11 changes: 11 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"github.copilot",
"rohit-gohri.format-code-action",
"streetsidesoftware.code-spell-checker",
"svelte.svelte-vscode",
"EditorConfig.EditorConfig"
]
}
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Node",
"type": "node",
"request": "launch",
"runtimeExecutable": "bun",
"runtimeArgs": ["run", "dev"],
"outputCapture": "std"
}
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.formatDocument": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
"eslint.enable": true,
"eslint.format.enable": true,
"eslint.useFlatConfig": true,
"eslint.validate": ["javascript", "typescript", "svelte"],
"prettier.documentSelectors": ["**/*"],
"svelte.enable-ts-plugin": true,
"svelte.plugin.svelte.defaultScriptLanguage": "ts",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}
24 changes: 24 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@readable/api",
"version": "0.0.1",
"private": true,
"type": "module",
"exports": {
"./trpc": "./src/router.ts"
},
"scripts": {
"dev": "bun run --hot src/main.ts"
},
"dependencies": {
"@hono/trpc-server": "^0.3.2",
"@trpc/server": "^11.0.0-rc.466",
"hono": "^4.5.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@readable/lintconfig": "workspace:*",
"@readable/tsconfig": "workspace:*",
"@types/bun": "^1.1.6",
"typescript": "^5.5.3"
}
}
8 changes: 8 additions & 0 deletions apps/api/src/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { FetchCreateContextFnOptions } from '@trpc/server/adapters/fetch';

export function createContext({ req, resHeaders }: FetchCreateContextFnOptions) {
const user = { name: req.headers.get('username') ?? 'anonymous' };
return { req, resHeaders, user };
}

export type Context = Awaited<ReturnType<typeof createContext>>;
20 changes: 20 additions & 0 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { trpcServer } from '@hono/trpc-server';
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { createContext } from './context';
import { appRouter } from './router';

const app = new Hono();

app.use('*', cors());

app.use(
'/trpc/*',
trpcServer({
router: appRouter,
createContext,
}),
);

// eslint-disable-next-line import/no-default-export
export default app;
36 changes: 36 additions & 0 deletions apps/api/src/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { initTRPC } from '@trpc/server';
import { z } from 'zod';
import type { Context } from './context';

type User = {
id: string;
name: string;
bio?: string;
};

const users: Record<string, User> = {};

export const t = initTRPC.context<Context>().create();

export const appRouter = t.router({
getUserById: t.procedure.input(z.string()).query((opts) => {
return opts.input; // input type is string
}),
createUser: t.procedure
// validate input with Zod
.input(
z.object({
name: z.string().min(3),
bio: z.string().max(142).optional(),
}),
)
.mutation((opts) => {
const id = Date.now().toString();
const user: User = { id, ...opts.input };
users[user.id] = user;
return user;
}),
});

// export type definition of API
export type AppRouter = typeof appRouter;
14 changes: 14 additions & 0 deletions apps/api/src/trpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { initTRPC } from '@trpc/server';

/**
* Initialization of tRPC backend
* Should be done only once per backend!
*/
const t = initTRPC.create();

/**
* Export reusable router and procedure helpers
* that can be used throughout the router
*/
export const router = t.router;
export const publicProcedure = t.procedure;
3 changes: 3 additions & 0 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@readable/tsconfig"]
}
9 changes: 9 additions & 0 deletions apps/dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Output
.output
.vercel
/.svelte-kit
/build

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
30 changes: 30 additions & 0 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@readable/dashboard",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"build": "vite build",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"dev": "vite dev",
"preview": "vite preview"
},
"dependencies": {
"@trpc/client": "^11.0.0-rc.466",
"@trpc/server": "^11.0.0-rc.466"
},
"devDependencies": {
"@readable/api": "workspace:*",
"@readable/lintconfig": "workspace:*",
"@readable/tsconfig": "workspace:*",
"@sveltejs/adapter-auto": "^3.2.2",
"@sveltejs/kit": "^2.5.18",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"svelte": "^4.2.18",
"svelte-check": "^3.8.4",
"tslib": "^2.6.3",
"typescript": "^5.5.3",
"vite": "^5.3.4"
}
}
13 changes: 13 additions & 0 deletions apps/dashboard/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
12 changes: 12 additions & 0 deletions apps/dashboard/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!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>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
10 changes: 10 additions & 0 deletions apps/dashboard/src/lib/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '@readable/api/trpc';

export const client = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:3000/trpc',
}),
],
});
1 change: 1 addition & 0 deletions apps/dashboard/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.
7 changes: 7 additions & 0 deletions apps/dashboard/src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { client } from '$lib/client';

export const load = async () => {
return {
user: await client.getUserById.query('1'),
};
};
9 changes: 9 additions & 0 deletions apps/dashboard/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
export let data;
$: console.log(data.user);
</script>

dashboard
<br />
{data.user}
Binary file added apps/dashboard/static/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions apps/dashboard/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
export default {
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
},
};
3 changes: 3 additions & 0 deletions apps/dashboard/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./.svelte-kit/tsconfig.json", "@readable/tsconfig"]
}
7 changes: 7 additions & 0 deletions apps/dashboard/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
plugins: [sveltekit()],
server: { port: 4100 },
});
9 changes: 9 additions & 0 deletions apps/usersite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Output
.output
.vercel
/.svelte-kit
/build

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
25 changes: 25 additions & 0 deletions apps/usersite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@readable/usersite",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"build": "vite build",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"dev": "vite dev",
"preview": "vite preview"
},
"devDependencies": {
"@readable/lintconfig": "workspace:*",
"@readable/tsconfig": "workspace:*",
"@sveltejs/adapter-auto": "^3.2.2",
"@sveltejs/kit": "^2.5.18",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"svelte": "^4.2.18",
"svelte-check": "^3.8.4",
"tslib": "^2.6.3",
"typescript": "^5.5.3",
"vite": "^5.3.4"
}
}
13 changes: 13 additions & 0 deletions apps/usersite/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
12 changes: 12 additions & 0 deletions apps/usersite/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!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>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
1 change: 1 addition & 0 deletions apps/usersite/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.
1 change: 1 addition & 0 deletions apps/usersite/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usersite
Binary file added apps/usersite/static/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions apps/usersite/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
export default {
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
},
};
3 changes: 3 additions & 0 deletions apps/usersite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./.svelte-kit/tsconfig.json", "@readable/tsconfig"]
}
7 changes: 7 additions & 0 deletions apps/usersite/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
plugins: [sveltekit()],
server: { port: 4200 },
});
9 changes: 9 additions & 0 deletions apps/website/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Output
.output
.vercel
/.svelte-kit
/build

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
Loading

0 comments on commit 442dddd

Please sign in to comment.