Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Nov 24, 2024
1 parent 7715112 commit 111a41b
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 123 deletions.
154 changes: 87 additions & 67 deletions bin/sync
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ require __DIR__.'/../vendor/autoload.php';

$files = new Illuminate\Filesystem\Filesystem();

$files->delete("{$workingPath}/laravel/.env");
$files->deleteDirectory("{$workingPath}/skeleton");
$purgeSkeletonDirectories = static function () use ($files, $workingPath) {
$files->delete("{$workingPath}/laravel/.env");

$files->deleteDirectory("{$workingPath}/skeleton");
};

function line(string $code, int $tab = 0): string {
return implode('', [PHP_EOL, str_repeat(' ', ($tab * 4)), $code]);
}

$purgeSkeletonDirectories();

$files->copy("{$workingPath}/vendor/orchestra/testbench-core/laravel/bootstrap/app.php", "{$workingPath}/laravel/bootstrap/app.php");
$files->copy("{$workingPath}/vendor/orchestra/testbench-core/laravel/server.php", "{$workingPath}/laravel/server.php");
Expand All @@ -22,75 +31,86 @@ Symfony\Component\Process\Process::fromShellCommandline(
'composer create-project "laravel/laravel:9.x-dev" skeleton --no-scripts --no-plugins --quiet --no-install', $workingPath
)->mustRun();

Illuminate\Support\Collection::make([
'.env.example',
'config/*.php',
'database/.gitignore',
'database/migrations/2014_10_12_000000_create_users_table.php',
'database/migrations/2014_10_12_100000_create_password_resets_table.php',
'database/migrations/2019_08_19_000000_create_failed_jobs_table.php',
'lang/en/*.php',
'lang/*.json',
'resources/views/*',
'public/index.php',
'tests/CreatesApplication.php',
])->transform(fn ($file) => "{$workingPath}/skeleton/{$file}")
->map(fn ($file) => str_contains($file, '*') ? [...$files->glob($file)] : $file)
->flatten()
->each(function ($file) use ($files, $workingPath) {
$files->copy($file, "{$workingPath}/laravel".Illuminate\Support\Str::after($file, "{$workingPath}/skeleton"));
});
$files->delete("{$workingPath}/laravel/config/sanctum.php");
$files->move("{$workingPath}/laravel/database/migrations/2014_10_12_000000_create_users_table.php", "{$workingPath}/laravel/migrations/2014_10_12_000000_testbench_create_users_table.php");
$files->move("{$workingPath}/laravel/database/migrations/2014_10_12_100000_create_password_resets_table.php", "{$workingPath}/laravel/migrations/2014_10_12_100000_testbench_create_password_resets_table.php");
$files->move("{$workingPath}/laravel/database/migrations/2019_08_19_000000_create_failed_jobs_table.php", "{$workingPath}/laravel/migrations/2019_08_19_000000_testbench_create_failed_jobs_table.php");

Illuminate\Support\Collection::make([
'cache/0001_01_01_000000_testbench_create_cache_table' => 'Cache/Console/stubs/cache.stub',
'notifications/0001_01_01_000000_testbench_create_notifications_table' => 'Notifications/Console/stubs/notifications.stub',
'queue/0001_01_01_000000_testbench_create_jobs_table' => 'Queue/Console/stubs/jobs.stub',
'queue/0001_01_01_000000_testbench_create_job_batches_table' => 'Queue/Console/stubs/batches.stub',
// 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => 'Queue/Console/stubs/failed_jobs.stub',
'session/0001_01_01_000000_testbench_create_sessions_table' => 'Session/Console/stubs/database.stub',
])->transform(fn ($file) => "{$workingPath}/vendor/laravel/framework/src/Illuminate/{$file}")
->each(function ($from, $to) use ($files, $workingPath) {
$files->copy($from, "{$workingPath}/laravel/migrations/{$to}.php");
})->keys()
->push(...[
'2014_10_12_000000_testbench_create_users_table',
'2014_10_12_100000_testbench_create_password_resets_table',
'2019_08_19_000000_testbench_create_failed_jobs_table',
])->each(function ($migration) use ($files, $workingPath) {
$files->replaceInFile('class Create', 'class TestbenchCreate', "{$workingPath}/laravel/migrations/{$migration}.php");
})->filter(fn ($migration) => str_starts_with($migration, 'queue'))
->mapWithKeys(fn ($migration) => match ($migration) {
'queue/0001_01_01_000000_testbench_create_jobs_table' => [$migration => 'jobs'],
'queue/0001_01_01_000000_testbench_create_job_batches_table' => [$migration => 'job_batches'],
// 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => [$migration => 'failed_jobs'],
})->each(function ($table, $migration) use ($files, $workingPath) {
$files->replaceInFile(['{{tableClassName}}', '{{table}}'], [Illuminate\Support\Str::studly($table), $table], "{$workingPath}/laravel/migrations/{$migration}.php");
});

