Skip to content

Commit 5c5a015

Browse files
authored
Merge pull request #13 from marsidev/path-setup
Path refactor
2 parents e8520bc + 19fae39 commit 5c5a015

Some content is hidden

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

70 files changed

+2852
-3694
lines changed

.eslintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ on:
66
- main
77

88
paths-ignore:
9+
- 'docs/**'
910
- '**.md'
11+
- '**.mdx'
1012

1113
pull_request:
1214
branches:
1315
- main
1416

1517
paths-ignore:
18+
- 'docs/**'
1619
- '**.md'
20+
- '**.mdx'
1721

1822
jobs:
1923
lint:
@@ -37,12 +41,12 @@ jobs:
3741
run: nci
3842

3943
- name: Build
40-
run: nr build
44+
run: nr lib:build
4145

4246
- name: Lint
4347
run: nr lint
4448

45-
typecheck:
49+
format:
4650
runs-on: ubuntu-latest
4751
steps:
4852
- uses: actions/checkout@v3
@@ -63,10 +67,36 @@ jobs:
6367
run: nci
6468

6569
- name: Build
66-
run: nr build
70+
run: nr lib:build
6771

68-
- name: Typecheck
69-
run: nr typecheck
72+
- name: Format
73+
run: nr format
74+
75+
type-check:
76+
runs-on: ubuntu-latest
77+
steps:
78+
- uses: actions/checkout@v3
79+
80+
- name: Install pnpm
81+
uses: pnpm/action-setup@v2
82+
83+
- name: Set node
84+
uses: actions/setup-node@v3
85+
with:
86+
node-version: 18.x
87+
cache: pnpm
88+
89+
- name: Setup
90+
run: npm i -g @antfu/ni
91+
92+
- name: Install
93+
run: nci
94+
95+
- name: Build
96+
run: nr lib:build
97+
98+
- name: Type check
99+
run: nr type-check
70100

71101
e2e-test:
72102
runs-on: ${{ matrix.os }}
@@ -99,7 +129,7 @@ jobs:
99129
run: npx playwright install --with-deps chromium webkit
100130

101131
- name: Build
102-
run: nr build
132+
run: nr lib:build
103133

104134
- name: Test
105135
run: npx playwright test

.prettierrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

.prettierrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
semi: false,
3+
useTabs: true,
4+
singleQuote: true,
5+
jsxSingleQuote: false,
6+
trailingComma: 'none',
7+
tabWidth: 2,
8+
arrowParens: 'avoid',
9+
printWidth: 100
10+
}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"eslint.packageManager": "pnpm",
3-
"eslint.workingDirectories": ["./packages/example"],
3+
"eslint.workingDirectories": ["./packages/lib", "./demos/nextjs"],
44
"editor.codeActionsOnSave": {
55
"source.fixAll.eslint": true
66
},

README.md

Lines changed: 21 additions & 335 deletions
Large diffs are not rendered by default.

packages/example/.gitignore renamed to demos/nextjs/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,3 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37-
38-
.vercel

demos/nextjs/.prettierrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
...require('../../.prettierrc.js'),
3+
plugins: [require('prettier-plugin-tailwindcss')]
4+
}

demos/nextjs/.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"typescript.tsdk": "..\\..\\node_modules\\.pnpm\\[email protected]\\node_modules\\typescript\\lib",
3+
"typescript.enablePromptUseWorkspaceTsdk": true
4+
}

