Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feat: Generate Views together with Tests #16

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use function Laravel\Prompts\text;

class ActivateModuleCommand extends Command
class ModuleActivateCommand extends Command
{
public $signature = 'modular:activate {name?}';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use function Laravel\Prompts\text;

class DeactivateModuleCommand extends Command
class ModuleDeactivateCommand extends Command
{
public $signature = 'modular:deactivate {name?}';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use function Laravel\Prompts\text;

class MakeModuleCommand extends Command
class ModuleMakeCommand extends Command
{
use CanManipulateFiles;

Expand Down
41 changes: 41 additions & 0 deletions src/Commands/ViewMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Savannabits\Modular\Commands;

use Illuminate\Support\Str;
use Savannabits\Modular\Support\Concerns\GeneratesModularFiles;

class ViewMakeCommand extends \Illuminate\Foundation\Console\ViewMakeCommand
{
use GeneratesModularFiles;

protected $name = 'modular:make-view';

protected $description = 'Create a new view file in a modular package';

protected function getPath($name)
{
return $this->viewPath(
$this->getNameInput().'.'.$this->option('extension'),
);
}

protected function getTestPath(): string
{
return $this->getModule()->path(
Str::of($this->testClassFullyQualifiedName())
->replace('\\', '/')
->replaceFirst('Tests/Feature', 'tests/Feature')
->append('Test.php')
->value()
);
}

protected function getTestStub(): string
{
$stubName = 'view.'.($this->usingPest() ? 'pest' : 'test').'.stub';
$stubName = '/stubs/'.$stubName;

return parent::resolveStubPath($stubName);
}
}
8 changes: 8 additions & 0 deletions src/Commands/stubs/api-routes.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

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

Route::get('/user', function (Request $request) {
return $request->user();
})->middleware('auth:sanctum');
7 changes: 7 additions & 0 deletions src/Commands/stubs/broadcasting-routes.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
19 changes: 19 additions & 0 deletions src/Commands/stubs/cast.inbound.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace {{ namespace }};

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes;

class {{ class }} implements CastsInboundAttributes
{
/**
* Prepare the given value for storage.
*
* @param array<string, mixed> $attributes
*/
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value;
}
}
29 changes: 29 additions & 0 deletions src/Commands/stubs/cast.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace {{ namespace }};

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class {{ class }} implements CastsAttributes
{
/**
* Cast the given value.
*
* @param array<string, mixed> $attributes
*/
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value;
}

/**
* Prepare the given value for storage.
*
* @param array<string, mixed> $attributes
*/
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value;
}
}
24 changes: 24 additions & 0 deletions src/Commands/stubs/channel.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace {{ namespace }};

use {{ namespacedUserModel }};

class {{ class }}
{
/**
* Create a new channel instance.
*/
public function __construct()
{
//
}

/**
* Authenticate the user's access to the channel.
*/
public function join({{ userModel }} $user): array|bool
{
//
}
}
22 changes: 22 additions & 0 deletions src/Commands/stubs/class.invokable.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace {{ namespace }};

class {{ class }}
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}

/**
* Invoke the class instance.
*/
public function __invoke(): void
{

}
}
14 changes: 14 additions & 0 deletions src/Commands/stubs/class.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace {{ namespace }};

class {{ class }}
{
/**
* Create a new class instance.
*/
public function __construct()
{
//
}
}
30 changes: 30 additions & 0 deletions src/Commands/stubs/console.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace {{ namespace }};

use Illuminate\Console\Command;

class {{ class }} extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = '{{ command }}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
public function handle()
{
//
}
}
7 changes: 7 additions & 0 deletions src/Commands/stubs/echo-bootstrap-js.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Echo exposes an expressive API for subscribing to channels and listening
* for events that are broadcast by Laravel. Echo and event broadcasting
* allow your team to quickly build robust real-time web applications.
*/

import './echo';
14 changes: 14 additions & 0 deletions src/Commands/stubs/echo-js.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Echo from 'laravel-echo';

import Pusher from 'pusher-js';
window.Pusher = Pusher;

window.Echo = new Echo({
broadcaster: 'reverb',
key: import.meta.env.VITE_REVERB_APP_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
enabledTransports: ['ws', 'wss'],
});
8 changes: 8 additions & 0 deletions src/Commands/stubs/enum.backed.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace {{ namespace }};

enum {{ class }}: {{ type }}
{
//
}
8 changes: 8 additions & 0 deletions src/Commands/stubs/enum.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace {{ namespace }};

enum {{ class }}
{
//
}
36 changes: 36 additions & 0 deletions src/Commands/stubs/event.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace {{ namespace }};

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class {{ class }}
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct()
{
//
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}
26 changes: 26 additions & 0 deletions src/Commands/stubs/exception-render-report.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace {{ namespace }};

use Exception;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class {{ class }} extends Exception
{
/**
* Report the exception.
*/
public function report(): void
{
//
}

/**
* Render the exception as an HTTP response.
*/
public function render(Request $request): Response
{
//
}
}
18 changes: 18 additions & 0 deletions src/Commands/stubs/exception-render.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace {{ namespace }};

use Exception;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class {{ class }} extends Exception
{
/**
* Render the exception as an HTTP response.
*/
public function render(Request $request): Response
{
//
}
}
16 changes: 16 additions & 0 deletions src/Commands/stubs/exception-report.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace {{ namespace }};

use Exception;

class {{ class }} extends Exception
{
/**
* Report the exception.
*/
public function report(): void
{
//
}
}
10 changes: 10 additions & 0 deletions src/Commands/stubs/exception.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace {{ namespace }};

use Exception;

class {{ class }} extends Exception
{
//
}
8 changes: 8 additions & 0 deletions src/Commands/stubs/interface.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace {{ namespace }};

interface {{ class }}
{
//
}
Loading