Passed
Push — main ( 0290e9...b434a8 )
by PRATIK
03:39 queued 11s
created

InstallAdmineticCommand::addHeader()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
c 0
b 0
f 0
nc 4
nop 0
dl 0
loc 14
rs 9.9666
1
<?php
2
3
namespace Pratiksh\Adminetic\Console\Commands;
4
5
use Illuminate\Console\Command;
6
7
class InstallAdmineticCommand extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'install:adminetic';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Command to install adminetic';
22
23
    /**
24
     * Create a new command instance.
25
     *
26
     * @return void
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return int
37
     */
38
    public function handle()
39
    {
40
        $this->call('vendor:publish', [
41
            '--tag' => ['adminetic-config'],
42
        ]);
43
        $this->info('Adminetic config file published ... ✅');
44
        $this->call('vendor:publish', [
45
            '--tag' => ['adminetic-assets-files'],
46
        ]);
47
        $this->info('Adminetic asset files published ... ✅');
48
        $this->call('vendor:publish', [
49
            '--tag' => ['adminetic-static-files'],
50
        ]);
51
        $this->info('Adminetic static files published ... ✅');
52
        $this->addMyMenu();
53
        $this->info('My Menu Added ... ✅');
54
        $this->addMyDashboard();
55
        $this->info('My Dashboard Added ... ✅');
56
        $this->addAdminServiceProvider();
57
        if ($this->confirm('Do you wish to extend header ?')) {
58
            $this->addHeader();
59
        }
60
        if ($this->confirm('Do you wish to extend footer ?')) {
61
            $this->addFooter();
62
        }
63
        $this->info('Adminetic Installed');
64
        $this->info('Star to the admenictic repo would be appreciated.');
65
    }
66
67
    private function addAdminServiceProvider()
68
    {
69
        $adminServiceProviderTemplate = file_get_contents(__DIR__ . '/../../Console/Commands/AdminStubs/AdminServiceProvider.stub');
70
        $adminServiceProviderfile = app_path('Providers/AdminServiceProvider.php');
71
        file_put_contents($adminServiceProviderfile, $adminServiceProviderTemplate);
72
        if (file_exists($adminServiceProviderfile)) {
73
            $this->info('AdminServiceProvider created successfully ... ✅');
74
        } else {
75
            $this->error('Failed to create AdminServiceProvider ...');
76
        }
77
    }
78
79
    private function addMyMenu()
80
    {
81
        $modelTemplate = file_get_contents(__DIR__ . '/../../Console/Commands/AdminStubs/MyMenu.stub');
82
83
        if (!file_exists($path = app_path('Services'))) {
84
            mkdir($path, 0777, true);
85
        }
86
87
        $file = app_path('Services/MyMenu.php');
88
        file_put_contents($file, $modelTemplate);
89
        if (file_exists($file)) {
90
            $this->info('MyMenu created successfully ... ✅');
91
        } else {
92
            $this->error('Failed to create MyMenu ...');
93
        }
94
    }
95
96
    private function addMyDashboard()
97
    {
98
        $myDashboardTemplate = file_get_contents(__DIR__ . '/../../Console/Commands/AdminStubs/MyDashboard.stub');
99
        $myDashboardIndexTemplate = file_get_contents(__DIR__ . '/../../Console/Commands/AdminStubs/DashboardIndex.stub');
100
101
        if (!file_exists($path = app_path('Services'))) {
102
            mkdir($path, 0777, true);
103
        }
104
        if (!file_exists($path = resource_path('views/admin/dashboard'))) {
105
            mkdir($path, 0777, true);
106
        }
107
        if (!file_exists($path = resource_path('views/admin/layouts/modules/dashboard'))) {
108
            mkdir($path, 0777, true);
109
        }
110
        $myDashboardIndexfile = resource_path('views/admin/dashboard/index.blade.php');
111
        file_put_contents($myDashboardIndexfile, $myDashboardIndexTemplate);
112
        if (file_exists($myDashboardIndexfile)) {
113
            $this->info('MyDashboardIndex created successfully ... ✅');
114
        } else {
115
            $this->error('Failed to create MyDashboardIndex ...');
116
        }
117
        $dashboardScript = resource_path('views/admin/layouts/modules/dashboard/scripts.blade.php');
118
        file_put_contents(resource_path('views/admin/layouts/modules/dashboard/scripts.blade.php'), '');
119
        if (file_exists($dashboardScript)) {
120
            $this->info('MyDashboardScripts created successfully ... ✅');
121
        } else {
122
            $this->error('Failed to create MyDashboardScripts ...');
123
        }
124
125
        $myDashboardFilefile = app_path('Services/MyDashboard.php');
126
        file_put_contents($myDashboardFilefile, $myDashboardTemplate);
127
        if (file_exists($myDashboardFilefile)) {
128
            $this->info('MyDashboard created successfully ... ✅');
129
        } else {
130
            $this->error('Failed to create MyDashboard ...');
131
        }
132
    }
133
134
    protected function addHeader()
135
    {
136
        $myHeaderTemplate = file_get_contents(__DIR__ . '/../../Console/Commands/AdminStubs/HeaderView.stub');
137
138
        if (!file_exists($path = resource_path('views/admin/layouts/components'))) {
139
            mkdir($path, 0777, true);
140
        }
141
142
        $myHeaderFilefile = resource_path('views/admin/layouts/components/header.blade.php');
143
        file_put_contents($myHeaderFilefile, $myHeaderTemplate);
144
        if (file_exists($myHeaderFilefile)) {
145
            $this->info('Header view created successfully ... ✅');
146
        } else {
147
            $this->error('Failed to create header view ...');
148
        }
149
    }
150
151
    protected function addFooter()
152
    {
153
        $myFooterTemplate = file_get_contents(__DIR__ . '/../../Console/Commands/AdminStubs/FooterView.stub');
154
155
        if (!file_exists($path = resource_path('views/admin/layouts/components'))) {
156
            mkdir($path, 0777, true);
157
        }
158
159
        $myFooterFilefile = resource_path('views/admin/layouts/components/footer.blade.php');
160
        file_put_contents($myFooterFilefile, $myFooterTemplate);
161
        if (file_exists($myFooterFilefile)) {
162
            $this->info('Footer view created successfully ... ✅');
163
        } else {
164
            $this->error('Failed to create footer view ...');
165
        }
166
    }
167
168
    protected static function getStub($type)
169
    {
170
        return file_get_contents(__DIR__ . "/../../Console/Commands/AdminStubs/$type.stub");
171
    }
172
}
173