Skip to content

Commit

Permalink
Dev-tisna (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnamuliarta authored Mar 14, 2024
2 parents b302cc6 + b902952 commit f626a1d
Show file tree
Hide file tree
Showing 50 changed files with 1,606 additions and 720 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2

[*.{ts,tsx,json,js,css}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
Empty file.
62 changes: 62 additions & 0 deletions Modules/Master/App/Http/Controllers/MasterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Modules\Master\App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class MasterController extends Controller
{
public array $data = [];

/**
* Display a listing of the resource.
*/
public function index(): JsonResponse
{
//

return response()->json($this->data);
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request): JsonResponse
{
//

return response()->json($this->data);
}

/**
* Show the specified resource.
*/
public function show($id): JsonResponse
{
//

return response()->json($this->data);
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): JsonResponse
{
//

return response()->json($this->data);
}

/**
* Remove the specified resource from storage.
*/
public function destroy($id): JsonResponse
{
//

return response()->json($this->data);
}
}
Empty file.
114 changes: 114 additions & 0 deletions Modules/Master/App/Providers/MasterServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace Modules\Master\App\Providers;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class MasterServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Master';

protected string $moduleNameLower = 'master';

/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'Database/migrations'));
}

/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(RouteServiceProvider::class);
}

/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}

/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}

/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);

if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
}
}

/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}

/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');

$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);

$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);

$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.config('modules.paths.generator.component-class.path'));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}

/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}

private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
$paths[] = $path.'/modules/'.$this->moduleNameLower;
}
}

return $paths;
}
}
59 changes: 59 additions & 0 deletions Modules/Master/App/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Modules\Master\App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
/**
* The module namespace to assume when generating URLs to actions.
*/
protected string $moduleNamespace = 'Modules\Master\App\Http\Controllers';

/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}

/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();

$this->mapWebRoutes();
}

/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')
->namespace($this->moduleNamespace)
->group(module_path('Master', '/routes/web.php'));
}

/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::prefix('api')
->middleware('api')
->namespace($this->moduleNamespace)
->group(module_path('Master', '/routes/api.php'));
}
}
Empty file.
16 changes: 16 additions & 0 deletions Modules/Master/Database/Seeders/MasterDatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Modules\Master\Database\Seeders;

use Illuminate\Database\Seeder;

class MasterDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// $this->call([]);
}
}
31 changes: 31 additions & 0 deletions Modules/Master/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "nwidart/master",
"description": "",
"authors": [
{
"name": "Nicolas Widart",
"email": "[email protected]"
}
],
"extra": {
"laravel": {
"providers": [],
"aliases": {

}
}
},
"autoload": {
"psr-4": {
"Modules\\Master\\": "",
"Modules\\Master\\App\\": "app/",
"Modules\\Master\\Database\\Factories\\": "database/factories/",
"Modules\\Master\\Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Modules\\Master\\Tests\\": "tests/"
}
}
}
Empty file added Modules/Master/config/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions Modules/Master/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'name' => 'Master',
];
11 changes: 11 additions & 0 deletions Modules/Master/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Master",
"alias": "master",
"description": "",
"keywords": [],
"priority": 0,
"providers": [
"Modules\\Master\\App\\Providers\\MasterServiceProvider"
],
"files": []
}
15 changes: 15 additions & 0 deletions Modules/Master/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"axios": "^1.1.2",
"laravel-vite-plugin": "^0.7.5",
"sass": "^1.69.5",
"postcss": "^8.3.7",
"vite": "^4.0.0"
}
}
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions Modules/Master/resources/views/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@extends('master::layouts.master')

@section('content')
<h1>Hello World</h1>

<p>Module: {!! config('master.name') !!}</p>
@endsection
29 changes: 29 additions & 0 deletions Modules/Master/resources/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title>Master Module - {{ config('app.name', 'Laravel') }}</title>

<meta name="description" content="{{ $description ?? '' }}">
<meta name="keywords" content="{{ $keywords ?? '' }}">
<meta name="author" content="{{ $author ?? '' }}">

<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />

{{-- Vite CSS --}}
{{-- {{ module_vite('build-master', 'resources/assets/sass/app.scss') }} --}}
</head>

<body>
@yield('content')

{{-- Vite JS --}}
{{-- {{ module_vite('build-master', 'resources/assets/js/app.tsx') }} --}}
</body>
Empty file added Modules/Master/routes/.gitkeep
Empty file.
19 changes: 19 additions & 0 deletions Modules/Master/routes/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware(['auth:sanctum'])->prefix('v1')->name('api.')->group(function () {
Route::get('master', fn (Request $request) => $request->user())->name('master');
});
Loading

0 comments on commit f626a1d

Please sign in to comment.