Skip to content

Commit

Permalink
chore: add react/vue playgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed May 11, 2024
1 parent d577d63 commit d0e9097
Show file tree
Hide file tree
Showing 128 changed files with 3,557 additions and 414 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ package-lock.json
todo.md
.adonisjs
playground/public/assets
docs/public/assets
public/assets
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@japa/snapshot": "^2.0.5",
"@julr/tooling-configs": "^2.2.0",
"@swc/core": "^1.4.17",
"@types/node": "^20.12.11",
"c8": "^9.1.0",
"copyfiles": "^2.4.1",
"del-cli": "^5.1.0",
Expand All @@ -33,7 +34,8 @@
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"tsup": "^8.0.2",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"vite": "^5.2.11"
},
"pnpm": {
"overrides": {
Expand Down
22 changes: 0 additions & 22 deletions playgrounds/inertia-react/.editorconfig

This file was deleted.

2 changes: 1 addition & 1 deletion playgrounds/inertia-react/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ TZ=UTC
PORT=3333
HOST=localhost
LOG_LEVEL=info
APP_KEY=0Q0aaWK8qBOgnBaigvLlaqNJYPejCL5t
APP_KEY=_lnNOQKKmINM8q3Kvk1djR5BeN_PcQvs
NODE_ENV=development
SESSION_DRIVER=cookie
2 changes: 1 addition & 1 deletion playgrounds/inertia-react/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ TZ=UTC
PORT=3333
HOST=localhost
LOG_LEVEL=info
APP_KEY=0Q0aaWK8qBOgnBaigvLlaqNJYPejCL5t
APP_KEY=_lnNOQKKmINM8q3Kvk1djR5BeN_PcQvs
NODE_ENV=development
SESSION_DRIVER=cookie
1 change: 0 additions & 1 deletion playgrounds/inertia-react/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* Register hook to process TypeScript files using ts-node
*/
import { register } from 'node:module'

Check failure on line 22 in playgrounds/inertia-react/ace.js

View workflow job for this annotation

GitHub Actions / lint

Expected 1 empty line after import statement not followed by another import

register('ts-node/esm', import.meta.url)

/**
Expand Down
34 changes: 3 additions & 31 deletions playgrounds/inertia-react/adonisrc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { relative } from 'node:path'
import { defineConfig } from '@adonisjs/core/app'

export default defineConfig({
Expand All @@ -11,11 +10,7 @@ export default defineConfig({
| will be scanned automatically from the "./commands" directory.
|
*/
commands: [
() => import('@adonisjs/core/commands'),
() => import('@adonisjs/lucid/commands'),
() => import('@tuyau/core/commands'),
],
commands: [() => import('@adonisjs/core/commands'), () => import('@adonisjs/lucid/commands')],

/*
|--------------------------------------------------------------------------
Expand All @@ -42,8 +37,7 @@ export default defineConfig({
() => import('@adonisjs/cors/cors_provider'),
() => import('@adonisjs/lucid/database_provider'),
() => import('@adonisjs/auth/auth_provider'),
() => import('@adonisjs/inertia/inertia_provider'),
() => import('@tuyau/core/tuyau_provider'),
() => import('@adonisjs/inertia/inertia_provider')

Check warning on line 40 in playgrounds/inertia-react/adonisrc.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
],

/*
Expand Down Expand Up @@ -75,7 +69,7 @@ export default defineConfig({
{
files: ['tests/functional/**/*.spec(.ts|.js)'],
name: 'functional',
timeout: 30_000,
timeout: 30000,

Check failure on line 72 in playgrounds/inertia-react/adonisrc.ts

View workflow job for this annotation

GitHub Actions / lint

Invalid group length in numeric value
},
],
forceExit: false,
Expand Down Expand Up @@ -104,27 +98,5 @@ export default defineConfig({
assetsBundler: false,
unstable_assembler: {
onBuildStarting: [() => import('@adonisjs/vite/build_hook')],
/**
* Temporary code to handle HotHook messages
* Will be moved to @adonisjs/core or @hot-hook/adonis later
*/
onHttpServerMessage: [
async () => ({
default: (ui, message, actions) => {
if (message.type === 'hot-hook:full-reload') {
const path = relative(import.meta.dirname, message.path || message.paths[0])

ui.logger.log(`${ui.colors.green('full-reload')} due to ${ui.colors.cyan(path)}`)
actions.restartServer()
}

if (message.type === 'hot-hook:invalidated') {
const path = relative(import.meta.dirname, message.path || message.paths[0])

ui.logger.log(`${ui.colors.yellow('invalidated')} ${ui.colors.cyan(path)}`)
}
},
}),
],
},
})
3 changes: 1 addition & 2 deletions playgrounds/inertia-react/app/exceptions/handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import app from '@adonisjs/core/services/app'
import type { HttpContext } from '@adonisjs/core/http'
import { ExceptionHandler } from '@adonisjs/core/http'
import { HttpContext, ExceptionHandler } from '@adonisjs/core/http'

