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