2
2
3
3
declare (strict_types=1 );
4
4
5
+ use Castor \Attribute \AsArgument ;
5
6
use Castor \Attribute \AsOption ;
6
7
use Castor \Attribute \AsTask ;
7
- use dcorroyer \mybudget \Docker \DockerUtils ;
8
+ use TheoD \MusicAutoTagger \ContainerDefinitionBag ;
9
+ use TheoD \MusicAutoTagger \Docker \DockerUtils ;
8
10
11
+ use function Castor \Attribute \AsArgument ;
9
12
use function Castor \capture ;
10
13
use function Castor \context ;
11
14
use function Castor \finder ;
15
+ use function Castor \fingerprint ;
16
+ use function Castor \fs ;
12
17
use function Castor \import ;
13
18
use function Castor \io ;
14
- use function Castor \notify ;
15
19
use function Castor \run ;
16
- use function dcorroyer \mybudget \delayed_fingerprint ;
17
- use function dcorroyer \mybudget \docker ;
18
- use function dcorroyer \mybudget \fgp ;
19
- use function dcorroyer \mybudget \Runner \composer ;
20
- use function dcorroyer \mybudget \Runner \npm ;
21
- use function dcorroyer \mybudget \Runner \qa ;
20
+ use function TheoD \MusicAutoTagger \app_context ;
21
+ use function TheoD \MusicAutoTagger \docker ;
22
+ use function TheoD \MusicAutoTagger \fgp ;
23
+ use function TheoD \MusicAutoTagger \Runner \composer ;
24
+ use function TheoD \MusicAutoTagger \Runner \pnpm ;
25
+ use function TheoD \MusicAutoTagger \Runner \qa ;
26
+ use function TheoD \MusicAutoTagger \Runner \symfony ;
22
27
23
28
import ('composer://theod02/castor-class-task ' );
24
29
@@ -35,18 +40,19 @@ function start(bool $force = false): void
35
40
}
36
41
37
42
if (
38
- ! delayed_fingerprint (
43
+ ! fingerprint (
39
44
callback: static fn () => docker ()
40
- ->compose ('--profile ' , 'app ' , 'build ' , '--no-cache ' )
45
+ ->compose ('-f ' , 'compose.yaml ' , '-f ' , 'compose.override.yaml ' , ' build ' )
41
46
->run (),
42
- fingerprint: static fn () => fgp ()->php_docker (),
43
- force: $ force
47
+ id: 'docker ' ,
48
+ fingerprint: fgp ()->php_docker (),
49
+ force: $ force ,
44
50
)
45
51
) {
46
52
io ()->note ('Docker images are already built. ' );
47
53
}
48
54
49
- docker ()->compose ('--profile ' , 'app ' , 'up ' , '-d ' , '--wait ' )->run ();
55
+ docker ()->compose ('-f ' , ' compose.yaml ' , ' -f ' , 'compose.override.yaml ' , 'up ' , '-d ' , '--wait ' )->run ();
50
56
}
51
57
52
58
#[AsTask]
@@ -69,46 +75,71 @@ function install(bool $force = false): void
69
75
70
76
io ()->title ('Installing dependencies ' );
71
77
io ()->section ('Composer ' );
72
- $ forceVendor = $ force || ! is_dir (context ()->workingDirectory . '/vendor ' );
73
- if (! delayed_fingerprint (
78
+ $ forceVendor = $ force || ! is_dir (app_context ()->workingDirectory . '/vendor ' );
79
+ if (! fingerprint (
74
80
callback: static fn () => composer ()->install ()->run (),
75
- fingerprint: static fn () => fgp ()->composer (),
76
- force: $ forceVendor || $ force
81
+ id: 'composer ' ,
82
+ fingerprint: fgp ()->composer (),
83
+ force: $ forceVendor || $ force ,
77
84
)) {
78
85
io ()->note ('Composer dependencies are already installed. ' );
79
86
} else {
80
87
io ()->success ('Composer dependencies installed ' );
81
88
}
82
89
90
+ // io()->section('Generate auth Keypair');
91
+ // if (fs()->exists(app_context()->workingDirectory . '/config/jwt/private.pem')) {
92
+ // io()->note('Auth keypair already exists');
93
+ // } else {
94
+ // symfony()->console('lexik:jwt:generate-keypair')->run();
95
+ // }
96
+
83
97
io ()->section ('QA tools ' );
84
98
qa ()->install ();
85
99
86
- io ()->section ('NPM ' );
87
- $ forceNodeModules = $ force || ! is_dir (context ()->workingDirectory . '/node_modules ' );
88
- if (! delayed_fingerprint (
89
- callback: static fn () => npm ()->install ()->run (),
90
- fingerprint: static fn () => fgp ()->npm (),
91
- force: $ forceNodeModules || $ force
92
- )) {
93
- io ()->note ('NPM dependencies are already installed. ' );
94
- } else {
95
- io ()->success ('NPM dependencies installed ' );
100
+ if (pnpm ()->hasPackageJson ()) {
101
+ io ()->section ('NPM ' );
102
+ $ forceNodeModules = $ force || ! is_dir (app_context ()->workingDirectory . '/node_modules ' );
103
+ if (! fingerprint (
104
+ callback: static fn () => pnpm ()->install ()->run (),
105
+ id: 'npm ' ,
106
+ fingerprint: fgp ()->npm (),
107
+ force: $ forceNodeModules || $ force ,
108
+ )) {
109
+ io ()->note ('NPM dependencies are already installed. ' );
110
+ } else {
111
+ io ()->success ('NPM dependencies installed ' );
112
+ }
113
+
114
+ pnpm ()->add ('run ' , 'build ' )->run ();
96
115
}
97
116
98
- npm ()->add ('run ' , 'build ' )->run ();
117
+ db_reset ();
118
+
119
+ // notify('Dependencies installed');
120
+ }
99
121
100
- notify ('Dependencies installed ' );
122
+ #[AsTask(name: 'sync ' )]
123
+ function sync (): void
124
+ {
125
+ symfony ()->console ('spotify:sync ' )->run ();
126
+ symfony ()->console ('spotify:sync:artists:full ' )->run ();
127
+ symfony ()->console ('spotify:sync:tracks:full ' )->run ();
128
+ symfony ()->console ('spotify:sync:tracks:full:audio-feature ' )->run ();
101
129
}
102
130
103
131
#[AsTask]
104
132
function shell (
105
133
#[AsOption(name: 'no-check ' , description: 'Don \'t check the dependencies ' )]
106
- bool $ noCheck = false // Not used here, but used in listeners.php
134
+ bool $ noCheck = false , // Not used here, but used in listeners.php,
135
+ #[AsArgument(name: 'cmd ' , description: 'Command to run ' )]
136
+ ?string $ command = null ,
107
137
): void {
108
138
docker (context ()->withTty ())
109
139
->compose ('exec ' )
110
140
->add ('--user ' , 'www-data ' )
111
- ->add ('app ' , 'fish ' )
141
+ ->add (ContainerDefinitionBag::php ()->composeName , 'fish ' )
142
+ ->addIf ($ command !== null , '-c ' , "\"{$ command }\"" )
112
143
->run ()
113
144
;
114
145
}
@@ -117,10 +148,10 @@ function shell(
117
148
#[AsTask]
118
149
function generate_domain_dir (string $ domainName ): void
119
150
{
120
- $ srcDirectory = context ()->workingDirectory . '/src ' ;
151
+ $ srcDirectory = app_context ()->workingDirectory . '/src ' ;
121
152
$ domainName = ucfirst ($ domainName );
122
153
123
- $ domainDirectory = $ srcDirectory . ' / ' . $ domainName ;
154
+ $ domainDirectory = "{ $ srcDirectory} / { $ domainName}" ;
124
155
125
156
if (is_dir ($ domainDirectory )) {
126
157
io ()->error ("Domain directory {$ domainName } already exists " );
@@ -212,13 +243,13 @@ function import_sql(): void
212
243
#[AsTask(name: 'ui:install ' )]
213
244
function ui_install (): void
214
245
{
215
- npm ()->install ();
246
+ pnpm ()->install ();
216
247
}
217
248
218
249
#[AsTask(name: 'ui:dev ' )]
219
250
function ui_dev (): void
220
251
{
221
- npm (context ()->withTty ())->add ('run ' , 'dev ' )->run ();
252
+ pnpm (context ()->withTty ())->add ('run ' , 'dev ' )->run ();
222
253
}
223
254
224
255
#[AsTask(name: 'ui:format ' )]
@@ -265,7 +296,33 @@ function ui_http_schema(): void
265
296
->compose ('exec ' )
266
297
->add ('--user ' , 'www-data ' )
267
298
->add ('--workdir ' , '/app/assets ' )
268
- ->add ('app ' , 'npx ' , 'openapi-typescript ' , 'http://music-auto-tagger.web.localhost/api/docs.json ' , '-o ' , './src/api/schema.d.ts ' )
299
+ ->add (
300
+ 'app ' ,
301
+ 'npx ' ,
302
+ 'openapi-typescript ' ,
303
+ 'http://mantine-starter-kit.web.localhost/api/docs.json ' ,
304
+ '-o ' ,
305
+ './src/api/schema.d.ts ' ,
306
+ )
269
307
->run ()
270
308
;
271
309
}
310
+
311
+ #[AsTask(name: 'db:reset ' )]
312
+ function db_reset (): void
313
+ {
314
+ // Check if the database app exists
315
+ $ output = docker (context ()->withQuiet ())->compose (
316
+ "exec -it database sh -c \"psql -d app -c ' \\l' \"" ,
317
+ )->run ()->getOutput ();
318
+ if (str_contains ($ output , 'app ' )) {
319
+ if (io ()->confirm ('The database "app" already exists. Do you want to drop it? ' , false ) === false ) {
320
+ return ;
321
+ }
322
+ }
323
+
324
+ symfony ()->console ('doctrine:database:drop ' , '--force ' , '--if-exists ' )->run ();
325
+ symfony ()->console ('doctrine:database:create ' )->run ();
326
+ symfony ()->console ('doctrine:migrations:migrate ' , '--allow-no-migration ' , '--no-interaction ' )->run ();
327
+ symfony ()->console ('doctrine:fixtures:load ' , '--no-interaction ' , '--append ' )->run ();
328
+ }
0 commit comments