Skip to content

Commit 99f1d1d

Browse files
committed
Cloned from 112-1-hack2-fallback/student-version
0 parents  commit 99f1d1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2567
-0
lines changed

.env.example

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
POSTGRES_URL=postgres://postgres:postgres@localhost:5432/hack2
2+
3+
AUTH_SECRET=
4+
AUTH_GITHUB_ID=
5+
AUTH_GITHUB_SECRET=
6+
7+
NEXT_PUBLIC_BASE_URL=http://localhost:3000

.eslintrc.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": ["*.mjs", "*.ts", "*.tsx"],
5+
"parserOptions": {
6+
"project": "tsconfig.json"
7+
}
8+
}
9+
],
10+
"ignorePatterns": ["**/components/ui"],
11+
"parser": "@typescript-eslint/parser",
12+
"parserOptions": {
13+
"project": "./tsconfig.json"
14+
},
15+
"plugins": ["react", "@typescript-eslint"],
16+
"extends": [
17+
"next/core-web-vitals",
18+
"eslint:recommended",
19+
"plugin:@typescript-eslint/recommended",
20+
"plugin:react/recommended",
21+
"plugin:react-hooks/recommended",
22+
"prettier"
23+
],
24+
"rules": {
25+
"@typescript-eslint/consistent-type-imports": "warn",
26+
"react/react-in-jsx-scope": "off",
27+
"react/no-unescaped-entities": "off",
28+
"react/function-component-definition": [
29+
"warn",
30+
{
31+
"namedComponents": "function-declaration",
32+
"unnamedComponents": "arrow-function"
33+
}
34+
],
35+
"@typescript-eslint/no-non-null-assertion": "off"
36+
}
37+
}

.gitignore

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
37+
38+
# postgresql
39+
/pg-data
40+
41+
# playwright
42+
/test-results/
43+
/playwright-report/
44+
/blob-report/
45+
/playwright/.cache/
46+
/results.json

.prettierrc.cjs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
plugins: [
3+
require.resolve("@trivago/prettier-plugin-sort-imports"),
4+
require.resolve("prettier-plugin-tailwindcss"),
5+
],
6+
importOrder: ["^react", "^next", "<THIRD_PARTY_MODULES>", "^@\\/", "^\\.\\/"],
7+
importOrderSeparation: true,
8+
};

README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Run the project
2+
3+
## Install dependencies
4+
5+
```bash
6+
yarn
7+
```
8+
9+
## Environment variables
10+
11+
Create a `.env.local` file in the root of the project and add the following variables:
12+
13+
```bash
14+
POSTGRES_URL=postgres://postgres:postgres@localhost:5432/hack2
15+
16+
AUTH_SECRET=<ANY_RANDOM_STRING>
17+
AUTH_GITHUB_ID=
18+
AUTH_GITHUB_SECRET=
19+
20+
NEXT_PUBLIC_BASE_URL=http://localhost:3000
21+
```
22+
23+
### Get Github OAuth credentials (Optional)
24+
25+
本次考試不會評分 Github 登入的部分,但是如果懶得打帳號密碼,可以參考以下步驟:
26+
27+
- Go to `Settings` tab of your Github account
28+
- Click `Developer settings` on the left sidebar
29+
- Click `OAuth Apps` on the left sidebar
30+
- Click `New OAuth App`
31+
- Enter the following information:
32+
- `Application name`: `Notion Clone` (or any name you like)
33+
- `Homepage URL`: `http://localhost:3000`
34+
- `Authorization callback URL`: `http://localhost:3000/api/auth/callback/github`
35+
- Click `Register application`
36+
- Copy the `Client ID` and `Client Secret` to your `.env.local` file:
37+
38+
```text
39+
AUTH_GITHUB_ID=<Client ID>
40+
AUTH_GITHUB_SECRET=<Client Secret>
41+
```
42+
43+
Note that in NextAuth v5, the prefix `AUTH_` is required for the env variables.
44+
45+
Note that you do not have to add those keys to `src/lib/env/private.ts` since they are automatically handled by NextAuth.
46+
47+
## Database
48+
49+
1. Start database
50+
51+
```bash
52+
docker compose up -d
53+
```
54+
55+
2. Run migrations
56+
57+
```bash
58+
yarn migrate
59+
```
60+
61+
## Start the server
62+
63+
```bash
64+
yarn dev
65+
```
66+
67+
## Run tests
68+
69+
```bash
70+
yarn playwright install chromium # Install Chromium (if not already installed)
71+
yarn playwright install-deps chromium # Install Chromium dependencies (if not already installed)
72+
yarn test
73+
```

components.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "new-york",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.ts",
8+
"css": "src/app/globals.css",
9+
"baseColor": "slate",
10+
"cssVariables": true
11+
},
12+
"aliases": {
13+
"components": "@/components",
14+
"utils": "@/lib/utils/shadcn"
15+
}
16+
}

docker-compose.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: "3.1"
2+
3+
services:
4+
postgresql:
5+
image: postgres:16
6+
environment:
7+
POSTGRES_DB: hack2
8+
POSTGRES_USER: postgres
9+
POSTGRES_PASSWORD: postgres
10+
PGDATA: /var/lib/postgresql/data
11+
volumes:
12+
- ./pg-data:/var/lib/postgresql/data
13+
ports:
14+
- "5432:5432"
15+
16+
# adminer is a simple frontend for you to interact with the database
17+
adminer:
18+
image: adminer
19+
ports:
20+
- 8080:8080

