Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 9b6c9e0

Browse files
committed
autoreg
1 parent 1d2835c commit 9b6c9e0

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
]
2626
```
2727

28+
- after installation, package will auto-add
29+
+ package routes to `routes/web.php`
30+
+ package assets compiling to `webpack.mix.js`
31+
+ `MIX_SM_FRAMEWORK=bulma` to `.env`
32+
2833
- the package rely heavily on caching through **Redis**, so make sure to check the [docs](https://laravel.com/docs/5.4/redis) for installation & configuration.
2934

3035
- publish the packages assets with `php artisan vendor:publish`

src/SimpleMenuServiceProvider.php

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ctf0\SimpleMenu\Models\Menu;
66
use ctf0\SimpleMenu\Models\Page;
77
use Illuminate\Support\Facades\URL;
8+
use Illuminate\Filesystem\Filesystem;
89
use Illuminate\Support\ServiceProvider;
910
use ctf0\SimpleMenu\Observers\MenuObserver;
1011
use ctf0\SimpleMenu\Observers\PageObserver;
@@ -24,7 +25,19 @@ class SimpleMenuServiceProvider extends ServiceProvider
2425
/**
2526
* Perform post-registration booting of services.
2627
*/
27-
public function boot()
28+
public function boot(Filesystem $file)
29+
{
30+
$this->file = $file;
31+
32+
$this->packagePublish();
33+
34+
// append extra data
35+
if (!app('cache')->store('file')->has('ct-sm')) {
36+
$this->autoReg();
37+
}
38+
}
39+
40+
protected function packagePublish()
2841
{
2942
// config
3043
$this->publishes([
@@ -164,4 +177,60 @@ protected function regPMW()
164177
$this->app['router']->aliasMiddleware('localizationRedirect', LaravelLocalizationRedirectFilter::class);
165178
$this->app['router']->aliasMiddleware('localeSessionRedirect', LocaleSessionRedirect::class);
166179
}
180+
181+
/**
182+
* [autoReg description].
183+
*
184+
* @return [type] [description]
185+
*/
186+
protected function autoReg()
187+
{
188+
// routes
189+
$route_file = base_path('routes/web.php');
190+
$search = 'SimpleMenu';
191+
192+
if ($this->checkExist($route_file, $search)) {
193+
$data = "\n// SimpleMenu\nSimpleMenu::menuRoutes();";
194+
195+
$this->file->append($route_file, $data);
196+
}
197+
198+
// mix
199+
$mix_file = base_path('webpack.mix.js');
200+
$search = 'SimpleMenu';
201+
202+
if ($this->checkExist($mix_file, $search)) {
203+
$data = "\n// SimpleMenu\nmix.sass('resources/assets/vendor/SimpleMenu/sass/style.scss', 'public/assets/vendor/SimpleMenu/style.css').version();";
204+
205+
$this->file->append($mix_file, $data);
206+
}
207+
208+
// fw
209+
$env_file = base_path('.env');
210+
$search = 'MIX_SM_FRAMEWORK';
211+
212+
if ($this->checkExist($env_file, $search)) {
213+
$data = "\nMIX_SM_FRAMEWORK=bulma";
214+
215+
$this->file->append($env_file, $data);
216+
}
217+
218+
// run check once
219+
app('cache')->store('file')->rememberForever('ct-mm', function () {
220+
return 'added';
221+
});
222+
}
223+
224+
/**
225+
* [checkExist description].
226+
*
227+
* @param [type] $file [description]
228+
* @param [type] $search [description]
229+
*
230+
* @return [type] [description]
231+
*/
232+
protected function checkExist($file, $search)
233+
{
234+
return $this->file->exists($file) && !str_contains($this->file->get($file), $search);
235+
}
167236
}

src/resources/views/admin/bulma/shared.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
99
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bulma/0.6.0/css/bulma.min.css">
10+
<link rel="stylesheet" href="{{ asset('assets/vendor/SimpleMenu/style.css') }}"/>
1011

1112
{{-- jquery --}}
1213
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>

0 commit comments

Comments
 (0)