Skip to content
Open
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
16 changes: 7 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
php: [8.3, 8.2]
laravel: [11.*, 10.*]
stability: [prefer-lowest, prefer-stable]
laravel: [12.*]
stability: [prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
carbon: ^2.63
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
- laravel: 12.*
testbench: 10.*
carbon: 3.*
collision: 8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"pestphp/pest-plugin-laravel": "^2.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"spatie/laravel-ray": "^1.35"
"phpstan/phpstan-phpunit": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
60 changes: 27 additions & 33 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

function ask(string $question, string $default = ''): string
{
$answer = readline($question . ($default ? " ({$default})" : null) . ': ');
$answer = readline($question.($default ? " ({$default})" : null).': ');

if (! $answer) {
return $default;
Expand All @@ -14,7 +14,7 @@ function ask(string $question, string $default = ''): string

function confirm(string $question, bool $default = false): bool
{
$answer = ask($question . ' (' . ($default ? 'Y/n' : 'y/N') . ')');
$answer = ask($question.' ('.($default ? 'Y/n' : 'y/N').')');

if (! $answer) {
return $default;
Expand All @@ -25,7 +25,7 @@ function confirm(string $question, bool $default = false): bool

function writeln(string $line): void
{
echo $line . PHP_EOL;
echo $line.PHP_EOL;
}

function run(string $command): string
Expand Down Expand Up @@ -84,20 +84,20 @@ function remove_prefix(string $prefix, string $content): string

function remove_composer_deps(array $names)
{
$data = json_decode(file_get_contents(__DIR__ . '/composer.json'), true);
$data = json_decode(file_get_contents(__DIR__.'/composer.json'), true);

foreach ($data['require-dev'] as $name => $version) {
if (in_array($name, $names, true)) {
unset($data['require-dev'][$name]);
}
}

file_put_contents(__DIR__ . '/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
file_put_contents(__DIR__.'/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}

function remove_composer_script($scriptName)
{
$data = json_decode(file_get_contents(__DIR__ . '/composer.json'), true);
$data = json_decode(file_get_contents(__DIR__.'/composer.json'), true);

foreach ($data['scripts'] as $name => $script) {
if ($scriptName === $name) {
Expand All @@ -107,7 +107,7 @@ function remove_composer_script($scriptName)
}
}

file_put_contents(__DIR__ . '/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
file_put_contents(__DIR__.'/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}

function remove_readme_paragraphs(string $file): void
Expand All @@ -134,12 +134,12 @@ function determineSeparator(string $path): string

function replaceForWindows(): array
{
return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i ' . basename(__FILE__) . ' | findstr /r /i /M /F:/ ":author :vendor :package VendorName skeleton migration_table_name vendor_name vendor_slug author@domain.com"'));
return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ ":author :vendor :package VendorName skeleton migration_table_name vendor_name vendor_slug author@domain.com"'));
}

function replaceForAllOtherOSes(): array
{
return explode(PHP_EOL, run('grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|migration_table_name|vendor_name|vendor_slug|author@domain.com" --exclude-dir=vendor ./* ./.github/* | grep -v ' . basename(__FILE__)));
return explode(PHP_EOL, run('grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|migration_table_name|vendor_name|vendor_slug|author@domain.com" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__)));
}

function getGitHubApiEndpoint(string $endpoint): ?stdClass
Expand Down Expand Up @@ -273,7 +273,6 @@ function guessGitHubVendorInfo($authorName, $username): array
$usePhpStan = confirm('Enable PhpStan?', true);
$useLaravelPint = confirm('Enable Laravel Pint?', true);
$useDependabot = confirm('Enable Dependabot?', true);
$useLaravelRay = confirm('Use Ray for debugging?', true);
$useUpdateChangelogWorkflow = confirm('Use automatic changelog updater workflow?', true);

writeln('------');
Expand All @@ -284,11 +283,10 @@ function guessGitHubVendorInfo($authorName, $username): array
writeln("Class name : {$className}");
writeln('---');
writeln('Packages & Utilities');
writeln('Use Laravel/Pint : ' . ($useLaravelPint ? 'yes' : 'no'));
writeln('Use Larastan/PhpStan : ' . ($usePhpStan ? 'yes' : 'no'));
writeln('Use Dependabot : ' . ($useDependabot ? 'yes' : 'no'));
writeln('Use Ray App : ' . ($useLaravelRay ? 'yes' : 'no'));
writeln('Use Auto-Changelog : ' . ($useUpdateChangelogWorkflow ? 'yes' : 'no'));
writeln('Use Laravel/Pint : '.($useLaravelPint ? 'yes' : 'no'));
writeln('Use Larastan/PhpStan : '.($usePhpStan ? 'yes' : 'no'));
writeln('Use Dependabot : '.($useDependabot ? 'yes' : 'no'));
writeln('Use Auto-Changelog : '.($useUpdateChangelogWorkflow ? 'yes' : 'no'));
writeln('------');

writeln('This script will replace the above values in all relevant files in the project directory.');
Expand Down Expand Up @@ -318,26 +316,26 @@ function guessGitHubVendorInfo($authorName, $username): array
]);

match (true) {
str_contains($file, determineSeparator('src/Skeleton.php')) => rename($file, determineSeparator('./src/' . $className . '.php')),
str_contains($file, determineSeparator('src/SkeletonServiceProvider.php')) => rename($file, determineSeparator('./src/' . $className . 'ServiceProvider.php')),
str_contains($file, determineSeparator('src/Facades/Skeleton.php')) => rename($file, determineSeparator('./src/Facades/' . $className . '.php')),
str_contains($file, determineSeparator('src/Commands/SkeletonCommand.php')) => rename($file, determineSeparator('./src/Commands/' . $className . 'Command.php')),
str_contains($file, determineSeparator('database/migrations/create_skeleton_table.php.stub')) => rename($file, determineSeparator('./database/migrations/create_' . title_snake($packageSlugWithoutPrefix) . '_table.php.stub')),
str_contains($file, determineSeparator('config/skeleton.php')) => rename($file, determineSeparator('./config/' . $packageSlugWithoutPrefix . '.php')),
str_contains($file, determineSeparator('src/Skeleton.php')) => rename($file, determineSeparator('./src/'.$className.'.php')),
str_contains($file, determineSeparator('src/SkeletonServiceProvider.php')) => rename($file, determineSeparator('./src/'.$className.'ServiceProvider.php')),
str_contains($file, determineSeparator('src/Facades/Skeleton.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')),
str_contains($file, determineSeparator('src/Commands/SkeletonCommand.php')) => rename($file, determineSeparator('./src/Commands/'.$className.'Command.php')),
str_contains($file, determineSeparator('database/migrations/create_skeleton_table.php.stub')) => rename($file, determineSeparator('./database/migrations/create_'.title_snake($packageSlugWithoutPrefix).'_table.php.stub')),
str_contains($file, determineSeparator('config/skeleton.php')) => rename($file, determineSeparator('./config/'.$packageSlugWithoutPrefix.'.php')),
str_contains($file, 'README.md') => remove_readme_paragraphs($file),
default => [],
};
}

if (! $useLaravelPint) {
safeUnlink(__DIR__ . '/.github/workflows/fix-php-code-style-issues.yml');
safeUnlink(__DIR__ . '/pint.json');
safeUnlink(__DIR__.'/.github/workflows/fix-php-code-style-issues.yml');
safeUnlink(__DIR__.'/pint.json');
}

if (! $usePhpStan) {
safeUnlink(__DIR__ . '/phpstan.neon.dist');
safeUnlink(__DIR__ . '/phpstan-baseline.neon');
safeUnlink(__DIR__ . '/.github/workflows/phpstan.yml');
safeUnlink(__DIR__.'/phpstan.neon.dist');
safeUnlink(__DIR__.'/phpstan-baseline.neon');
safeUnlink(__DIR__.'/.github/workflows/phpstan.yml');

remove_composer_deps([
'phpstan/extension-installer',
Expand All @@ -350,16 +348,12 @@ function guessGitHubVendorInfo($authorName, $username): array
}

if (! $useDependabot) {
safeUnlink(__DIR__ . '/.github/dependabot.yml');
safeUnlink(__DIR__ . '/.github/workflows/dependabot-auto-merge.yml');
}

if (! $useLaravelRay) {
remove_composer_deps(['spatie/laravel-ray']);
safeUnlink(__DIR__.'/.github/dependabot.yml');
safeUnlink(__DIR__.'/.github/workflows/dependabot-auto-merge.yml');
}

if (! $useUpdateChangelogWorkflow) {
safeUnlink(__DIR__ . '/.github/workflows/update-changelog.yml');
safeUnlink(__DIR__.'/.github/workflows/update-changelog.yml');
}

confirm('Execute `composer install` and run tests?') && run('composer install && composer test');
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected function setUp(): void
parent::setUp();

Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'Backstage\Laravel\\AI\\Database\\Factories\\' . class_basename($modelName) . 'Factory'
fn (string $modelName) => 'Backstage\Laravel\\AI\\Database\\Factories\\'.class_basename($modelName).'Factory'
);
}

Expand Down