-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreset.ts
175 lines (160 loc) · 5.53 KB
/
preset.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
export default definePreset({
name: 'hybridly-breeze',
options: {},
handler: async () => {
await applyNestedPreset({ preset: 'hybridly/preset', args: ['--no-pest'] });
await installNpmDependencies();
await extractTemplates({
title: 'extract templates',
from: 'base',
});
await installComposerDependencies();
await setupFortify();
},
});
const installNpmDependencies = async () => {
await installPackages({
title: 'add npm dependencies',
for: 'node',
dev: false,
packages: ['@heroicons/vue', '@vueuse/core', 'axios'],
});
await installPackages({
title: 'add npm dev dependencies',
for: 'node',
dev: true,
packages: ['prettier-plugin-tailwindcss', 'color'],
});
};
const installComposerDependencies = async () => {
await installPackages({
title: 'install composer dependencies',
for: 'php',
packages: ['jenssegers/agent'],
});
};
const setupFortify = async () => {
await installPackages({
title: 'install fortify',
for: 'php',
packages: ['laravel/fortify'],
});
await executeCommand({
title: "publish fortify's resources",
command: 'php',
arguments: [
'artisan',
'vendor:publish',
'--provider=Laravel\\Fortify\\FortifyServiceProvider',
],
});
await editFiles({
title: 'add fortify service provider',
files: 'config/app.php',
operations: {
type: 'add-line',
match: /App\\Providers\\RouteServiceProvider::class,/,
position: 'after',
lines: ['App\\Providers\\FortifyServiceProvider::class,'],
},
});
await editFiles({
title: 'register fortify auth views',
files: 'app/Providers/FortifyServiceProvider.php',
operations: {
type: 'add-line',
match: /Fortify::createUsersUsing\(CreateNewUser::class\);/,
position: 'before',
lines: [
"Fortify::loginView(fn () => hybridly('Auth.Login', [",
" 'canResetPassword' => app('router')->has('password.request'),",
" 'status' => session('status'),",
']));',
"Fortify::registerView(fn () => hybridly('Auth.Register'));",
"Fortify::verifyEmailView(fn () => hybridly('Auth.VerifyEmail', [",
" 'status' => session('status'),",
']));',
"Fortify::confirmPasswordView(fn () => hybridly('Auth.ConfirmPassword'));",
"Fortify::twoFactorChallengeView(fn () => hybridly('Auth.TwoFactorChallenge'));",
"Fortify::requestPasswordResetLinkView(fn () => hybridly('Auth.ForgotPassword', [",
" 'status' => session('status'),",
']));',
"Fortify::resetPasswordView(fn () => hybridly('reset-password', [",
" 'email' => request()->input('email'),",
" 'token' => request()->route('token')",
']));',
],
},
});
await editFiles({
title: 'update user model',
files: 'app/Models/User.php',
operations: [
{
type: 'add-line',
match: /use Laravel\\Sanctum\\HasApiTokens;/,
position: 'after',
lines: ['use Laravel\\Fortify\\TwoFactorAuthenticatable;'],
},
{
type: 'update-content',
update: (content) =>
content.replace(
'use HasApiTokens, HasFactory, Notifiable;',
'use HasApiTokens, HasFactory, Notifiable, TwoFactorAuthenticatable;'
),
},
],
});
await editFiles({
title: 'setup hybridly shared properties',
files: 'app/Http/Middleware/HandleHybridRequests.php',
operations: [
{
type: 'remove-line',
match: /public function share\(\): SharedData/,
count: 7,
start: 1,
},
{
type: 'add-line',
match: /public function share\(\): SharedData/,
position: 'after',
lines: [
'{',
' return SharedData::from([',
" 'security' => SecurityData::from([",
" 'user' => UserData::optional(auth()->user()),",
' ]),',
" 'status' => session('status') // used by fortify",
' ]);',
'}',
],
},
],
});
await editFiles({
title: 'update default home route in fortify',
files: 'config/fortify.php',
operations: {
type: 'update-content',
update: (content) =>
content.replace(
"'home' => '/home',",
"'home' => '/dashboard',"
),
},
});
await editFiles({
title: 'update default home route in route service provider',
files: 'app/Providers/RouteServiceProvider.php',
operations: {
type: 'update-content',
update: (content) =>
content.replace(
"public const HOME = '/home';",
"public const HOME = '/dashboard';"
),
},
});
};