Check failure on line 2 in playgrounds/inertia-react/app/exceptions/handler.ts

View workflow job for this annotation

GitHub Actions / lint

Import "HttpContext" is only used as types
import type { StatusPageRange, StatusPageRenderer } from '@adonisjs/core/types/http'

export default class HttpExceptionHandler extends ExceptionHandler {
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/inertia-react/app/middleware/auth_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default class AuthMiddleware {
next: NextFn,
options: {
guards?: (keyof Authenticators)[]
} = {},
} = {}
) {
await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo })
return next()
}
}
}

Check warning on line 25 in playgrounds/inertia-react/app/middleware/auth_middleware.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '@adonisjs/core/logger'
import { HttpContext } from '@adonisjs/core/http'
import type { NextFn } from '@adonisjs/core/types/http'
import { NextFn } from '@adonisjs/core/types/http'

Check failure on line 3 in playgrounds/inertia-react/app/middleware/container_bindings_middleware.ts

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

/**
* The container bindings middleware binds classes to their request
Expand Down
31 changes: 31 additions & 0 deletions playgrounds/inertia-react/app/middleware/guest_middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { HttpContext } from '@adonisjs/core/http'
import type { NextFn } from '@adonisjs/core/types/http'
import type { Authenticators } from '@adonisjs/auth/types'

/**
* Guest middleware is used to deny access to routes that should
* be accessed by unauthenticated users.
*
* For example, the login page should not be accessible if the user
* is already logged-in
*/
export default class GuestMiddleware {
/**
* The URL to redirect to when user is logged-in
*/
redirectTo = '/'

async handle(
ctx: HttpContext,
next: NextFn,
options: { guards?: (keyof Authenticators)[] } = {}
) {
for (let guard of options.guards || [ctx.auth.defaultGuard]) {

Check failure on line 23 in playgrounds/inertia-react/app/middleware/guest_middleware.ts

View workflow job for this annotation

GitHub Actions / lint

'guard' is never reassigned. Use 'const' instead
if (await ctx.auth.use(guard).check()) {
return ctx.response.redirect(this.redirectTo, true)
}
}

return next()
}
}

Check warning on line 31 in playgrounds/inertia-react/app/middleware/guest_middleware.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
5 changes: 1 addition & 4 deletions playgrounds/inertia-react/app/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import hash from '@adonisjs/core/services/hash'
import { compose } from '@adonisjs/core/helpers'
import { BaseModel, column } from '@adonisjs/lucid/orm'
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid'
import { DbAccessTokensProvider } from '@adonisjs/auth/access_tokens'

