-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Pre & Post Build Command Support #167
Open
PeteBishwhip
wants to merge
12
commits into
main
Choose a base branch
from
feature/493-second-pass-pre-post-build-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c2b4f4d
Implement Pre and Post Processing
80277dc
Provide pre and post-process functionality to build command
1dd1314
Refactor to align with change to config keys
05121d2
Test
1be0d77
Fix styling
PeteBishwhip 4fda3f8
Rmeove changes to yarn.lock
ec176cd
Remove no-longer necessary keys
66af0b0
Allow dynamic properties on mock class
391fef3
Reduce complexity, remove Mockery, update test
8ad121a
Fix styling
PeteBishwhip dd0ebdd
Merge branch 'main' into feature/493-second-pass-pre-post-build-config
SRWieZ 4d3af32
Fix styling
SRWieZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Native\Electron\Traits; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Process; | ||
|
||
use function Laravel\Prompts\error; | ||
use function Laravel\Prompts\intro; | ||
use function Laravel\Prompts\note; | ||
use function Laravel\Prompts\outro; | ||
|
||
trait HasPreAndPostProcessing | ||
{ | ||
public function preProcess(): void | ||
{ | ||
$config = collect(config('nativephp.prebuild')); | ||
|
||
if ($config->isEmpty()) { | ||
return; | ||
} | ||
|
||
intro('Running pre-process commands...'); | ||
|
||
$this->runProcess($config); | ||
|
||
outro('Pre-process commands completed.'); | ||
} | ||
|
||
public function postProcess(): void | ||
{ | ||
$config = collect(config('nativephp.postbuild')); | ||
|
||
if ($config->isEmpty()) { | ||
return; | ||
} | ||
|
||
intro('Running post-process commands...'); | ||
|
||
$this->runProcess($config); | ||
|
||
outro('Post-process commands completed.'); | ||
} | ||
|
||
private function runProcess(Collection $configCommands): void | ||
{ | ||
$configCommands->each(function ($command) { | ||
note("Running command: {$command}"); | ||
|
||
if (is_array($command)) { | ||
$command = implode(' && ', $command); | ||
} | ||
|
||
$result = Process::path(base_path()) | ||
->timeout(300) | ||
->tty(\Symfony\Component\Process\Process::isTtySupported()) | ||
->run($command, function (string $type, string $output) { | ||
echo $output; | ||
}); | ||
|
||
if (! $result->successful()) { | ||
error("Command failed: {$command}"); | ||
|
||
return; | ||
} | ||
|
||
note("Command successful: {$command}"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Native\Electron\Tests\Unit\Traits; | ||
|
||
use Illuminate\Support\Facades\Config; | ||
use Native\Electron\Traits\HasPreAndPostProcessing; | ||
|
||
it('can run pre and post processing from config', function (object $mock) { | ||
$tmpDir = sys_get_temp_dir(); | ||
|
||
Config::set('nativephp.prebuild', [ | ||
'touch '.$tmpDir.'/prebuild1', | ||
'touch '.$tmpDir.'/prebuild2', | ||
]); | ||
|
||
Config::set('nativephp.postbuild', [ | ||
'touch '.$tmpDir.'/postbuild1', | ||
'touch '.$tmpDir.'/postbuild2', | ||
]); | ||
|
||
// Verify those files were created in preProcess | ||
$mock->preProcess(); | ||
|
||
expect(file_exists($tmpDir.'/prebuild1'))->toBeTrue(); | ||
expect(file_exists($tmpDir.'/prebuild2'))->toBeTrue(); | ||
|
||
// Verify those files were created in postProcess | ||
$mock->postProcess(); | ||
expect(file_exists($tmpDir.'/postbuild1'))->toBeTrue(); | ||
expect(file_exists($tmpDir.'/postbuild2'))->toBeTrue(); | ||
|
||
// Cleanup | ||
unlink($tmpDir.'/prebuild1'); | ||
unlink($tmpDir.'/prebuild2'); | ||
unlink($tmpDir.'/postbuild1'); | ||
unlink($tmpDir.'/postbuild2'); | ||
}) | ||
->with([ | ||
// Empty class with the HasPreAndPostProcessing trait | ||
new class | ||
{ | ||
use HasPreAndPostProcessing; | ||
}, | ||
]); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beautiful!