#38 Add a rebuild command to the Hyde CLI to rebuild a specific file #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The rebuild command
Using the
php hyde build
command is great and all that, but when you just need to update that one file it gets a little... overkill.Let's solve that! Use the
php hyde rebuild <file>
command!In the future it will support an array of files, but for now, the rebuild command will recompile just that file.
Behind the scenes
The command acts like an alias to a new service class, the Build Service, which accepts a single source path.
We can in the future make a wrapper for the service that allows for an array input which then starts a build loop of build service classes.
Once the service class is instantiated we call the execute action method to start the build loop. If here the service determines which model to render based on the file path prefix. If a file is not found or a model does not exist an error will be thrown.
The service flow goes like this:
Command is run > a service class is instantiated, the command arguments are passed to the constructor > execute the action.
This flow allows for plenty of opportunities to add validation and confirmation.