const AuthFinder = withAuthFinder(() => hash.use('scrypt'), {
uids: ['email'],
Expand All @@ -28,6 +27,4 @@ export default class User extends compose(BaseModel, AuthFinder) {

@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null

static accessTokens = DbAccessTokensProvider.forModel(User)
}
}

Check warning on line 30 in playgrounds/inertia-react/app/models/user.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
1 change: 0 additions & 1 deletion playgrounds/inertia-react/bin/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

import 'reflect-metadata'

import { Ignitor, prettyPrintError } from '@adonisjs/core'

Check failure on line 15 in playgrounds/inertia-react/bin/console.ts

View workflow job for this annotation

GitHub Actions / lint

Missed spacing between "reflect-metadata" and "@adonisjs/core" imports

/**
Expand Down
1 change: 0 additions & 1 deletion playgrounds/inertia-react/bin/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

import 'reflect-metadata'

import { Ignitor, prettyPrintError } from '@adonisjs/core'

Check failure on line 13 in playgrounds/inertia-react/bin/server.ts

View workflow job for this annotation

GitHub Actions / lint

Missed spacing between "reflect-metadata" and "@adonisjs/core" imports

/**
Expand Down
12 changes: 6 additions & 6 deletions playgrounds/inertia-react/bin/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
|
*/

import 'reflect-metadata'
process.env.NODE_ENV = 'test'

import 'reflect-metadata'

Check failure on line 15 in playgrounds/inertia-react/bin/test.ts

View workflow job for this annotation

GitHub Actions / lint

Import in body of module; reorder to top
import { Ignitor, prettyPrintError } from '@adonisjs/core'
import { configure, processCLIArgs, run } from '@japa/runner'

process.env.NODE_ENV = 'test'

/**
* URL to the application root. AdonisJS need it to resolve
* paths to file and directories for scaffolding commands
Expand Down Expand Up @@ -50,9 +49,10 @@ new Ignitor(APP_ROOT, { importer: IMPORTER })
configure({
...app.rcFile.tests,
...config,

setup: runnerHooks.setup,
teardown: runnerHooks.teardown.concat([() => app.terminate()]),
...{
setup: runnerHooks.setup,
teardown: runnerHooks.teardown.concat([() => app.terminate()]),
},
})
})
.run(() => run())
Expand Down
3 changes: 1 addition & 2 deletions playgrounds/inertia-react/config/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import env from '#start/env'
import app from '@adonisjs/core/services/app'
import { Secret } from '@adonisjs/core/helpers'
import { defineConfig } from '@adonisjs/core/http'

import env from '#start/env'

/**
* The app key is used for encrypting cookies, generating signed URLs,
* and by the "encryption" module.
Expand Down
16 changes: 8 additions & 8 deletions playgrounds/inertia-react/config/auth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { defineConfig } from '@adonisjs/auth'
import type { InferAuthEvents, Authenticators } from '@adonisjs/auth/types'
import { tokensGuard, tokensUserProvider } from '@adonisjs/auth/access_tokens'
import { InferAuthEvents, Authenticators } from '@adonisjs/auth/types'
import { sessionGuard, sessionUserProvider } from '@adonisjs/auth/session'

const authConfig = defineConfig({
default: 'api',
default: 'web',
guards: {
api: tokensGuard({
provider: tokensUserProvider({
tokens: 'accessTokens',
model: () => import('#models/user'),
web: sessionGuard({
useRememberMeTokens: false,
provider: sessionUserProvider({
model: () => import('#models/user')

Check warning on line 11 in playgrounds/inertia-react/config/auth.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
}),
}),
},
Expand All @@ -25,4 +25,4 @@ declare module '@adonisjs/auth/types' {
}
declare module '@adonisjs/core/types' {
interface EventsList extends InferAuthEvents<Authenticators> {}
}
}

Check warning on line 28 in playgrounds/inertia-react/config/auth.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
4 changes: 2 additions & 2 deletions playgrounds/inertia-react/config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const dbConfig = defineConfig({
sqlite: {
client: 'better-sqlite3',
connection: {
filename: app.tmpPath('db.sqlite3'),
filename: app.tmpPath('db.sqlite3')

Check warning on line 10 in playgrounds/inertia-react/config/database.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
},
useNullAsDefault: true,
migrations: {
Expand All @@ -18,4 +18,4 @@ const dbConfig = defineConfig({
},
})

export default dbConfig
export default dbConfig

Check warning on line 21 in playgrounds/inertia-react/config/database.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎`
4 changes: 2 additions & 2 deletions playgrounds/inertia-react/config/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const hashConfig = defineConfig({

list: {
scrypt: drivers.scrypt({
cost: 16_384,
cost: 16384,
blockSize: 8,
parallelization: 1,
maxMemory: 33_554_432,
maxMemory: 33554432,
}),
},
})
Expand Down
8 changes: 4 additions & 4 deletions playgrounds/inertia-react/config/inertia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineConfig({
* Options for the server-side rendering
*/
ssr: {
enabled: false,
entrypoint: 'inertia/app/ssr.tsx',
},
})
enabled: true,
entrypoint: 'inertia/app/ssr.tsx'

Check warning on line 21 in playgrounds/inertia-react/config/inertia.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
}

Check warning on line 22 in playgrounds/inertia-react/config/inertia.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
})
3 changes: 1 addition & 2 deletions playgrounds/inertia-react/config/logger.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import env from '#start/env'
import app from '@adonisjs/core/services/app'
import { defineConfig, targets } from '@adonisjs/core/logger'

import env from '#start/env'

const loggerConfig = defineConfig({
default: 'app',

Expand Down
3 changes: 1 addition & 2 deletions playgrounds/inertia-react/config/session.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import env from '#start/env'
import app from '@adonisjs/core/services/app'
import { defineConfig, stores } from '@adonisjs/session'

import env from '#start/env'

const sessionConfig = defineConfig({
enabled: true,
cookieName: 'adonis-session',
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/inertia-react/config/shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const shieldConfig = defineConfig({
* to learn more
*/
csrf: {
enabled: false,
enabled: true,
exceptRoutes: [],
enableXsrfCookie: true,
methods: ['POST', 'PUT', 'PATCH', 'DELETE'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { BaseSchema } from '@adonisjs/lucid/schema'

export default class extends BaseSchema {
protected tableName = 'users'

async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').notNullable()
table.string('full_name').nullable()
table.string('email', 254).notNullable().unique()
table.string('password').notNullable()

table.timestamp('created_at').notNullable()
table.timestamp('updated_at').nullable()
})
}

async down() {
this.schema.dropTable(this.tableName)
}
}
Loading

0 comments on commit d0e9097

Please sign in to comment.