Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Add new starter-kit:init command #11215

Merged
merged 26 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4d1175b
Add new `starter-kit:init` command.
jesseleite Dec 4, 2024
40b8600
Register command.
jesseleite Dec 4, 2024
72eca06
Update stub.
jesseleite Dec 4, 2024
2faa54f
Clean up other commands a bit to match this one.
jesseleite Dec 4, 2024
d81e06c
Make `—name` and `—description` options instead of args, since they’r…
jesseleite Dec 4, 2024
6f5b808
Merge branch '5.x' of https://github.com/statamic/cms into starter-ki…
jesseleite Dec 4, 2024
9b915ab
Extract this out so it can be reused by `init` command.
jesseleite Dec 4, 2024
8df346d
Make it runnable without export path.
jesseleite Dec 4, 2024
d7d9333
Implement legacy config migration in `init`.
jesseleite Dec 4, 2024
ecf0442
Make `—force` to skip prompts and overwrite.
jesseleite Dec 4, 2024
9e33094
Add prompt to ask if user wants kit `updatable`, and adjust stubbed f…
jesseleite Dec 4, 2024
03defc6
Todo.
jesseleite Dec 4, 2024
3095f76
Extract updatable prompt to method.
jesseleite Dec 5, 2024
f2d2448
Dynamically generate composer.json.
jesseleite Dec 5, 2024
abfc28b
Remove unused stub.
jesseleite Dec 5, 2024
a586d7e
Add guards to fix mockery expectations in non-interactive tests.
jesseleite Dec 5, 2024
a4e6c5b
Fix issue with package error output.
jesseleite Dec 5, 2024
b955b35
Add test coverage.
jesseleite Dec 5, 2024
7e204fb
Pass tests around `package` validation error.
jesseleite Dec 5, 2024
9e4b24b
Refactor to use properties.
jesseleite Dec 5, 2024
196e2e2
Add service provider stub.
jesseleite Dec 5, 2024
b6032a4
Create service provider in updatable kits.
jesseleite Dec 5, 2024
0411923
Test coverage.
jesseleite Dec 5, 2024
f92ba52
Merge branch '5.x' of https://github.com/statamic/cms into starter-ki…
jesseleite Dec 5, 2024
fe05bff
This is why we can’t have nice things.
jesseleite Dec 5, 2024
c10b139
Ignore line endings.
jesseleite Dec 5, 2024
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
67 changes: 67 additions & 0 deletions src/Console/Commands/Concerns/MigratesLegacyStarterKitConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Statamic\Console\Commands\Concerns;

use Statamic\Facades\File;

use function Laravel\Prompts\confirm;

trait MigratesLegacyStarterKitConfig
{
protected $migrated = false;

/**
* Determine if dev sandbox has starter-kit.yaml at root and/or customized composer.json at target path.
*/
protected function isUsingLegacyExporterConventions(): bool
{
return File::exists(base_path('starter-kit.yaml'));
}

/**
* Determine if dev sandbox has starter-kit.yaml at root and/or customized composer.json at target path.
*/
protected function migrateLegacyConfig(?string $exportPath = null): self
{
if (! $this->isUsingLegacyExporterConventions()) {
return $this;
}

if ($this->input->isInteractive()) {
if (! confirm('Config should now live in the [package] folder. Would you like Statamic to move it for you?', true)) {
return $this;
}
}

if (! File::exists($dir = base_path('package'))) {
File::makeDirectory($dir, 0755, true);
}

if (File::exists($starterKitConfig = base_path('starter-kit.yaml'))) {
File::move($starterKitConfig, base_path('package/starter-kit.yaml'));
$this->components->info('Starter kit config moved to [package/starter-kit.yaml].');
}

if (File::exists($postInstallHook = base_path('StarterKitPostInstall.php'))) {
File::move($postInstallHook, base_path('package/StarterKitPostInstall.php'));
$this->components->info('Starter kit post-install hook moved to [package/StarterKitPostInstall.php].');
}

if ($exportPath && File::exists($packageComposerJson = $exportPath.'/composer.json')) {
File::move($packageComposerJson, base_path('package/composer.json'));
$this->components->info('Composer package config moved to [package/composer.json].');
}

$this->migrated = true;

return $this;
}

/**
* Check if migration logic was ran.
*/
protected function migratedLegacyConfig(): bool
{
return $this->migrated;
}
}
56 changes: 11 additions & 45 deletions src/Console/Commands/StarterKitExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Console\Commands;

use Illuminate\Console\Command;
use Statamic\Console\Commands\Concerns\MigratesLegacyStarterKitConfig;
use Statamic\Console\RunsInPlease;
use Statamic\Facades\File;
use Statamic\Facades\Path;
Expand All @@ -13,7 +14,7 @@

class StarterKitExport extends Command
{
use RunsInPlease;
use MigratesLegacyStarterKitConfig, RunsInPlease;

/**
* The name and signature of the console command.
Expand All @@ -36,11 +37,11 @@ class StarterKitExport extends Command
*/
public function handle()
{
if ($this->isUsingLegacyExporterConventions()) {
$this->askToMigrateToPackageFolder();
}
$path = $this->getAbsolutePath();

$this->migrateLegacyConfig($path);

if (! File::exists($path = $this->getAbsolutePath())) {
if (! File::exists($path)) {
$this->askToCreateExportPath($path);
}

Expand All @@ -55,7 +56,11 @@ public function handle()
return 1;
}

$this->components->info("Starter kit was successfully exported to [$path].");
if (version_compare(app()->version(), '11', '<')) {
return $this->components->info("Starter kit was successfully exported to [$path].");
}

$this->components->success("Starter kit was successfully exported to [$path].");
}

/**
Expand Down Expand Up @@ -85,43 +90,4 @@ protected function askToCreateExportPath(string $path): void

$this->components->info("A new directory has been created at [{$path}].");
}

/**
* Determine if dev sandbox has starter-kit.yaml at root and/or customized composer.json at target path.
*/
protected function isUsingLegacyExporterConventions(): bool
{
return File::exists(base_path('starter-kit.yaml'));
}

/**
* Determine if dev sandbox has starter-kit.yaml at root and/or customized composer.json at target path.
*/
protected function askToMigrateToPackageFolder(): void
{
if ($this->input->isInteractive()) {
if (! confirm('Config should now live in the [package] folder. Would you like Statamic to move it for you?', true)) {
return;
}
}

if (! File::exists($dir = base_path('package'))) {
File::makeDirectory($dir, 0755, true);
}

if (File::exists($starterKitConfig = base_path('starter-kit.yaml'))) {
File::move($starterKitConfig, base_path('package/starter-kit.yaml'));
$this->components->info('Starter kit config moved to [package/starter-kit.yaml].');
}

if (File::exists($postInstallHook = base_path('StarterKitPostInstall.php'))) {
File::move($postInstallHook, base_path('package/StarterKitPostInstall.php'));
$this->components->info('Starter kit post-install hook moved to [package/StarterKitPostInstall.php].');
}

if (File::exists($packageComposerJson = $this->getAbsolutePath().'/composer.json')) {
File::move($packageComposerJson, base_path('package/composer.json'));
$this->components->info('Composer package config moved to [package/composer.json].');
}
}
}
Loading
Loading