-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchisel.php
More file actions
175 lines (152 loc) · 5.52 KB
/
Copy pathchisel.php
File metadata and controls
175 lines (152 loc) · 5.52 KB
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
<?php
require getenv('LARAVEL_INSTALLER_AUTOLOADER') ?: __DIR__.'/vendor/autoload.php';
use Laravel\Chisel\Chisel;
use Laravel\Chisel\Question;
use Laravel\Prompts\Support\Logger;
use Symfony\Component\Process\Process;
use function Laravel\Prompts\task;
function chiselRun(array $command, string $label): void
{
$process = task(
label: $label,
keepSummary: true,
callback: function (Logger $logger) use ($command) {
$process = new Process($command);
$process->run(function ($type, $line) use ($logger) {
$logger->line($line);
});
if ($process->isSuccessful()) {
$logger->success(implode(' ', $command));
return $process;
}
$logger->error(implode(' ', $command));
$logger->error('Error output: '.trim($process->getErrorOutput()));
$logger->error('Chisel: Your project may be in a partially-modified state — review the output above before continuing.');
return $process;
},
);
if (! $process->isSuccessful()) {
exit($process->getExitCode());
}
}
/**
* Framework-specific file paths are supplied by the sibling chisel-paths.php.
*
* @var array{
* app_layout: string,
* types: string,
* update_profile_form: string,
* teams_files: list<string>,
* teams_factory_callers: list<string>,
* api_files: list<string>,
* email_verification_files: list<string>,
* } $paths
*/
$paths = require __DIR__.'/chisel-paths.php';
/**
* Shared files that carry teams markers (cleaned when kept, stripped when off).
*/
$teamsSharedFiles = [
'app/Models/User.php',
'config/jetstream.php',
'app/Providers/JetstreamServiceProvider.php',
'app/Actions/Fortify/CreateNewUser.php',
'app/Actions/Jetstream/DeleteUser.php',
'database/factories/UserFactory.php',
'database/migrations/0001_01_01_000000_create_users_table.php',
$paths['app_layout'],
$paths['types'],
];
$apiSharedFiles = [
'app/Models/User.php',
'config/jetstream.php',
'app/Providers/JetstreamServiceProvider.php',
'app/Actions/Jetstream/DeleteUser.php',
$paths['app_layout'],
$paths['types'],
];
$emailVerificationSharedFiles = [
'config/fortify.php',
'routes/web.php',
'database/factories/UserFactory.php',
$paths['types'],
$paths['update_profile_form'],
];
return Chisel::script(__DIR__)
->questions([
Question::multiselect(
name: 'features',
label: 'Which optional features would you like to enable?',
options: [
'teams' => 'Teams',
'api' => 'API tokens',
'email-verification' => 'Email verification',
],
default: ['teams', 'api', 'email-verification'],
hint: 'Use space to select, enter to confirm.',
),
])
// Teams is evaluated first so the ->withPersonalTeam() call inside the
// shared EmailVerificationTest is stripped while that file still exists.
->selected(
'features',
'teams',
then: function (Chisel $c) use ($teamsSharedFiles) {
$c->files(...$teamsSharedFiles)->removeSectionMarkers('teams');
},
else: function (Chisel $c) use ($paths, $teamsSharedFiles) {
$c->files(...$teamsSharedFiles)->removeSection('teams');
$c->files(...$paths['teams_factory_callers'])
->replace('->withPersonalTeam()', '');
$c->files(...$paths['teams_files'])->delete();
},
)
->selected(
'features',
'api',
then: function (Chisel $c) use ($apiSharedFiles) {
$c->files(...$apiSharedFiles)->removeSectionMarkers('api');
},
else: function (Chisel $c) use ($paths, $apiSharedFiles) {
$c->files(...$apiSharedFiles)->removeSection('api');
$c->files(...$paths['api_files'])->delete();
},
)
->selected(
'features',
'email-verification',
then: function (Chisel $c) use ($emailVerificationSharedFiles) {
$c->files(...$emailVerificationSharedFiles)->removeSectionMarkers('email-verification');
},
else: function (Chisel $c) use ($paths, $emailVerificationSharedFiles) {
$c->files(...$emailVerificationSharedFiles)->removeSection('email-verification');
$c->file('app/Models/User.php')->replace(' implements MustVerifyEmail', '');
$c->files(...$paths['email_verification_files'])->delete();
},
)
->apply(function (Chisel $c): void {
// Prune directories left empty after a feature's files were deleted
// (deepest first so parents become empty before we reach them).
foreach ([
'resources/js/Pages/Teams/Partials',
'resources/js/Pages/Teams',
'resources/js/Pages/API/Partials',
'resources/js/Pages/API',
] as $dir) {
$path = __DIR__.'/'.$dir;
if (is_dir($path) && count(scandir($path)) === 2) {
@rmdir($path);
}
}
chiselRun([__DIR__.'/vendor/bin/pint', '--quiet'], 'Pint');
chiselRun(['npx', 'prettier', '--write', 'resources/js'], 'Prettier');
$c->file('composer.json')->replace(
",\n \"@php artisan install:features --ansi\"",
'',
);
$c->files(
'app/Console/Commands/InstallFeaturesCommand.php',
'chisel.php',
'chisel-paths.php',
)->delete();
});