transform([
PHP_EOL.'APP_KEY=' => PHP_EOL.'APP_KEY=AckfSECXIvnK5r28GVIWUAxmbBSjTsmF',
PHP_EOL.'DB_CONNECTION=mysql' => PHP_EOL.'DB_CONNECTION=sqlite',
PHP_EOL.'DB_HOST=' => PHP_EOL.'# DB_HOST=',
PHP_EOL.'DB_PORT=' => PHP_EOL.'# DB_PORT=',
PHP_EOL.'DB_DATABASE=' => PHP_EOL.'# DB_DATABASE=',
PHP_EOL.'DB_USERNAME=' => PHP_EOL.'# DB_USERNAME=',
PHP_EOL.'DB_PASSWORD=' => PHP_EOL.'# DB_PASSWORD=',
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/.env.example"));
require Orchestra\Testbench\join_paths($workingPath, 'vendor', 'orchestra', 'testbench-core', 'bin', 'configure-skeleton.php');

transform([
"env('APP_ENV', 'production')" => "env('APP_ENV', 'testing')",
PHP_EOL.' App\Providers' => PHP_EOL.' // App\Providers',
PHP_EOL.' * Package Service Providers...' => PHP_EOL.' * Dusk Service Provider'.PHP_EOL.' */'.PHP_EOL.' Laravel\Dusk\DuskServiceProvider::class,'.PHP_EOL.PHP_EOL.' /*'.PHP_EOL.' * Package Service Providers...'
line('App\Providers', 2) => line('// App\Providers', 2),
line(' * Package Service Providers...', 2) => line(' * Dusk Service Provider', 2).line(' */', 2).line('Laravel\Dusk\DuskServiceProvider::class,', 2).PHP_EOL.line('/*', 2).line(' * Package Service Providers...', 2),
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/app.php"));

transform([
"'model' => App\Models\User::class" => "'model' => Illuminate\Foundation\Auth\User::class",
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/auth.php"));
// Illuminate\Support\Collection::make([
// '.env.example',
// 'config/*.php',
// 'database/.gitignore',
// 'database/migrations/2014_10_12_000000_create_users_table.php',
// 'database/migrations/2014_10_12_100000_create_password_resets_table.php',
// 'database/migrations/2019_08_19_000000_create_failed_jobs_table.php',
// 'lang/en/*.php',
// 'lang/*.json',
// 'resources/views/*',
// 'public/index.php',
// 'tests/CreatesApplication.php',
// ])->transform(fn ($file) => "{$workingPath}/skeleton/{$file}")
// ->map(fn ($file) => str_contains($file, '*') ? [...$files->glob($file)] : $file)
// ->flatten()
// ->each(function ($file) use ($files, $workingPath) {
// $files->copy($file, "{$workingPath}/laravel".Illuminate\Support\Str::after($file, "{$workingPath}/skeleton"));
// });
// $files->delete("{$workingPath}/laravel/config/sanctum.php");
// $files->move("{$workingPath}/laravel/database/migrations/2014_10_12_000000_create_users_table.php", "{$workingPath}/laravel/migrations/2014_10_12_000000_testbench_create_users_table.php");
// $files->move("{$workingPath}/laravel/database/migrations/2014_10_12_100000_create_password_resets_table.php", "{$workingPath}/laravel/migrations/2014_10_12_100000_testbench_create_password_resets_table.php");
// $files->move("{$workingPath}/laravel/database/migrations/2019_08_19_000000_create_failed_jobs_table.php", "{$workingPath}/laravel/migrations/2019_08_19_000000_testbench_create_failed_jobs_table.php");

// Illuminate\Support\Collection::make([
// 'cache/0001_01_01_000000_testbench_create_cache_table' => 'Cache/Console/stubs/cache.stub',
// 'notifications/0001_01_01_000000_testbench_create_notifications_table' => 'Notifications/Console/stubs/notifications.stub',
// 'queue/0001_01_01_000000_testbench_create_jobs_table' => 'Queue/Console/stubs/jobs.stub',
// 'queue/0001_01_01_000000_testbench_create_job_batches_table' => 'Queue/Console/stubs/batches.stub',
// // 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => 'Queue/Console/stubs/failed_jobs.stub',
// 'session/0001_01_01_000000_testbench_create_sessions_table' => 'Session/Console/stubs/database.stub',
// ])->transform(fn ($file) => "{$workingPath}/vendor/laravel/framework/src/Illuminate/{$file}")
// ->each(function ($from, $to) use ($files, $workingPath) {
// $files->copy($from, "{$workingPath}/laravel/migrations/{$to}.php");
// })->keys()
// ->push(...[
// '2014_10_12_000000_testbench_create_users_table',
// '2014_10_12_100000_testbench_create_password_resets_table',
// '2019_08_19_000000_testbench_create_failed_jobs_table',
// ])->each(function ($migration) use ($files, $workingPath) {
// $files->replaceInFile('class Create', 'class TestbenchCreate', "{$workingPath}/laravel/migrations/{$migration}.php");
// })->filter(fn ($migration) => str_starts_with($migration, 'queue'))
// ->mapWithKeys(fn ($migration) => match ($migration) {
// 'queue/0001_01_01_000000_testbench_create_jobs_table' => [$migration => 'jobs'],
// 'queue/0001_01_01_000000_testbench_create_job_batches_table' => [$migration => 'job_batches'],
// // 'queue/0001_01_01_000000_testbench_create_failed_jobs_table' => [$migration => 'failed_jobs'],
// })->each(function ($table, $migration) use ($files, $workingPath) {
// $files->replaceInFile(['{{tableClassName}}', '{{table}}'], [Illuminate\Support\Str::studly($table), $table], "{$workingPath}/laravel/migrations/{$migration}.php");
// });

// transform([
// line('APP_KEY=') => line('APP_KEY=AckfSECXIvnK5r28GVIWUAxmbBSjTsmF'),
// line('DB_CONNECTION=mysql') => line('DB_CONNECTION=sqlite'),
// line('DB_HOST=') => line('# DB_HOST='),
// line('DB_PORT=') => line('# DB_PORT='),
// line('DB_DATABASE=') => line('# DB_DATABASE='),
// line('DB_USERNAME=') => line('# DB_USERNAME='),
// line('DB_PASSWORD=') => line('# DB_PASSWORD='),
// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/.env.example"));

// transform([
// line("'env' => env('APP_ENV', 'production'),", 1) => line("'env' => env('APP_ENV', 'workbench'),", 1),
// line("'timezone' => 'UTC',", 1) => line("'timezone' => env('APP_TIMEZONE', 'UTC'),", 1),
// line("'locale' => 'en',", 1) => line("'locale' => env('APP_LOCALE', 'en'),", 1),
// line("'fallback_locale' => 'en',", 1) => line("'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),", 1),
// line('App\Providers', 2) => line('// App\Providers', 2),
// PHP_EOL.' App\Providers' => PHP_EOL.' // App\Providers',
// PHP_EOL.' * Package Service Providers...' => PHP_EOL.' * Dusk Service Provider'.PHP_EOL.' */'.PHP_EOL.' Laravel\Dusk\DuskServiceProvider::class,'.PHP_EOL.PHP_EOL.' /*'.PHP_EOL.' * Package Service Providers...'
// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/app.php"));

// transform([
// "'model' => App\Models\User::class" => "'model' => Illuminate\Foundation\Auth\User::class",
// ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/laravel/config/auth.php"));

$files->copy("{$workingPath}/vendor/laravel/dusk/stubs/phpunit.xml", "{$workingPath}/stubs/phpunit.xml");

$files->deleteDirectory("{$workingPath}/skeleton");
$purgeSkeletonDirectories();
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
"laravel/dusk": "^7.13",
"laravel/serializable-closure": "^1.3",
"orchestra/dusk-updater": "^1.10 || ^2.6",
"orchestra/testbench": "^7.47",
"orchestra/testbench-core": "^7.48",
"php-webdriver/webdriver": "^1.9"
"orchestra/testbench": "^7.48",
"orchestra/testbench-core": "^7.49",
"php-webdriver/webdriver": "^1.9",
"symfony/polyfill-php83": "^1.31"
},
"require-dev": {
"laravel/pint": "^1.4",
Expand Down
53 changes: 53 additions & 0 deletions laravel/artisan
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env php
<?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any of our classes manually. It's great to relax.
|
*/

require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/

$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);

$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);

/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/

$kernel->terminate($input, $status);

exit($status);
8 changes: 4 additions & 4 deletions laravel/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
|
*/

'env' => env('APP_ENV', 'testing'),
'env' => env('APP_ENV', 'workbench'),

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -69,7 +69,7 @@
|
*/

'timezone' => 'UTC',
'timezone' => env('APP_TIMEZONE', 'UTC'),

/*
|--------------------------------------------------------------------------
Expand All @@ -82,7 +82,7 @@
|
*/

'locale' => 'en',
'locale' => env('APP_LOCALE', 'en'),

/*
|--------------------------------------------------------------------------
Expand All @@ -95,7 +95,7 @@
|
*/

'fallback_locale' => 'en',
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),

/*
|--------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions laravel/config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

'defaults' => [
'guard' => 'web',
'passwords' => 'users',
'guard' => env('AUTH_GUARD', 'web'),
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
],

/*
Expand Down Expand Up @@ -62,7 +62,7 @@
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => Illuminate\Foundation\Auth\User::class,
'model' => env('AUTH_MODEL', Illuminate\Foundation\Auth\User::class),
],

// 'users' => [
Expand Down Expand Up @@ -110,6 +110,6 @@
|
*/

'password_timeout' => 10800,
'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),

];
6 changes: 3 additions & 3 deletions laravel/config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@

'database' => [
'driver' => 'database',
'table' => 'cache',
'connection' => null,
'lock_connection' => null,
'table' => env('DB_CACHE_TABLE', 'cache'),
'connection' => env('DB_CACHE_CONNECTION'),
'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'),
],

'file' => [
Expand Down
8 changes: 4 additions & 4 deletions laravel/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
Expand All @@ -71,7 +71,7 @@
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
Expand All @@ -86,7 +86,7 @@
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => '',
'prefix_indexes' => true,
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
Expand Down
8 changes: 4 additions & 4 deletions laravel/config/hashing.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
|
*/

'driver' => 'bcrypt',
'driver' => env('HASH_DRIVER', 'bcrypt'),

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -44,9 +44,9 @@
*/

'argon' => [
'memory' => 65536,
'threads' => 1,
'time' => 4,
'memory' => env('ARGON_MEMORY', 65536),
'threads' => env('ARGON_THREADS', 1),
'time' => env('ARGON_TIME', 4),
],

];
6 changes: 3 additions & 3 deletions laravel/config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

'deprecations' => [
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
'trace' => false,
'trace' => env('LOG_DEPRECATIONS_TRACE', false),
],

/*
Expand All @@ -53,7 +53,7 @@
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
'channels' => explode(',', env('LOG_STACK', 'single')),
'ignore_exceptions' => false,
],

Expand All @@ -67,7 +67,7 @@
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
'days' => env('LOG_DAILY_DAYS', 14),
],

'slack' => [
Expand Down
Loading

0 comments on commit 111a41b

Please sign in to comment.