Skip to content

Commit

Permalink
Added InstallCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniputra committed May 13, 2024
1 parent 20055f7 commit 90f5c6d
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/ngeblog-admin-assets/ngeblog.css

Large diffs are not rendered by default.

36 changes: 28 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

# Ngeblog

It's a quick start to have a simple **Blogging System** for your existing or brand-new Laravel application. Ngeblog provides a simple and elegant admin panel built with Vue and DaisyUI as an SPA App.
It helps you to quickly set up a simple **Blogging System** for your existing or brand-new Laravel application. Ngeblog provides a simple and elegant admin panel built with `Vue` and `Daisy UI` as a **Modern SPA App**.

### Features

- BlogPost with [Tiptap Editor](https://tiptap.dev).
- Tagging feature.
- Dashboard for summary information.
- Dashboard.
- Starter Page.
- and more...

### Screenshot
Expand All @@ -28,15 +29,32 @@ It's a quick start to have a simple **Blogging System** for your existing or bra

## Installation

1. `composer require antoniputra/ngeblog`
2. `php artisan vendor:publish`
3. `php artisan migrate`
4. You done!
```bash
composer require antoniputra/ngeblog
```

Resolve the installation:
```bash
php artisan ngeblog:install
```


## Configuration

Once this package already installed, by default it will provide admin panel at `/ngeblog` with no protection. You can add your own protection like below:
After installation, by default will provide an admin panel at `https://your-web.test/ngeblog` and only available for authenticated user.

Follow below section to customize as you wish.

### Change Admin Panel URL

Go to your `.env` and put new key value:
```env
NGEBLOG_PATH='blog-admin-panel'
```

### Protect Admin Panel

You can add your own protection logic like below:

```php
// App/Providers/AppServiceProvider.php
Expand All @@ -56,4 +74,6 @@ Gate::define('accessNgeblogAdmin', function ($user) {

## License

**Ngeblog** is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
**Ngeblog** is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

Built with love by @antoni_putra12 and made better by you.
66 changes: 59 additions & 7 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace AntoniPutra\Ngeblog\Console;

use AntoniPutra\Ngeblog\NgeblogServiceProvider;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;

use function Laravel\Prompts\confirm;

class InstallCommand extends Command
{
Expand All @@ -18,22 +22,70 @@ class InstallCommand extends Command
*
* @var string
*/
protected $description = 'Install the Ngeblog package.';
protected $description = 'Install the Ngeblog admin panel and resources.';

/**
* Execute the console command.
*/
public function handle()
{
// TODO Finish copyo from stubs into Consumer directory
$this->line('');
$this->call('vendor:publish', ['--provider' => NgeblogServiceProvider::class]);

// TODO - Copy routes/ngeblog.php from stubs.
// ...
$this->line('');
$this->runDatabaseMigrations();

// TODO - Copy Controllers file from stubs.
// copy(__DIR__ .'/../../stubs/Http/Controllers/', '');
$this->line('');
$this->installStarterPage();

$this->line('');
$this->components->info('Installation completed. You might access admin panel here: '. route('ngeblog.index'));
}

protected function runDatabaseMigrations()
{
if (confirm('New database migrations were added. Would you like to run your migrations?', true)) {
$this->call('migrate', ['--force' => true]);
}
}

protected function installStarterPage()
{
$confirmed = confirm(
label: 'Do you want to install Starter Page scaffolding?',
default: false,
yes: 'Yep, Please!',
no: 'Nope.',
// hint: ''
);

if (! $confirmed) {
return;
}

// TODO - Copy Controllers file from stubs.
copy(__DIR__ .'/../../stubs/Http/Controllers/NgeblogPostController.php', app_path('Http/Controllers/NgeblogPostController.php'));

// TODO - Copy blade views file from stubs
// ...
(new Filesystem)->copyDirectory(__DIR__ .'/../../stubs/ngeblog', resource_path('views/ngeblog'));

// TODO - Copy routes/ngeblog.php from stubs
// TODO - and write require inside web.php of consumer.
copy(__DIR__ .'/../../stubs/routes/ngeblog.php', base_path('routes/ngeblog.php'));
(new Filesystem)->append(
base_path('routes/web.php'),
$this->publicPageRouteDefinition()
);

$this->components->info('Ngeblog Default Public Page scaffolding installed successfully.');
}

protected function publicPageRouteDefinition()
{
return <<<'EOF'
require __DIR__.'/ngeblog.php';

EOF;
}
}
14 changes: 14 additions & 0 deletions src/NgeblogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AntoniPutra\Ngeblog;

use AntoniPutra\Ngeblog\Console\InstallCommand;
use AntoniPutra\Ngeblog\Http\Middleware\AdminAuthorization;
use AntoniPutra\Ngeblog\Models\Post;
use Illuminate\Support\Facades\Gate;
Expand All @@ -23,6 +24,7 @@ public function boot(): void
$this->bootRoutes();
$this->bootAdminAssetRoute();
$this->bootDefaultAuthorization();
$this->configureCommands();

$this->loadViewsFrom(__DIR__.'/../resources/views', 'ngeblog');
}
Expand Down Expand Up @@ -86,4 +88,16 @@ protected function bootDefaultAuthorization(): void
return true;
});
}

protected function configureCommands()
{
if (! $this->app->runningInConsole()) {
return;
}

$this->commands([
InstallCommand::class,
]);
}

}
12 changes: 12 additions & 0 deletions stubs/routes/ngeblog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\NgeblogPostController;

Route::controller(NgeblogPostController::class)
->prefix('blogs')
->name('blogs.')
->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/{ngeblogPost}', 'show')->name('show');
});

0 comments on commit 90f5c6d

Please sign in to comment.