-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
castor.php
82 lines (69 loc) · 2.21 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
<?php
/*
* This file is part of the 3D Follow project.
* (c) Loïck Piera <[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\import;
use function Castor\io;
use function Castor\notify;
use function Castor\variable;
import(__DIR__ . '/.castor');
/**
* @return array<string, mixed>
*/
function create_default_variables(): array
{
$projectName = '3dfollow';
$tld = 'test';
return [
'project_name' => $projectName,
'root_domain' => "{$projectName}.{$tld}",
'extra_domains' => [
"www.{$projectName}.{$tld}",
],
'php_version' => $_SERVER['DS_PHP_VERSION'] ?? '8.1',
'project_directory' => 'application',
];
}
#[AsTask(description: 'Builds and starts the infrastructure, then install the application (composer, yarn, ...)')]
function start(): void
{
infra\workers_stop();
infra\generate_certificates(false);
infra\build();
infra\up();
cache_clear();
install();
migrate();
infra\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')]
function install(): void
{
$basePath = sprintf('%s/%s', variable('root_dir'), variable('project_directory'));
if (is_file("{$basePath}/composer.json")) {
docker_compose_run('composer install -n --prefer-dist --optimize-autoloader');
}
if (is_file("{$basePath}/yarn.lock")) {
docker_compose_run('yarn');
} elseif (is_file("{$basePath}/package.json")) {
docker_compose_run('npm install');
}
}
#[AsTask(description: 'Clear the application cache', namespace: 'app')]
function cache_clear(): void
{
docker_compose_run('rm -rf var/cache/ && bin/console cache:warmup');
}
#[AsTask(description: 'Migrates database schema', namespace: 'app:db')]
function migrate(): void
{
docker_compose_run('bin/console doctrine:database:create --if-not-exists');
docker_compose_run('bin/console doctrine:migration:migrate -n --allow-no-migration');
}