drizzle.config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import dotenv from "dotenv";
2+
import type { Config } from "drizzle-kit";
3+
4+
// this file is for drizzle-kit, which is used to do our database migrations
5+
dotenv.config({ path: "./.env.local" });
6+
7+
if (!process.env.POSTGRES_URL) {
8+
throw new Error("POSTGRES_URL must be defined in .env.local");
9+
}
10+
11+
export default {
12+
schema: "./src/db/schema.ts",
13+
out: "./drizzle",
14+
driver: "pg",
15+
dbCredentials: { connectionString: process.env.POSTGRES_URL },
16+
} satisfies Config;

gen-result.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const fs = require("fs");
2+
3+
try {
4+
const jsonString = fs.readFileSync("test-results/test-results.json");
5+
const jsonObject = JSON.parse(jsonString);
6+
7+
const tests = jsonObject.suites
8+
.map((suite) =>
9+
suite.specs.map((spec) => {
10+
const match = spec.title.match(/^(\d+\.\d+) (.*) \((\d+)%\)$/);
11+
const status = spec.tests[0].results[0].status;
12+
return {
13+
score: status === "passed" ? parseInt(match[3], 10) : 0,
14+
max_score: parseInt(match[3], 10),
15+
status,
16+
name: match[2],
17+
name_format: "text",
18+
number: match[1],
19+
...(spec.tests[0].results[0].error?.snippet && {
20+
output: spec.tests[0].results[0].error.snippet,
21+
output_format: "ansi",
22+
}),
23+
visibility: "visible",
24+
extra_data: {
25+
duration: spec.tests[0].results[0].duration,
26+
...(spec.tests[0].results[0].error && {
27+
error_message:
28+
spec.tests[0].results[0].error.stack.split("\n")[0],
29+
...(spec.tests[0].results[0].error.location && {
30+
error_path: `${
31+
spec.tests[0].results[0].error.location.file.split(
32+
"/tests/",
33+
)[1]
34+
}:${spec.tests[0].results[0].error.location.line}:${
35+
spec.tests[0].results[0].error.location.column
36+
}`,
37+
}),
38+
...(spec.tests[0].results[0].error.snippet && {
39+
error_snippet: spec.tests[0].results[0].error.snippet,
40+
}),
41+
}),
42+
},
43+
};
44+
}),
45+
)
46+
.flat();
47+
48+
const totalScore = tests.reduce((acc, test) => acc + test.score, 0);
49+
50+
const leaderboard = [{ name: "score", value: totalScore, order: "desc" }];
51+
52+
console.log(
53+
JSON.stringify({
54+
tests,
55+
leaderboard,
56+
visibility: "visible",
57+
// stdout_visibility: 'visible',
58+
}),
59+
);
60+
} catch (err) {
61+
console.error("Error:", err);
62+
}

next.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {};
3+
4+
module.exports = nextConfig;

nextauth.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { DefaultSession } from "next-auth";
2+
3+
import type { User } from "@/lib/types";
4+
5+
declare module "next-auth" {
6+
interface Session extends DefaultSession {
7+
user?: User;
8+
}
9+
}

package.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "112-1-unit2-notion-clone",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "next lint",
10+
"format": "prettier --write .",
11+
"migrate": "drizzle-kit push:pg",
12+
"studio": "drizzle-kit studio",
13+
"test": "playwright test"
14+
},
15+
"dependencies": {
16+
"@radix-ui/react-icons": "^1.3.0",
17+
"@radix-ui/react-label": "^2.0.2",
18+
"@radix-ui/react-separator": "^1.0.3",
19+
"@radix-ui/react-slot": "^1.0.2",
20+
"@radix-ui/react-toast": "^1.1.5",
21+
"@types/bcryptjs": "^2.4.6",
22+
"bcryptjs": "^2.4.3",
23+
"class-variance-authority": "^0.7.0",
24+
"clsx": "^2.0.0",
25+
"dotenv": "^16.3.1",
26+
"drizzle-orm": "^0.28.6",
27+
"lucide-react": "^0.292.0",
28+
"next": "14.0.1",
29+
"next-auth": "^5.0.0-beta.3",
30+
"pg": "^8.11.3",
31+
"pusher": "^5.1.3",
32+
"pusher-js": "^8.3.0",
33+
"react": "^18",
34+
"react-dom": "^18",
35+
"tailwind-merge": "^2.0.0",
36+
"tailwindcss-animate": "^1.0.7"
37+
},
38+
"devDependencies": {
39+
"@playwright/test": "^1.40.0",
40+
"@trivago/prettier-plugin-sort-imports": "^4.2.1",
41+
"@types/node": "^20",
42+
"@types/pg": "^8.10.8",
43+
"@types/react": "^18",
44+
"@types/react-dom": "^18",
45+
"@typescript-eslint/eslint-plugin": "^6.10.0",
46+
"@typescript-eslint/parser": "^6.10.0",
47+
"autoprefixer": "^10.0.1",
48+
"drizzle-kit": "^0.19.13",
49+
"eslint": "^8.53.0",
50+
"eslint-config-next": "14.0.1",
51+
"eslint-config-prettier": "^9.0.0",
52+
"postcss": "^8",
53+
"prettier": "^3.0.3",
54+
"prettier-plugin-tailwindcss": "^0.5.6",
55+
"tailwindcss": "^3.3.0",
56+
"typescript": "^5.2.2"
57+
}
58+
}

0 commit comments

Comments
 (0)