|
18 | 18 | use Symfony\Component\Console\Input\InputOption;
|
19 | 19 | use Symfony\Component\Console\Output\OutputInterface;
|
20 | 20 | use Symfony\Component\Console\Style\SymfonyStyle;
|
| 21 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
21 | 22 | use Symfony\Component\Filesystem\Exception\IOException;
|
22 | 23 | use Symfony\Component\Filesystem\Filesystem;
|
23 | 24 | use Symfony\Component\Finder\Finder;
|
@@ -55,7 +56,7 @@ protected function configure()
|
55 | 56 | {
|
56 | 57 | $this
|
57 | 58 | ->setDefinition(array(
|
58 |
| - new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'), |
| 59 | + new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', null), |
59 | 60 | ))
|
60 | 61 | ->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
|
61 | 62 | ->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks')
|
@@ -92,6 +93,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
|
92 | 93 | $kernel = $this->getApplication()->getKernel();
|
93 | 94 | $targetArg = rtrim($input->getArgument('target'), '/');
|
94 | 95 |
|
| 96 | + if (!$targetArg) { |
| 97 | + $targetArg = $this->getPublicDirectory($this->getContainer()); |
| 98 | + } |
| 99 | + |
95 | 100 | if (!is_dir($targetArg)) {
|
96 | 101 | $targetArg = $kernel->getContainer()->getParameter('kernel.project_dir').'/'.$targetArg;
|
97 | 102 |
|
@@ -248,4 +253,27 @@ private function hardCopy(string $originDir, string $targetDir): string
|
248 | 253 |
|
249 | 254 | return self::METHOD_COPY;
|
250 | 255 | }
|
| 256 | + |
| 257 | + private function getPublicDirectory(ContainerInterface $container) |
| 258 | + { |
| 259 | + $defaultPublicDir = 'public'; |
| 260 | + |
| 261 | + if (!$container->hasParameter('kernel.project_dir')) { |
| 262 | + return $defaultPublicDir; |
| 263 | + } |
| 264 | + |
| 265 | + $composerFilePath = $container->getParameter('kernel.project_dir').'/composer.json'; |
| 266 | + |
| 267 | + if (!file_exists($composerFilePath)) { |
| 268 | + return $defaultPublicDir; |
| 269 | + } |
| 270 | + |
| 271 | + $composerConfig = json_decode(file_get_contents($composerFilePath), true); |
| 272 | + |
| 273 | + if (isset($composerConfig['extra']['public-dir'])) { |
| 274 | + return $composerConfig['extra']['public-dir']; |
| 275 | + } |
| 276 | + |
| 277 | + return $defaultPublicDir; |
| 278 | + } |
251 | 279 | }
|
0 commit comments