|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
|
|
7
|
|
|
class SetupCommand extends Command |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The console command name. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $name = 'module:setup'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The console command description. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $description = 'Setting up modules folders for first use.'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Execute the console command. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function handle() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->generateModulesFolder(); |
|
29
|
|
|
|
|
30
|
|
|
$this->generateAssetsFolder(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Generate the modules folder. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function generateModulesFolder() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->generateDirectory( |
|
39
|
|
|
$this->laravel['modules']->config('paths.modules'), |
|
40
|
|
|
'Modules directory created successfully', |
|
41
|
|
|
'Modules directory already exist' |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Generate the assets folder. |
|
47
|
|
|
*/ |
|
48
|
|
|
public function generateAssetsFolder() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->generateDirectory( |
|
51
|
|
|
$this->laravel['modules']->config('paths.assets'), |
|
52
|
|
|
'Assets directory created successfully', |
|
53
|
|
|
'Assets directory already exist' |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Generate the specified directory by given $dir. |
|
59
|
|
|
* |
|
60
|
|
|
* @param $dir |
|
61
|
|
|
* @param $success |
|
62
|
|
|
* @param $error |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function generateDirectory($dir, $success, $error) |
|
65
|
|
|
{ |
|
66
|
|
|
if (!$this->laravel['files']->isDirectory($dir)) { |
|
67
|
|
|
$this->laravel['files']->makeDirectory($dir); |
|
68
|
|
|
|
|
69
|
|
|
$this->info($success); |
|
70
|
|
|
|
|
71
|
|
|
return; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$this->error($error); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|