Skip to content

Commit

Permalink
Merge branch '9.x' into 10.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Aug 14, 2024
2 parents 681300e + db7ba7a commit 48af537
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 80 deletions.
36 changes: 36 additions & 0 deletions CHANGELOG-8.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

This changelog references the relevant changes (bug and security fixes) done to `orchestra/workbench`.

## 8.9.0

Released: 2024-08-14

### Added

* Added `Orchestra\Workbench\Console\InstallCommand::$configurationBaseFile` option to define the default `testbench.yaml` stub.
* Utilise Symfony Console `InputOption::VALUE_NEGATABLE` feature on `workbench:install` and `workbench:devtool` command.
* Implements `Illuminate\Contracts\Console\PromptsForMissingInput` on `workbench:install` and `workbench:devtool` command.

## 8.8.1

Released: 2024-08-12

### Changes

* Update `workbench:devtool` command.

## 8.8.0

Released: 2024-08-10

### Changes

* Generate `User` model and `UserFactory` class via `workbench:install`.
* Update generated `DatabaseSeeder.php` to match Laravel 10 skeleton.

## 8.7.0

Released: 2024-08-06

### Changes

* Flush session when loading the start page via `composer run serve`.
* Disallow running `workbench:build`, `workbench:devtool` or `workbench:install` via `workbench:build` command.

## 8.6.0

Released: 2024-07-30
Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG-9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

This changelog references the relevant changes (bug and security fixes) done to `orchestra/workbench`.

## 9.5.0

Released: 2024-08-14

### Added

* Added `Orchestra\Workbench\Console\InstallCommand::$configurationBaseFile` option to define the default `testbench.yaml` stub.
* Utilise Symfony Console `InputOption::VALUE_NEGATABLE` feature on `workbench:install` and `workbench:devtool` command.
* Implements `Illuminate\Contracts\Console\PromptsForMissingInput` on `workbench:install` and `workbench:devtool` command.

## 9.4.1

Released: 2024-08-12

### Changes

* Update `workbench:devtool` command.

## 9.4.0

Released: 2024-08-10

### Changes

* Generate `User` model and `UserFactory` class via `workbench:install`.
* Update generated `DatabaseSeeder.php` to match Laravel 11 skeleton.

## 9.3.0

Released: 2024-08-06

### Changes

* Flush session when loading the start page via `composer run serve`.
* Disallow running `workbench:build`, `workbench:devtool` or `workbench:install` via `workbench:build` command.

## 9.2.0

