diff --git a/modules/Demo/app/Http/Controllers/.gitkeep b/modules/Demo/app/Http/Controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/app/Http/Controllers/Admin/Index.php b/modules/Demo/app/Http/Controllers/Admin/Index.php new file mode 100644 index 0000000..7959525 --- /dev/null +++ b/modules/Demo/app/Http/Controllers/Admin/Index.php @@ -0,0 +1,8 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $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->nameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->nameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $configPath = module_path($this->name, config('modules.paths.generator.config.path')); + + if (is_dir($configPath)) { + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath)); + + foreach ($iterator as $file) { + if ($file->isFile() && $file->getExtension() === 'php') { + $config = str_replace($configPath.DIRECTORY_SEPARATOR, '', $file->getPathname()); + $config_key = str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $config); + $segments = explode('.', $this->nameLower.'.'.$config_key); + + // Remove duplicated adjacent segments + $normalized = []; + foreach ($segments as $segment) { + if (end($normalized) !== $segment) { + $normalized[] = $segment; + } + } + + $key = ($config === 'config.php') ? $this->nameLower : implode('.', $normalized); + + $this->publishes([$file->getPathname() => config_path($config)], 'config'); + $this->merge_config_from($file->getPathname(), $key); + } + } + } + } + + /** + * Merge config from the given path recursively. + */ + protected function merge_config_from(string $path, string $key): void + { + $existing = config($key, []); + $module_config = require $path; + + config([$key => array_replace_recursive($existing, $module_config)]); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->nameLower); + $sourcePath = module_path($this->name, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower); + + Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower); + } + + /** + * 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->nameLower)) { + $paths[] = $path.'/modules/'.$this->nameLower; + } + } + + return $paths; + } +} diff --git a/modules/Demo/app/Providers/EventServiceProvider.php b/modules/Demo/app/Providers/EventServiceProvider.php new file mode 100644 index 0000000..1e31c61 --- /dev/null +++ b/modules/Demo/app/Providers/EventServiceProvider.php @@ -0,0 +1,27 @@ +> + */ + protected $listen = []; + + /** + * Indicates if events should be discovered. + * + * @var bool + */ + protected static $shouldDiscoverEvents = true; + + /** + * Configure the proper event listeners for email verification. + */ + protected function configureEmailVerification(): void {} +} diff --git a/modules/Demo/app/Providers/RouteServiceProvider.php b/modules/Demo/app/Providers/RouteServiceProvider.php new file mode 100644 index 0000000..1383315 --- /dev/null +++ b/modules/Demo/app/Providers/RouteServiceProvider.php @@ -0,0 +1,61 @@ +mapApiRoutes(); + $this->mapWebRoutes(); + $this->mapAdminRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + */ + protected function mapWebRoutes(): void + { + Route::middleware('web')->group(module_path($this->name, '/routes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapApiRoutes(): void + { + Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '/routes/api.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapAdminRoutes(): void + { + Route::middleware('admin')->prefix('admin')->name('admin.')->group(module_path($this->name, '/routes/admin.php')); + } +} diff --git a/modules/Demo/composer.json b/modules/Demo/composer.json new file mode 100644 index 0000000..b711984 --- /dev/null +++ b/modules/Demo/composer.json @@ -0,0 +1,30 @@ +{ + "name": "nwidart/demo", + "description": "", + "authors": [ + { + "name": "Nicolas Widart", + "email": "n.widart@gmail.com" + } + ], + "extra": { + "laravel": { + "providers": [], + "aliases": { + + } + } + }, + "autoload": { + "psr-4": { + "Modules\\Demo\\": "app/", + "Modules\\Demo\\Database\\Factories\\": "database/factories/", + "Modules\\Demo\\Database\\Seeders\\": "database/seeders/" + } + }, + "autoload-dev": { + "psr-4": { + "Modules\\Demo\\Tests\\": "tests/" + } + } +} diff --git a/modules/Demo/config/.gitkeep b/modules/Demo/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/config/config.php b/modules/Demo/config/config.php new file mode 100644 index 0000000..37aee66 --- /dev/null +++ b/modules/Demo/config/config.php @@ -0,0 +1,5 @@ + 'Demo', +]; diff --git a/modules/Demo/database/factories/.gitkeep b/modules/Demo/database/factories/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/database/migrations/.gitkeep b/modules/Demo/database/migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/database/seeders/.gitkeep b/modules/Demo/database/seeders/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/database/seeders/DemoDatabaseSeeder.php b/modules/Demo/database/seeders/DemoDatabaseSeeder.php new file mode 100644 index 0000000..e414036 --- /dev/null +++ b/modules/Demo/database/seeders/DemoDatabaseSeeder.php @@ -0,0 +1,16 @@ +call([]); + } +} diff --git a/modules/Demo/module.json b/modules/Demo/module.json new file mode 100644 index 0000000..797d87e --- /dev/null +++ b/modules/Demo/module.json @@ -0,0 +1,11 @@ +{ + "name": "Demo", + "alias": "demo", + "description": "", + "keywords": [], + "priority": 0, + "providers": [ + "Modules\\Demo\\Providers\\DemoServiceProvider" + ], + "files": [] +} diff --git a/modules/Demo/package.json b/modules/Demo/package.json new file mode 100644 index 0000000..d6fbfc8 --- /dev/null +++ b/modules/Demo/package.json @@ -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" + } +} diff --git a/modules/Demo/resources/assets/.gitkeep b/modules/Demo/resources/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/resources/assets/js/app.js b/modules/Demo/resources/assets/js/app.js new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/resources/assets/sass/app.scss b/modules/Demo/resources/assets/sass/app.scss new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/resources/views/.gitkeep b/modules/Demo/resources/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/modules/Demo/resources/views/components/layouts/master.blade.php b/modules/Demo/resources/views/components/layouts/master.blade.php new file mode 100644 index 0000000..fbfd12b --- /dev/null +++ b/modules/Demo/resources/views/components/layouts/master.blade.php @@ -0,0 +1,30 @@ + + + +
+ + + + + +Module: {!! config('demo.name') !!}
+