create-cslug 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +12 -2
  2. package/docs/README.md +32 -0
  3. package/package.json +32 -4
  4. package/src/bin.ts +58 -0
  5. package/src/index.ts +10 -0
  6. package/src/scaffold.ts +133 -0
  7. package/templates/api/AGENTS.md +8 -0
  8. package/templates/api/README.md +12 -0
  9. package/templates/api/_env.example +5 -0
  10. package/templates/api/_env.test +7 -0
  11. package/templates/api/_gitignore +6 -0
  12. package/templates/api/app/providers/app-service-provider.ts +8 -0
  13. package/templates/api/bootstrap/app.ts +8 -0
  14. package/templates/api/bootstrap/providers.ts +12 -0
  15. package/templates/api/config/app.ts +10 -0
  16. package/templates/api/config/cache.ts +10 -0
  17. package/templates/api/config/database.ts +8 -0
  18. package/templates/api/config/env.ts +9 -0
  19. package/templates/api/config/http.ts +9 -0
  20. package/templates/api/config/i18n.ts +7 -0
  21. package/templates/api/config/index.ts +14 -0
  22. package/templates/api/config/redis.ts +6 -0
  23. package/templates/api/cslug.config.ts +8 -0
  24. package/templates/api/database/migrations/.gitkeep +0 -0
  25. package/templates/api/database/seeders/database-seeder.ts +4 -0
  26. package/templates/api/docker-compose.yml +9 -0
  27. package/templates/api/resources/lang/en.json +7 -0
  28. package/templates/api/routes/api.ts +9 -0
  29. package/templates/api/storage/.gitkeep +0 -0
  30. package/templates/api/tests/feature/api.test.ts.tpl +12 -0
  31. package/templates/api/tsconfig.json +18 -0
  32. package/templates/full/_env.example +8 -0
  33. package/templates/full/_env.test +8 -0
  34. package/templates/full/app/controllers/auth/register-controller.ts +30 -0
  35. package/templates/full/app/jobs/.gitkeep +0 -0
  36. package/templates/full/app/mail/welcome-mail.ts +20 -0
  37. package/templates/full/bootstrap/providers.ts +23 -0
  38. package/templates/full/config/env.ts +14 -0
  39. package/templates/full/config/index.ts +22 -0
  40. package/templates/full/config/mail.ts +12 -0
  41. package/templates/full/config/queue.ts +11 -0
  42. package/templates/full/config/storage.ts +9 -0
  43. package/templates/full/cslug.config.ts +15 -0
  44. package/templates/full/docker-compose.yml +12 -0
  45. package/templates/full/resources/lang/en.json +32 -0
  46. package/templates/full/resources/mail/layout.vue +20 -0
  47. package/templates/full/resources/mail/welcome.vue +14 -0
  48. package/templates/full/routes/schedule.ts +6 -0
  49. package/templates/full/tests/feature/welcome-mail.test.ts.tpl +21 -0
  50. package/templates/tailwind/resources/styles/tailwind.css +1 -0
  51. package/templates/web/app/controllers/auth/register-controller.ts +26 -0
  52. package/templates/web/app/controllers/auth/session-controller.ts +24 -0
  53. package/templates/web/app/controllers/home-controller.ts +16 -0
  54. package/templates/web/app/repositories/user-repository.ts +6 -0
  55. package/templates/web/app/tables/user-table.ts +12 -0
  56. package/templates/web/app/validators/login-validator.ts +6 -0
  57. package/templates/web/app/validators/register-validator.ts +26 -0
  58. package/templates/web/bootstrap/providers.ts +16 -0
  59. package/templates/web/bunfig.toml +3 -0
  60. package/templates/web/config/auth.ts +7 -0
  61. package/templates/web/config/index.ts +19 -0
  62. package/templates/web/config/session.ts +8 -0
  63. package/templates/web/cslug.config.ts +13 -0
  64. package/templates/web/database/factories/user-factory.ts +9 -0
  65. package/templates/web/database/migrations/00000000_000001_create_users.sql +13 -0
  66. package/templates/web/database/seeders/database-seeder.ts +7 -0
  67. package/templates/web/public/.gitkeep +0 -0
  68. package/templates/web/resources/client.ts +4 -0
  69. package/templates/web/resources/lang/en.json +25 -0
  70. package/templates/web/resources/styles/app.scss +80 -0
  71. package/templates/web/resources/views/auth/login.vue +26 -0
  72. package/templates/web/resources/views/auth/register.vue +34 -0
  73. package/templates/web/resources/views/dashboard.vue +13 -0
  74. package/templates/web/resources/views/errors/404.vue +13 -0
  75. package/templates/web/resources/views/home.vue +13 -0
  76. package/templates/web/resources/views/layouts/default.vue +39 -0
  77. package/templates/web/routes/web.ts +22 -0
  78. package/templates/web/tests/feature/auth.test.ts.tpl +57 -0
  79. package/templates/web/tsconfig.json +19 -0
