tempest-framework icon indicating copy to clipboard operation
tempest-framework copied to clipboard

feat(generator/console): add make:controller command

Open gturpin-dev opened this issue 1 year ago • 4 comments

This PR is a starting point of creating the make commands for the framework using the internal Generation Component. Here's the related issue #472

It add a make:controller command

  • it take a classname as an argument like Test
  • it will suffix the class with Controller like TestController.php
  • it will prepend the main autoloaded namespace/path from the composer file to it
  • it will then glue them with a Controllers directory
  • it will generate the right namespace PSR-4 compatible
  • it support adding subfolders directly in the classname arg from the command

So, for example if I have a project with a default autoloaded namespace from composer like : my-project/app => App And I run make:controller Admin/Dashboard

It will generate a class named DashboardController at my-project/app/Controllers/Admin/DashboardController.php And with the following namespace App\Controllers\Admin


Next steps before duplicate this into others make commands are :

  • [ ] Replace the way to retrieve the root path of the final user project
  • [ ] Find a way to test the file is properly generated and at the right location, with the right classname and namespace
  • [ ] Extract the main generation logic to the Generator component
  • [ ] ( later ) refactor the file creation logic by the Filesystem component
  • [ ] Handle Dummy replacements in Stubs file
  • [ ] Add MakeControllerCommand specifics params like the route path and the view path

For the 2 first TODOs I'm looking for ideas, if someone have any.

gturpin-dev avatar Oct 11 '24 14:10 gturpin-dev

@innocenzi For now, I'm not sure of the purpose of the ClassGenerator but I think the main logic could go there right ?

gturpin-dev avatar Oct 11 '24 14:10 gturpin-dev

@brendt are we good moving this outside the framework to the CLI project?

aidan-casey avatar Oct 11 '24 14:10 aidan-casey

I haven't tested this locally, but as I understand it, it will generate a controller in a predefined directory, right?

I don't really like this, personally, and I don't think it follows the philosophy of Tempest, where everything can be anywhere.

My implementation of tempest publish prompts the user every time for the path at which the file would be published. If the file already exists, the user is asked if the file should be replaced. What do you think of this approach?

You're right, this was the goal.

No problem for me, I can follow your already approved work, I'll check how your command work ! Then, we assume that every make command will always ask for the dist folder, we could imagine to give the main namespace path as an indication in the prompt if the user has no idea. I'll try to go in this way ( must think about how to generate the right namespace for the file then, maybe show a select for all composer.json autoload or ? )

gturpin-dev avatar Oct 11 '24 19:10 gturpin-dev

are we good moving this outside the framework to the CLI project?

Will discuss on Discord

brendt avatar Oct 12 '24 04:10 brendt

Pull Request Test Coverage Report for Build 11331827224

Details

  • 53 of 206 (25.73%) changed or added relevant lines in 8 files are covered.
  • 10 unchanged lines in 5 files lost coverage.
  • Overall coverage decreased (-1.4%) to 80.589%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Tempest/Console/src/Stubs/ControllerStub.php 0 2 0.0%
src/Tempest/Support/src/PathHelper.php 29 39 74.36%
src/Tempest/Console/src/Commands/Generators/MakeControllerCommand.php 0 56 0.0%
src/Tempest/Console/src/Commands/PublishCommand.php 0 85 0.0%
<!-- Total: 53 206
Files with Coverage Reduction New Missed Lines %
src/Tempest/Generation/src/SimplifiesClassNames.php 1 90.77%
src/Tempest/Auth/src/CreatePermissionsTable.php 2 75.0%
src/Tempest/Auth/src/CreateUserPermissionTable.php 2 77.78%
src/Tempest/Auth/src/CreateUsersTable.php 2 81.82%
src/Tempest/Generation/src/ManipulatesPhpClasses.php 3 69.33%
<!-- Total: 10
Totals Coverage Status
Change from base Build 11319238494: -1.4%
Covered Lines: 6813
Relevant Lines: 8454

💛 - Coveralls

coveralls avatar Oct 14 '24 16:10 coveralls

Don't worry about commits, I've pulled the unmerged work of Enzo to refactor the code with its helpers on namespaces and ClassManipulator.

Then I tried to stick as much as possible to the implementation of the publish command. So actually there is lot of duplicate code between both which is good, because it means we can now abstract those mechanism to create commands that generate files faster. I'll look into that in the followings days.

gturpin-dev avatar Oct 14 '24 17:10 gturpin-dev

As discussed in Discord here https://discord.com/channels/1236153076688359495/1295433932027990027/1298306566335893525 This PR is "ready", we are waiting to see the organization of the "roadmap" for the feature

gturpin-dev avatar Oct 24 '24 11:10 gturpin-dev

Let's close this one in favor of #647

brendt avatar Oct 31 '24 12:10 brendt