Released: 2024-07-30
Expand Down
9 changes: 9 additions & 0 deletions bin/sync
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Symfony\Component\Process\Process::fromShellCommandline(

Illuminate\Support\Collection::make([
'bootstrap/app.php',
'database/seeders/DatabaseSeeder.php',
// 'routes/api.php',
'routes/console.php',
'routes/web.php',
Expand All @@ -33,6 +34,14 @@ transform([
'return Application::configure(basePath: dirname(__DIR__))' => 'use function Orchestra\Testbench\default_skeleton_path;'.PHP_EOL.PHP_EOL.'return Application::configure(basePath: $APP_BASE_PATH ?? default_skeleton_path())',
PHP_EOL." health: '/up',".PHP_EOL => PHP_EOL,
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/bootstrap/app.php"));

transform([
'namespace Database\Seeders;' => 'namespace Workbench\Database\Seeders;',
'use App\Models\User;' => 'use Orchestra\Testbench\Factories\UserFactory;',
'User::factory(10)->create' => 'UserFactory::new(10)->create',
'User::factory()->create' => 'UserFactory::new()->create',
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/database/seeders/DatabaseSeeder.php"));

transform([
'Artisan::command(\'inspire\', function () {
$this->comment(Inspiring::quote());
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve"
"@php vendor/bin/testbench serve --ansi"
],
"lint": [
"@php vendor/bin/pint",
"@php vendor/bin/phpstan analyse"
"@php vendor/bin/pint --ansi",
"@php vendor/bin/phpstan analyse --verbose"
],
"test": "@php vendor/bin/phpunit",
"ci": [
Expand Down
28 changes: 25 additions & 3 deletions src/BuildParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@

use Illuminate\Support\Collection;

/**
* @internal
*/
class BuildParser
{
/**
* List of disallowed commands.
*
* @var array
*/
protected static $disallowedCommands = [
'workbench:build',
'workbench:devtool',
'workbench:install',
];

/**
* Get Workbench build steps.
*
Expand All @@ -15,7 +29,7 @@ class BuildParser
public static function make(array $config): Collection
{
return Collection::make($config)
->mapWithKeys(static function (array|string $build) {
->map(static function (array|string $build) {
/** @var string $name */
$name = match (true) {
\is_array($build) => array_key_first($build),
Expand All @@ -29,8 +43,16 @@ public static function make(array $config): Collection
};

return [
$name => Collection::make($options)->mapWithKeys(static fn ($value, $key) => [$key => $value])->all(),
'name' => $name,
'options' => Collection::make($options)->mapWithKeys(static fn ($value, $key) => [$key => $value])->all(),
];
});
})->whereNotIn(
'name',
Collection::make(static::$disallowedCommands)
->transform(static fn ($command) => [$command, str_replace(':', '-', $command)])
->flatten(),
)->mapWithKeys(static fn (array $build) => [
$build['name'] => $build['options'],
]);
}
}
107 changes: 85 additions & 22 deletions src/Console/DevToolCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\InstalledVersions;
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
Expand All @@ -14,22 +15,17 @@
use Orchestra\Workbench\Events\InstallStarted;
use Orchestra\Workbench\Workbench;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function Illuminate\Filesystem\join_paths;
use function Laravel\Prompts\confirm;
use function Orchestra\Testbench\package_path;

#[AsCommand(name: 'workbench:devtool', description: 'Configure Workbench for package development')]
class DevToolCommand extends Command
class DevToolCommand extends Command implements PromptsForMissingInput
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'workbench:devtool
{--force : Overwrite any existing files}
{--skip-install : Skipped Workbench installation}';

/**
* Execute the console command.
*
Expand All @@ -44,10 +40,10 @@ public function handle(Filesystem $filesystem)
$this->prepareWorkbenchDirectories($filesystem, $workingPath);
$this->prepareWorkbenchNamespaces($filesystem, $workingPath);

if (! $this->option('skip-install')) {
if ($this->option('install') === true) {
$this->call('workbench:install', [
'--force' => $this->option('force'),
'--skip-devtool' => true,
'--no-devtool' => true,
]);
}

Expand Down Expand Up @@ -85,12 +81,10 @@ protected function prepareWorkbenchDirectories(Filesystem $filesystem, string $w
$this->callSilently('make:provider', [
'name' => 'WorkbenchServiceProvider',
'--preset' => 'workbench',
'--force' => (bool) $this->option('force'),
]);

$this->callSilently('make:seeder', [
'name' => 'DatabaseSeeder',
'--preset' => 'workbench',
]);
$this->prepareWorkbenchDatabaseSchema($filesystem, $workbenchWorkingPath);

foreach (['console', 'web'] as $route) {
(new GeneratesFile(
Expand All @@ -116,6 +110,39 @@ protected function prepareWorkbenchNamespaces(Filesystem $filesystem, string $wo
));
}

/**
* Prepare workbench database schema including user model, factory and seeder.
*/
protected function prepareWorkbenchDatabaseSchema(Filesystem $filesystem, string $workingPath): void
{
$this->callSilently('make:user-model', [
'--preset' => 'workbench',
'--force' => (bool) $this->option('force'),
]);

$this->callSilently('make:user-factory', [
'--preset' => 'workbench',
'--force' => (bool) $this->option('force'),
]);

(new GeneratesFile(
filesystem: $filesystem,
components: $this->components,
force: (bool) $this->option('force'),
))->handle(
(string) realpath(join_paths(__DIR__, 'stubs', 'database', 'seeders', 'DatabaseSeeder.php')),
join_paths($workingPath, 'database', 'seeders', 'DatabaseSeeder.php')
);

if ($filesystem->exists(join_paths($workingPath, 'database', 'factories', 'UserFactory.php'))) {
$filesystem->replaceInFile([
'use Orchestra\Testbench\Factories\UserFactory;',
], [
'use Workbench\Database\Factories\UserFactory;',
], join_paths($workingPath, 'database', 'seeders', 'DatabaseSeeder.php'));
}
}

/**
* Append `scripts` to `composer.json`.
*/
Expand Down Expand Up @@ -155,21 +182,21 @@ protected function appendScriptsToComposer(array $content, Filesystem $filesyste
'Composer\\Config::disableProcessTimeout',
'@build',
$hasTestbenchDusk && \defined('TESTBENCH_DUSK')
? '@php vendor/bin/testbench-dusk serve'
: '@php vendor/bin/testbench serve',
? '@php vendor/bin/testbench-dusk serve --ansi'
: '@php vendor/bin/testbench serve --ansi',
];

if (! \array_key_exists('lint', $content['scripts'])) {
$lintScripts = [];

if (InstalledVersions::isInstalled('laravel/pint')) {
$lintScripts[] = '@php vendor/bin/pint';
$lintScripts[] = '@php vendor/bin/pint --ansi';
} elseif ($filesystem->exists(Workbench::packagePath('pint.json'))) {
$lintScripts[] = 'pint';
}

if (InstalledVersions::isInstalled('phpstan/phpstan')) {
$lintScripts[] = '@php vendor/bin/phpstan analyse';
$lintScripts[] = '@php vendor/bin/phpstan analyse --verbose --ansi';
}

if (\count($lintScripts) > 0) {
Expand Down Expand Up @@ -216,17 +243,53 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files
if (! \array_key_exists($namespace, $content['autoload-dev']['psr-4'])) {
$content['autoload-dev']['psr-4'][$namespace] = $path;

$this->components->task(sprintf(
$this->components->task(\sprintf(
'Added [%s] for [%s] to Composer', $namespace, $path
));
} else {
$this->components->twoColumnDetail(
sprintf('Composer already contain [%s] namespace', $namespace),
\sprintf('Composer already contain [%s] namespace', $namespace),
'<fg=yellow;options=bold>SKIPPED</>'
);
}
}

return $content;
}

/**
* Prompt the user for any missing arguments.
*
* @return void
*/
protected function promptForMissingArguments(InputInterface $input, OutputInterface $output)
{
$install = null;

if ($input->getOption('skip-install') === true) {
$install = false;
} elseif (\is_null($input->getOption('install'))) {
$install = confirm('Run Workbench installation?', true);
}

if (! \is_null($install)) {
$input->setOption('install', $install);
}
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['force', 'f', InputOption::VALUE_NONE, 'Overwrite any existing files'],
['install', null, InputOption::VALUE_NEGATABLE, 'Run Workbench installation'],

/** @deprecated */
['skip-install', null, InputOption::VALUE_NONE, 'Skipped Workbench installation (deprecated)'],
];
}
}
Loading

0 comments on commit 48af537

Please sign in to comment.