| @@ 10-82 (lines=73) @@ | ||
| 7 | use Consigliere\Components\Publishing\AssetPublisher; |
|
| 8 | use Symfony\Component\Console\Input\InputArgument; |
|
| 9 | ||
| 10 | class PublishAssetCommand extends ComponentCommand |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * The console command name. |
|
| 14 | * |
|
| 15 | * @var string |
|
| 16 | */ |
|
| 17 | protected $name = 'component:publish-asset'; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * The console command description. |
|
| 21 | * |
|
| 22 | * @var string |
|
| 23 | */ |
|
| 24 | protected $description = 'Publish a component\'s assets to the application'; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Execute the console command. |
|
| 28 | * |
|
| 29 | * @return mixed |
|
| 30 | */ |
|
| 31 | public function fire() |
|
| 32 | { |
|
| 33 | if ($name = $this->argument('component')) { |
|
| 34 | return $this->publish($name); |
|
| 35 | } |
|
| 36 | ||
| 37 | $this->publishAll(); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Publish assets from all components. |
|
| 42 | */ |
|
| 43 | public function publishAll() |
|
| 44 | { |
|
| 45 | foreach ($this->laravel['components']->enabled() as $component) { |
|
| 46 | $this->publish($component); |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * Publish assets from the specified component. |
|
| 52 | * |
|
| 53 | * @param string $name |
|
| 54 | */ |
|
| 55 | public function publish($name) |
|
| 56 | { |
|
| 57 | if ($name instanceof Component) { |
|
| 58 | $component = $name; |
|
| 59 | } else { |
|
| 60 | $component = $this->laravel['components']->findOrFail($name); |
|
| 61 | } |
|
| 62 | ||
| 63 | with(new AssetPublisher($component)) |
|
| 64 | ->setRepository($this->laravel['components']) |
|
| 65 | ->setConsole($this) |
|
| 66 | ->publish(); |
|
| 67 | ||
| 68 | $this->line("<info>Published</info>: {$component->getStudlyName()}"); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * Get the console command arguments. |
|
| 73 | * |
|
| 74 | * @return array |
|
| 75 | */ |
|
| 76 | protected function getArguments() |
|
| 77 | { |
|
| 78 | return [ |
|
| 79 | ['component', InputArgument::OPTIONAL, 'The name of component will be used.'], |
|
| 80 | ]; |
|
| 81 | } |
|
| 82 | } |
|
| 83 | ||
| @@ 10-82 (lines=73) @@ | ||
| 7 | use Consigliere\Components\Publishing\LangPublisher; |
|
| 8 | use Symfony\Component\Console\Input\InputArgument; |
|
| 9 | ||
| 10 | class PublishTranslationCommand extends ComponentCommand |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * The console command name. |
|
| 14 | * |
|
| 15 | * @var string |
|
| 16 | */ |
|
| 17 | protected $name = 'component:publish-translation'; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * The console command description. |
|
| 21 | * |
|
| 22 | * @var string |
|
| 23 | */ |
|
| 24 | protected $description = 'Publish a component\'s translations to the application'; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Execute the console command. |
|
| 28 | * |
|
| 29 | * @return mixed |
|
| 30 | */ |
|
| 31 | public function fire() |
|
| 32 | { |
|
| 33 | if ($name = $this->argument('component')) { |
|
| 34 | return $this->publish($name); |
|
| 35 | } |
|
| 36 | ||
| 37 | $this->publishAll(); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Publish assets from all components. |
|
| 42 | */ |
|
| 43 | public function publishAll() |
|
| 44 | { |
|
| 45 | foreach ($this->laravel['components']->enabled() as $component) { |
|
| 46 | $this->publish($component); |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * Publish assets from the specified component. |
|
| 52 | * |
|
| 53 | * @param string $name |
|
| 54 | */ |
|
| 55 | public function publish($name) |
|
| 56 | { |
|
| 57 | if ($name instanceof Component) { |
|
| 58 | $component = $name; |
|
| 59 | } else { |
|
| 60 | $component = $this->laravel['components']->findOrFail($name); |
|
| 61 | } |
|
| 62 | ||
| 63 | with(new LangPublisher($component)) |
|
| 64 | ->setRepository($this->laravel['components']) |
|
| 65 | ->setConsole($this) |
|
| 66 | ->publish(); |
|
| 67 | ||
| 68 | $this->line("<info>Published</info>: {$component->getStudlyName()}"); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * Get the console command arguments. |
|
| 73 | * |
|
| 74 | * @return array |
|
| 75 | */ |
|
| 76 | protected function getArguments() |
|
| 77 | { |
|
| 78 | return [ |
|
| 79 | ['component', InputArgument::OPTIONAL, 'The name of component will be used.'], |
|
| 80 | ]; |
|
| 81 | } |
|
| 82 | } |
|
| 83 | ||