<?php
namespace Deployer;

require 'recipe/symfony.php';
// require 'contrib/webpack_encore.php';
require 'contrib/npm.php';

// Config
set('nodejs_version', 'node_22.x');
set('keep_releases', '3');
set('repository', 'gitea@git.test.nestor-server.fr:Colgora/Mangarr.git');
set('webpack_encore/env', 'production');
set('composer_options', '--verbose --prefer-dist --no-progress --no-interaction --optimize-autoloader');

set('shared_files', ['.env.local','var/log/prod.log']);
set('shared_dirs', ['config/secrets','public/cbz','public/tmp','public/images']);
// add('writable_dirs', []);

desc('Runs webpack encore build');
task('webpack_encore:build', function () {
    run("cd {{release_path}} && npm run build");
});

desc('Run messenger consume');
task('messenger:consume', function () {
    run("sudo supervisorctl restart messenger-consume:*");
});

host('mangarr.test.nestor-server.fr')
    ->set('remote_user', 'colgora')
    ->set('deploy_path', '/var/www/mangarr')
    ->set('branch', 'main');

// Hooks
after('deploy:vendors', 'npm:install');
after('npm:install', 'webpack_encore:build');
after('deploy:vendors', 'database:migrate');
after('deploy:symlink', 'messenger:consume');
after('deploy:failed', 'deploy:unlock');