packages/example/README.md renamed to demos/nextjs/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ First, run the development server:
88
npm run dev
99
# or
1010
yarn dev
11+
# or
12+
pnpm dev
1113
```
1214

1315
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
1416

15-
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
17+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
1618

1719
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
1820

1921
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
2022

23+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
24+
2125
## Learn More
2226

2327
To learn more about Next.js, take a look at the following resources:

demos/nextjs/next.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
experimental: {
4+
appDir: true
5+
},
6+
async redirects() {
7+
return [
8+
{
9+
source: '/',
10+
destination: '/demo',
11+
permanent: true
12+
}
13+
]
14+
}
15+
}
16+
17+
module.exports = nextConfig

demos/nextjs/package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "nextjs-demo",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "pnpm run --filter=@marsidev/react-turnstile build && next build",
8+
"start": "next start",
9+
"lint": "next lint",
10+
"lint:fix": "next lint --fix",
11+
"type-check": "tsc --noEmit"
12+
},
13+
"dependencies": {
14+
"@marsidev/react-turnstile": "workspace:*",
15+
"classnames": "2.3.2",
16+
"next": "13.2.4",
17+
"react": "18.2.0",
18+
"react-dom": "18.2.0"
19+
},
20+
"devDependencies": {
21+
"autoprefixer": "10.4.13",
22+
"eslint-config-custom": "workspace:*",
23+
"eslint-config-next": "13.2.4",
24+
"postcss": "8.4.21",
25+
"prettier-plugin-tailwindcss": "0.2.4",
26+
"tailwindcss": "3.2.7"
27+
},
28+
"eslintConfig": {
29+
"extends": [
30+
"next/core-web-vitals",
31+
"custom"
32+
]
33+
}
34+
}
File renamed without changes.
File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { TurnstileServerValidationResponse } from '@marsidev/react-turnstile'
2+
3+
const verifyEndpoint = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'
4+
5+
const responseHeaders = {
6+
'content-type': 'application/json'
7+
}
8+
9+
export async function POST(request: Request) {
10+
const body = (await request.json()) as { token: string; secret: string }
11+
const { token, secret } = body
12+
13+
const data = (await fetch(verifyEndpoint, {
14+
method: 'POST',
15+
body: `secret=${encodeURIComponent(secret)}&response=${encodeURIComponent(token)}`,
16+
headers: {
17+
'content-type': 'application/x-www-form-urlencoded'
18+
}
19+
}).then(res => res.json())) as TurnstileServerValidationResponse
20+
21+
if (!data.success) {
22+
return new Response(JSON.stringify(data), {
23+
status: 400,
24+
headers: responseHeaders
25+
})
26+
}
27+
28+
return new Response(JSON.stringify(data), {
29+
status: 200,
30+
headers: responseHeaders
31+
})
32+
}

demos/nextjs/src/app/demo/layout.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import '~/app/globals.css'
2+
import { Inter } from 'next/font/google'
3+
4+
const inter = Inter({ subsets: ['latin'] })
5+
6+
export const metadata = {
7+
title: 'React Turnstile Demo',
8+
description: 'React Turnstile Next.js 13 App Router Demo'
9+
}
10+
11+
export default function RootLayout({ children }: { children: React.ReactNode }) {
12+
return (
13+
<html lang="en">
14+
<body className={inter.className}>
15+
<main className="flex min-h-screen w-full flex-col items-center justify-center bg-[#1d1f20] py-24">
16+
<div className="flex w-full max-w-[740px] flex-col justify-center gap-2 p-4 text-white">
17+
{children}
18+
</div>
19+
</main>
20+
</body>
21+
</html>
22+
)
23+
}

demos/nextjs/src/app/demo/page.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Demo from '~/components/demo'
2+
3+
export default function Page() {
4+
return (
5+
<>
6+
<h1 className="mb-4 text-4xl font-semibold">React Turnstile Demo</h1>
7+
<Demo />
8+
</>
9+
)
10+
}

demos/nextjs/src/app/favicon.ico

25.3 KB
Binary file not shown.

packages/example/src/components/ConfigForm.tsx renamed to demos/nextjs/src/components/config-form.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { forwardRef, useState } from 'react'
2-
import { langOptions, siteKeyOptions, sizeOptions, themeOptions } from '../constants'
3-
import { SiteKeyType, WidgetSize } from '../types'
4-
import Options from './Options'
2+
import { langOptions, siteKeyOptions, sizeOptions, themeOptions } from '~/constants'
3+
import { SiteKeyType, WidgetSize } from '~/types'
4+
import Options from './options'
55

66
interface FormProps {
77
onChangeTheme: (value: string) => void
@@ -33,35 +33,35 @@ const ConfigForm = forwardRef<HTMLFormElement, FormProps>((props, ref) => {
3333
}
3434

3535
return (
36-
<form ref={ref} className='text-left accent-[#f4a15d]'>
37-
<div className='flex gap-16'>
36+
<form ref={ref} className="text-left accent-[#f4a15d]">
37+
<div className="flex gap-16">
3838
<Options
39-
name='theme'
39+
name="theme"
4040
options={[...themeOptions]}
41-
title='Theme'
41+
title="Theme"
4242
onChange={props.onChangeTheme}
4343
/>
4444

45-
<Options name='size' options={[...sizeOptions]} title='Size' onChange={onChangeSizeProxy} />
45+
<Options name="size" options={[...sizeOptions]} title="Size" onChange={onChangeSizeProxy} />
4646

4747
<Options
48-
helperUrl='https://developers.cloudflare.com/turnstile/frequently-asked-questions/#are-there-sitekeys-and-secret-keys-that-can-be-used-for-testing'
49-
name='siteKey'
48+
helperUrl="https://developers.cloudflare.com/turnstile/frequently-asked-questions/#are-there-sitekeys-and-secret-keys-that-can-be-used-for-testing"
49+
name="siteKey"
5050
options={siteKeyOptions.map(option => ({
5151
...option,
5252
// Option will be disabled when requesting interactive challenge on
5353
// invisible widget type
5454
disabled: option.value === 'interactive' && isInvisibleType
5555
}))}
56-
title='Demo Site Key Type'
56+
title="Demo Site Key Type"
5757
value={siteKeyType}
5858
onChange={onChangeSiteKeyTypeProxy}
5959
/>
6060

6161
<Options
62-
name='lang'
62+
name="lang"
6363
options={[...langOptions]}
64-
title='Language'
64+
title="Language"
6565
onChange={props.onChangeLang}
6666
/>
6767
</div>

0 commit comments

Comments
 (0)