From d81e06ca803d6d2d157c18f469180bab3ca28017 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Tue, 3 Dec 2024 22:56:48 -0500 Subject: [PATCH] =?UTF-8?q?Make=20`=E2=80=94name`=20and=20`=E2=80=94descri?= =?UTF-8?q?ption`=20options=20instead=20of=20args,=20since=20they=E2=80=99?= =?UTF-8?q?re=20just=20meta.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Console/Commands/StarterKitInit.php | 56 ++++++++++++------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Console/Commands/StarterKitInit.php b/src/Console/Commands/StarterKitInit.php index 5ca17b19a8..6b5a75cf23 100644 --- a/src/Console/Commands/StarterKitInit.php +++ b/src/Console/Commands/StarterKitInit.php @@ -21,9 +21,9 @@ class StarterKitInit extends Command * @var string */ protected $signature = 'statamic:starter-kit:init - { name? : Specify a name for the starter kit } - { description? : Specify a description of the starter kit } - { package? : Specify a package for the starter kit (ie. vendor/starter-kit) }'; + { package? : Specify a package for the starter kit (ie. vendor/starter-kit) } + { --name : Specify a name for the starter kit } + { --description : Specify a description of the starter kit }'; /** * The console command description. @@ -37,11 +37,11 @@ class StarterKitInit extends Command */ public function handle() { + $package = $this->getKitPackage(); $name = $this->getKitName(); $description = $this->getKitDescription(); - $package = $this->getKitPackage(); - if (! $name || ! $package || ! $description) { + if (! $package || ! $name || ! $description) { $this->components->info('You can manage your starter kit\'s package config in [package/composer.json] at any time.'); } @@ -49,25 +49,9 @@ public function handle() ->createFolder() // ->migrateLegacy() // TODO: Consolidate logic to trait from other PR ->createConfig() - ->createComposerJson($name, $description, $package); + ->createComposerJson($package, $name, $description); - $this->components->success('Starter kit config was successfully created in [package/] folder.'); - } - - /** - * Get starter kit name for composer.json (optional). - */ - protected function getKitName(): ?string - { - return $this->argument('name') ?: text('Starter Kit Name'); - } - - /** - * Get starter kit description for composer.json (optional). - */ - protected function getKitDescription(): ?string - { - return $this->argument('description') ?: text('Starter Kit Description'); + $this->components->success('Your starter kit config was successfully created in your project\'s [package] folder.'); } /** @@ -94,6 +78,22 @@ protected function getKitPackage(bool $promptingAgain = false): ?string return $package; } + /** + * Get starter kit name for composer.json (optional). + */ + protected function getKitName(): ?string + { + return $this->option('name') ?: text('Starter Kit Name (eg. Kung Fury)'); + } + + /** + * Get starter kit description for composer.json (optional). + */ + protected function getKitDescription(): ?string + { + return $this->option('description') ?: text('Starter Kit Description'); + } + /** * Create composer.json config from stub. */ @@ -131,7 +131,7 @@ protected function createConfig(): self /** * Create composer.json config from stub. */ - protected function createComposerJson(?string $name, ?string $description, ?string $package): self + protected function createComposerJson(?string $package, ?string $name, ?string $description): self { $contents = File::get(__DIR__.'/stubs/starter-kits/composer.json.stub'); @@ -143,6 +143,10 @@ protected function createComposerJson(?string $name, ?string $description, ?stri } } + if ($package) { + $contents = str_replace('example/starter-kit-package', $package, $contents); + } + if ($name) { $contents = str_replace('Example Name', $name, $contents); } @@ -151,10 +155,6 @@ protected function createComposerJson(?string $name, ?string $description, ?stri $contents = str_replace('A description of your starter kit', $description, $contents); } - if ($package) { - $contents = str_replace('example/starter-kit-package', $package, $contents); - } - File::put($targetPath, $contents); return $this;