Skip to content

Commit

Permalink
Merge branch 'master' into package-installation
Browse files Browse the repository at this point in the history
  • Loading branch information
voidgraphics committed Apr 12, 2023
2 parents f7fdb56 + c6b00d2 commit 2169174
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Codestyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Whitecube\LaravelPreset;

use Illuminate\Support\Facades\File;
use Laravel\Ui\UiCommand;

class Codestyle
Expand All @@ -11,7 +12,15 @@ public static function install(UiCommand $command)
{
$command->info('Installing code style fixer...');

static::copyStubs();
}

public static function copyStubs()
{
copy(__DIR__.'/stubs/pint.json', base_path('pint.json'));

File::ensureDirectoryExists('.githooks');
copy(__DIR__.'/stubs/pre-commit', base_path('.githooks/pre-commit'));
}

}
1 change: 0 additions & 1 deletion src/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public static function install(UiCommand $command)

static::installPackages($command);
static::copyStub();
static::addComposerScripts();
}

public static function installPackages()
Expand Down
22 changes: 21 additions & 1 deletion src/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Preset extends LaravelPreset
{
public static function install(UiCommand $command)
{
static::updatePackages($command);
static::updatePackages();
static::addComposerScripts();
Codestyle::install($command);
Gitignore::install($command);
Mix::install($command);
Expand Down Expand Up @@ -51,4 +52,23 @@ public static function updatePackageArray($packages)
])
);
}

public static function addComposerScripts()
{
$composer = app()->make(\Whitecube\LaravelPreset\Support\Composer::class);

$composer->run([
'config',
'scripts.pre-install-cmd',
'App\\Console\\Commands\\ComposerEnv::loadLocalRepositories',
'git config core.hooksPath .githooks'
]);

$composer->run([
'config',
'scripts.pre-update-cmd',
'App\\Console\\Commands\\ComposerEnv::loadLocalRepositories',
'git config core.hooksPath .githooks'
]);
}
}
10 changes: 10 additions & 0 deletions src/stubs/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# store list of staged files to variable except deleted file since it won't work at re-add
files=$(git diff --name-only --cached --diff-filter=ACMR -- '*.php')

if [ -n "$files" ]; then
# run pint, this will unstage any files that pint will fix
./vendor/bin/pint $files

# re-add unstaged files caused by pint back to staging
printf $files | xargs git add
fi

0 comments on commit 2169174

Please sign in to comment.