@@ -0,0 +1,13 @@
1
+ <script setup lang="ts">
2
+ import { useT } from '@cslug/vue'
3
+ import Layout from './layouts/default.vue'
4
+
5
+ const { t } = useT()
6
+ </script>
7
+
8
+ <template>
9
+ <Layout :title="t('home.title')">
10
+ <h1>{{ t('app.name') }}</h1>
11
+ <p>{{ t('home.intro') }}</p>
12
+ </Layout>
13
+ </template>
@@ -0,0 +1,39 @@
1
+ <script setup lang="ts">
2
+ import { Assets, route, useRequest, useT } from '@cslug/vue'
3
+
4
+ defineProps<{ title: string }>()
5
+ const { locale, user, csrfToken, flash } = useRequest()
6
+ const { t } = useT()
7
+ </script>
8
+
9
+ <template>
10
+ <html :lang="locale">
11
+ <head>
12
+ <meta charset="utf-8" />
13
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
14
+ <title>{{ title }} · {{ t('app.name') }}</title>
15
+ <Assets entry="client" />
16
+ <slot name="head" />
17
+ </head>
18
+ <body>
19
+ <header class="site-header">
20
+ <a class="brand" :href="route('home')">{{ t('app.name') }}</a>
21
+ <nav v-if="user">
22
+ <a :href="route('dashboard')">{{ user.name }}</a>
23
+ <form :action="route('logout')" method="post">
24
+ <input type="hidden" name="_token" :value="csrfToken" />
25
+ <button class="link">{{ t('auth.logout') }}</button>
26
+ </form>
27
+ </nav>
28
+ <nav v-else>
29
+ <a :href="route('login')">{{ t('auth.login') }}</a>
30
+ <a :href="route('register')">{{ t('auth.register') }}</a>
31
+ </nav>
32
+ </header>
33
+
34
+ <p v-for="(message, type) in flash" :key="type" class="flash" :data-type="type">{{ message }}</p>
35
+
36
+ <main class="container"><slot /></main>
37
+ </body>
38
+ </html>
39
+ </template>
@@ -0,0 +1,22 @@
1
+ import { auth, guest } from '@cslug/auth'
2
+ import { defineRoutes } from '@cslug/http'
3
+ import { throttle } from '@cslug/http/middleware'
4
+ import { RegisterController } from '#app/controllers/auth/register-controller'
5
+ import { SessionController } from '#app/controllers/auth/session-controller'
6
+ import { HomeController } from '#app/controllers/home-controller'
7
+
8
+ export default defineRoutes((r) => {
9
+ r.get('/', [HomeController, 'index']).name('home')
10
+
11
+ r.group({ middleware: [guest()] }, (r) => {
12
+ r.get('/register', [RegisterController, 'create']).name('register')
13
+ r.post('/register', [RegisterController, 'store']).middleware(throttle('5/min')).name('register.store')
14
+ r.get('/login', [SessionController, 'create']).name('login')
15
+ r.post('/login', [SessionController, 'store']).middleware(throttle('5/min')).name('login.store')
16
+ })
17
+
18
+ r.group({ middleware: [auth()] }, (r) => {
19
+ r.get('/dashboard', [HomeController, 'dashboard']).name('dashboard')
20
+ r.post('/logout', [SessionController, 'destroy']).name('logout')
21
+ })
22
+ })
@@ -0,0 +1,57 @@
1
+ import { expect, test } from 'bun:test'
2
+ import { testApp } from '@cslug/testing'
3
+ import { UserFactory } from '#database/factories/user-factory'
4
+
5
+ const app = testApp()
6
+
7
+ test('the home page renders', async () => {
8
+ await app.get('/').assertOk().assertSee('{{title}}')
9
+ })
10
+
11
+ test('a visitor can register and lands on the dashboard', async () => {
12
+ await app
13
+ .post('/register')
14
+ .form({
15
+ name: 'Ada',
16
+ email: 'ADA@example.test',
17
+ password: 'correct horse battery',
18
+ passwordConfirmation: 'correct horse battery',
19
+ })
20
+ .assertRedirect('/dashboard')
21
+ .assertSessionHas('success')
22
+
23
+ await app.assertDatabaseHas('users', { email: 'ada@example.test' })
24
+ expect(app.auth.check()).toBe(true)
25
+ })
26
+
27
+ test('registration rejects a taken email and keeps the old input', async () => {
28
+ await UserFactory.create({ email: 'taken@example.test' })
29
+ await app
30
+ .post('/register')
31
+ .form({
32
+ name: 'Bob',
33
+ email: 'taken@example.test',
34
+ password: 'correct horse battery',
35
+ passwordConfirmation: 'correct horse battery',
36
+ })
37
+ .assertInvalid({ email: 'This value is already taken.' })
38
+ .assertOldInput({ name: 'Bob' })
39
+ })
40
+
41
+ test('login with the right password, then the dashboard', async () => {
42
+ const user = await UserFactory.create()
43
+ await app.post('/login').form({ email: user.email, password: 'password-password' }).assertRedirect('/dashboard')
44
+ await app.get('/dashboard').assertOk().assertSee(`Hello, ${user.name}!`)
45
+ })
46
+
47
+ test('login with the wrong password fails', async () => {
48
+ const user = await UserFactory.create()
49
+ await app
50
+ .post('/login')
51
+ .form({ email: user.email, password: 'nope' })
52
+ .assertInvalid({ email: 'These credentials do not match our records.' })
53
+ })
54
+
55
+ test('guests are redirected to login', async () => {
56
+ await app.get('/dashboard').assertRedirect('/login')
57
+ })
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ESNext", "DOM"],
7
+ "types": ["bun"],
8
+ "strict": true,
9
+ "noUncheckedIndexedAccess": true,
10
+ "noImplicitOverride": true,
11
+ "verbatimModuleSyntax": true,
12
+ "allowImportingTsExtensions": true,
13
+ "noEmit": true,
14
+ "skipLibCheck": true,
15
+ "paths": { "@/*": ["./resources/*"] }
16
+ },
17
+ "include": ["**/*.ts", "**/*.vue", ".cslug/**/*.d.ts"],
18
+ "exclude": ["node_modules", "public/build", "storage"]
19
+ }