Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsam726 authored and github-actions[bot] committed Apr 6, 2024
1 parent b673601 commit e10f84d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 62 deletions.
6 changes: 4 additions & 2 deletions src/Commands/ActivateModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Savannabits\Modular\Facades\Modular;

use function Laravel\Prompts\text;

class ActivateModuleCommand extends Command
{

public $signature = 'modular:activate {name?}';

public $description = 'Activate a module';

private string $moduleName;

public function handle(): void
Expand All @@ -24,7 +26,7 @@ public function handle(): void
private function activateModule(): void
{
$moduleName = $this->moduleName;
$repoName = config('modular.vendor','modular').'/'.$moduleName;
$repoName = config('modular.vendor', 'modular').'/'.$moduleName;
Modular::execCommand('composer require '.$repoName.':@dev');
Modular::execCommand("php artisan $moduleName:install");
}
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/DeactivateModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Savannabits\Modular\Facades\Modular;

use function Laravel\Prompts\text;

class DeactivateModuleCommand extends Command
{

public $signature = 'modular:deactivate {name?}';

public $description = 'Deactivate a module';

private string $moduleName;

public function handle(): void
Expand All @@ -24,7 +26,7 @@ public function handle(): void
private function deactivateModule(): void
{
$moduleName = $this->moduleName;
$repoName = config('modular.vendor','modular').'/'.$moduleName;
$repoName = config('modular.vendor', 'modular').'/'.$moduleName;
Modular::execCommand("composer remove $repoName");
}
}
42 changes: 26 additions & 16 deletions src/Commands/MakeModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Savannabits\Modular\Support\Concerns\CanManipulateFiles;

use function Laravel\Prompts\text;

class MakeModuleCommand extends Command
{
use CanManipulateFiles;

public $signature = 'modular:make {name?} {--F|force}';

public $description = 'Create a new module';

private string $moduleName;

private string $moduleTitle;

private string $moduleNamespace;

private string $modulePath;

private string $moduleStudlyName;

public function handle()
Expand All @@ -27,8 +35,8 @@ public function handle()
$this->moduleName = Str::of($name)->kebab()->toString();
$this->moduleStudlyName = Str::of($name)->studly()->toString();
$this->moduleTitle = Str::of($name)->kebab()->title()->replace('-', ' ')->toString();
$this->moduleNamespace = config('modular.namespace') . '\\' . Str::of($name)->studly()->toString();
$this->modulePath = config('modular.path') . '/' . $this->moduleName;
$this->moduleNamespace = config('modular.namespace').'\\'.Str::of($name)->studly()->toString();
$this->modulePath = config('modular.path').'/'.$this->moduleName;
$this->info("Creating module: $this->moduleName in $this->modulePath");

$this->generateModuleDirectories();
Expand All @@ -39,18 +47,20 @@ public function handle()
private function generateModuleDirectories(): bool
{
$directories = config('modular.directory_tree');
if (!count($directories)) {
if (! count($directories)) {
$this->error('No directories found in the configuration file');

return false;
}
foreach ($directories as $directory) {
$path = $this->modulePath . '/' . ltrim($directory,'/');
if (!is_dir($path)) {
$path = $this->modulePath.'/'.ltrim($directory, '/');
if (! is_dir($path)) {
mkdir($path, 0775, true);
$this->info("Created directory: $path");
}
}
$this->info('Module directories created successfully');

return true;
}

Expand All @@ -62,28 +72,28 @@ private function generateModuleFiles(): void
} catch (FileNotFoundException|NotFoundExceptionInterface|ContainerExceptionInterface $e) {
$this->error($e->getMessage());
}
// $this->generateModuleFacade();
// $this->generateModuleFacade();
}

private function generateModuleComposerFile(): void
{
$composerJson = [
'name' => config('modular.vendor') . '/' . $this->moduleName,
'name' => config('modular.vendor').'/'.$this->moduleName,
'type' => 'library',
'description' => $this->moduleTitle . ' module',
'description' => $this->moduleTitle.' module',
'require' => [
'php' => '^8.2',
],
'autoload' => [
'psr-4' => [
$this->moduleNamespace . '\\' => 'src/',
$this->moduleNamespace . '\\Database\\Factories\\' => 'database/factories/',
$this->moduleNamespace . '\\Database\\Seeders\\' => 'database/seeders/',
$this->moduleNamespace.'\\' => 'src/',
$this->moduleNamespace.'\\Database\\Factories\\' => 'database/factories/',
$this->moduleNamespace.'\\Database\\Seeders\\' => 'database/seeders/',
],
],
'autoload-dev' => [
'psr-4' => [
$this->moduleNamespace . '\\Tests\\' => 'tests/',
$this->moduleNamespace.'\\Tests\\' => 'tests/',
],
],
'config' => [
Expand All @@ -96,12 +106,12 @@ private function generateModuleComposerFile(): void
'extra' => [
'laravel' => [
'providers' => [
$this->moduleNamespace . '\\' . $this->moduleStudlyName . 'ServiceProvider',
$this->moduleNamespace.'\\'.$this->moduleStudlyName.'ServiceProvider',
],
],
],
];
$composerJsonPath = $this->modulePath . '/composer.json';
$composerJsonPath = $this->modulePath.'/composer.json';
file_put_contents($composerJsonPath, json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$this->info("Created composer.json file: $composerJsonPath");
}
Expand All @@ -113,9 +123,9 @@ private function generateModuleComposerFile(): void
*/
private function generateModuleServiceProvider(): void
{
$path = $this->modulePath . '/src/' . $this->moduleStudlyName . 'ServiceProvider.php';
$path = $this->modulePath.'/src/'.$this->moduleStudlyName.'ServiceProvider.php';
$namespace = $this->moduleNamespace;
$class = $this->moduleStudlyName . 'ServiceProvider';
$class = $this->moduleStudlyName.'ServiceProvider';
$this->copyStubToApp('module.provider', $path, [
'class' => $class,
'namespace' => $namespace,
Expand Down
11 changes: 5 additions & 6 deletions src/Commands/MigrationMakeCommand.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php

namespace Savannabits\Modular\Commands;

use Illuminate\Console\Command;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Database\Console\Migrations\BaseCommand;
use Illuminate\Database\Console\Migrations\MigrateMakeCommand;
use Savannabits\Modular\Facades\Modular;
use Symfony\Component\Console\Input\InputArgument;

class MigrationMakeCommand extends Command implements PromptsForMissingInput
{
Expand All @@ -16,6 +14,7 @@ class MigrationMakeCommand extends Command implements PromptsForMissingInput
{--create= : The table to be created}
{--table= : The table to migrate}
';

protected $description = 'Create a new migration file in a module';

public function handle(): void
Expand All @@ -30,14 +29,14 @@ public function handle(): void

protected function getMigrationPath(): string
{
return Modular::module($this->argument('module'))->migrationsPath(relative: true);
return Modular::module($this->argument('module'))->migrationsPath(relative: true);
}

protected function promptForMissingArgumentsUsing(): array
{
return [
'name' => ['What should the migration name be?','e.g create_planets_table'],
'module' => ['Enter the module name (It has to be existing)','e.g Blog, BlogPost, blog-post']
'name' => ['What should the migration name be?', 'e.g create_planets_table'],
'module' => ['Enter the module name (It has to be existing)', 'e.g Blog, BlogPost, blog-post'],
];
}
}
12 changes: 3 additions & 9 deletions src/Commands/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ModelMakeCommand extends BaseModelMakeCommand

protected function getArguments(): array
{
return array_merge(parent::getArguments(),[
return array_merge(parent::getArguments(), [
['module', InputArgument::REQUIRED, 'The name of the module in which this should be installed'],
]);
}
Expand All @@ -37,9 +37,11 @@ protected function rootNamespace(): string
{
return $this->getModule()->getRootNamespace();
}

protected function getPath($name): string
{
$name = Str::replaceFirst($this->rootNamespace(), '', $name);

return $this->getModule()->srcPath(str_replace('\\', '/', $name).'.php');
}

Expand All @@ -55,8 +57,6 @@ protected function createFactory(): void

/**
* Create a migration file for the model.
*
* @return void
*/
protected function createMigration(): void
{
Expand All @@ -75,8 +75,6 @@ protected function createMigration(): void

/**
* Create a seeder file for the model.
*
* @return void
*/
protected function createSeeder(): void
{
Expand All @@ -89,8 +87,6 @@ protected function createSeeder(): void

/**
* Create a controller for the model.
*
* @return void
*/
protected function createController(): void
{
Expand All @@ -110,8 +106,6 @@ protected function createController(): void

/**
* Create a policy file for the model.
*
* @return void
*/
protected function createPolicy(): void
{
Expand Down
17 changes: 10 additions & 7 deletions src/ModularServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class ModularServiceProvider extends PackageServiceProvider
{
public static string $name = 'modular';

public static string $vendor = 'savannabits';

public static string $viewNamespace = 'modular';

public function configurePackage(Package $package): void
{
/*
Expand All @@ -30,8 +34,7 @@ public function configurePackage(Package $package): void
$command
->askToStarRepoOnGitHub($name)
->startWith(fn (InstallCommand $command) => $this->installationSteps($command));
})
;
});
$this->mergeConfigFrom($this->package->basePath('/../config/modular.php'), 'modular');
}

Expand All @@ -40,10 +43,10 @@ private function configureComposerMerge(InstallCommand $command): void
$command->comment('Configuring Composer merge plugin:');
$composerJson = json_decode(file_get_contents(base_path('composer.json')), true);
// Add the modules repositories into compose if they don't exist
if (!isset($composerJson['repositories'])){
if (! isset($composerJson['repositories'])) {
$composerJson['repositories'] = [];
}
if (!collect($composerJson['repositories'])->contains(fn ($repo) => $repo['type'] === 'path' && $repo['url'] === config('modular.path').'/*')) {
if (! collect($composerJson['repositories'])->contains(fn ($repo) => $repo['type'] === 'path' && $repo['url'] === config('modular.path').'/*')) {
$composerJson['repositories'][] = [
'type' => 'path',
'url' => config('modular.path').'/*',
Expand All @@ -52,7 +55,7 @@ private function configureComposerMerge(InstallCommand $command): void
],
];
}
if (!isset($composerJson['extra']['merge-plugin'])) {
if (! isset($composerJson['extra']['merge-plugin'])) {
$composerJson['extra']['merge-plugin'] = [
'include' => [
'modules/*/composer.json',
Expand All @@ -65,7 +68,7 @@ private function configureComposerMerge(InstallCommand $command): void
];

// Ensure the composer-merge-plugin is in the list of allowed plugins
if (!isset($composerJson['config']['allow-plugins'])) {
if (! isset($composerJson['config']['allow-plugins'])) {
$composerJson['config']['allow-plugins'] = [];
}
// If allowed-plugins is set to true, disregard
Expand Down Expand Up @@ -93,7 +96,7 @@ private function ensureModularPathExists(InstallCommand $command): void
{
$command->comment('Ensuring modular path exists:');
$path = config('modular.path');
if (!is_dir($path)) {
if (! is_dir($path)) {
mkdir($path, 0755, true);
$command->info("Directory $path created successfully");
} else {
Expand Down
Loading

0 comments on commit e10f84d

Please sign in to comment.