-
Notifications
You must be signed in to change notification settings - Fork 19
/
castor.php
117 lines (96 loc) · 3.19 KB
/
castor.php
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
<?php
/*
* This file is part of the Secret Santa project.
*
* (c) JoliCode <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Castor\Attribute\AsTask;
use function Castor\guard_min_version;
use function Castor\import;
use function Castor\io;
use function Castor\notify;
use function Castor\variable;
use function docker\about;
use function docker\build;
use function docker\docker_compose_run;
use function docker\generate_certificates;
use function docker\up;
// use function docker\workers_start;
// use function docker\workers_stop;
guard_min_version('0.15.0');
import(__DIR__ . '/.castor');
/**
* @return array<string, mixed>
*/
function create_default_variables(): array
{
$projectName = 'secret-santa';
$tld = 'test';
return [
'project_name' => $projectName,
'root_domain' => "{$projectName}.{$tld}",
'project_directory' => '.',
'extra_domains' => [
"www.{$projectName}.{$tld}",
],
'php_version' => '8.3',
];
}
#[AsTask(description: 'Builds and starts the infrastructure, then install the application (composer, yarn, ...)')]
function start(): void
{
io()->title('Starting the stack');
// workers_stop();
generate_certificates(force: false);
build();
up();
cache_clear();
install();
migrate();
// workers_start();
notify('The stack is now up and running.');
io()->success('The stack is now up and running.');
about();
}
#[AsTask(description: 'Installs the application (composer, yarn, ...)', namespace: 'app', aliases: ['install'])]
function install(): void
{
io()->title('Installing the application');
$basePath = variable('root_dir');
if (is_file("{$basePath}/composer.json")) {
io()->section('Installing PHP dependencies');
docker_compose_run('composer install -n --prefer-dist --optimize-autoloader');
}
if (is_file("{$basePath}/yarn.lock")) {
io()->section('Installing Node.js dependencies');
docker_compose_run('yarn install --frozen-lockfile');
} elseif (is_file("{$basePath}/package.json")) {
io()->section('Installing Node.js dependencies');
if (is_file("{$basePath}/package-lock.json")) {
docker_compose_run('npm ci');
} else {
docker_compose_run('npm install');
}
}
if (is_file("{$basePath}/importmap.php")) {
io()->section('Installing importmap');
docker_compose_run('bin/console importmap:install');
}
qa\install();
}
#[AsTask(description: 'Clear the application cache', namespace: 'app', aliases: ['cache-clear'])]
function cache_clear(): void
{
io()->title('Clearing the application cache');
docker_compose_run('rm -rf var/cache/ && bin/console cache:warmup');
}
#[AsTask(description: 'Migrates database schema', namespace: 'app:db', aliases: ['migrate'])]
function migrate(): void
{
// io()->title('Migrating the database schema');
// docker_compose_run('bin/console doctrine:database:create --if-not-exists');
// docker_compose_run('bin/console doctrine:migration:migrate -n --allow-no-migration --all-or-nothing');
}