First Commit
This commit is contained in:
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ModulePublishCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'module:publish';
|
||||
protected static $defaultDescription = 'Copia os assets de um módulo para a pasta public do sistema';
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('module', InputArgument::REQUIRED, 'O nome do módulo');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$module = strtolower($input->getArgument('module'));
|
||||
$modulePath = dirname(__DIR__, 3) . "/modules/{$module}";
|
||||
|
||||
if (!is_dir($modulePath)) {
|
||||
$output->writeln("<error>Módulo '{$module}' não encontrado.</error>");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$assetsPath = "{$modulePath}/assets";
|
||||
if (!is_dir($assetsPath)) {
|
||||
$output->writeln("<comment>Nenhum diretório 'assets' encontrado no módulo '{$module}'.</comment>");
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$publicPath = dirname(__DIR__, 3) . "/public/assets/modules/{$module}";
|
||||
|
||||
if (!is_dir($publicPath)) {
|
||||
mkdir($publicPath, 0755, true);
|
||||
}
|
||||
|
||||
$output->writeln("<info>Copiando assets de '{$module}' para 'public/assets/modules/{$module}'...</info>");
|
||||
|
||||
$this->copyDirectory($assetsPath, $publicPath);
|
||||
|
||||
$output->writeln("<info>Assets publicados com sucesso!</info>");
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
protected function copyDirectory($source, $destination)
|
||||
{
|
||||
$dir = opendir($source);
|
||||
@mkdir($destination);
|
||||
while (false !== ($file = readdir($dir))) {
|
||||
if (($file != '.') && ($file != '..')) {
|
||||
if (is_dir($source . '/' . $file)) {
|
||||
$this->copyDirectory($source . '/' . $file, $destination . '/' . $file);
|
||||
} else {
|
||||
copy($source . '/' . $file, $destination . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user