2026-10-05 18:10:18 -04:00
<? php
declare ( strict_types = 1 );
namespace Pterodactyl\Console\Commands\Extensions ;
use Illuminate\Console\Attributes\Description ;
use Illuminate\Console\Attributes\Signature ;
use Illuminate\Console\Command ;
use Illuminate\Contracts\Console\PromptsForMissingInput ;
use Pterodactyl\Exceptions\Extensions\InvalidExtensionException ;
use Pterodactyl\Services\Extensions\Scaffolding\ExtensionScaffolder ;
2026-10-12 07:47:42 -04:00
#[ Description ( 'Scaffold a new extension package (manifest, provider, a client API route with Scribe attributes, and an SDK frontend) or, with --theme, a theme.' )]
2026-10-05 18:10:18 -04:00
#[ Signature ( 'p:extension:make
{id : The extension identifier (lowercase slug, e.g. my-extension).}
{--name= : Display name (defaults to the id in headline case).}
{--description= : Manifest description.}
{--author= : Manifest author.}
{--prefix= : Tailwind prefix for the classes of the extension: 2-12 lowercase letters (defaults to one derived from the id).}
{--no-ui : Skip the frontend scaffold (backend-only extension).}
2026-10-12 07:47:42 -04:00
{--theme : Scaffold a theme: stylesheet, a layout override, a skin, settings and a test.}
2026-10-12 18:21:55 -04:00
{--css-only : With --theme: a theme of CSS alone, with no JavaScript entry.}
2026-10-12 19:13:11 -04:00
{--extends= : With --theme: the theme to build on. Scaffolds a child that inherits its views, skins, stylesheet and settings.}
2026-10-12 17:58:43 -04:00
{--out= : Parent directory: the package is created in <out>/<id> (defaults to the extensions directory).}
{--path= : The package directory itself, created exactly as given (instead of --out).}
2026-10-05 18:10:18 -04:00
{--force : Overwrite the target directory if it already exists.}' )]
class MakeCommand extends Command implements PromptsForMissingInput
{
public function handle ( ExtensionScaffolder $scaffolder ) : int
{
try {
$target = $scaffolder -> scaffold (
id : $this -> argument ( 'id' ),
name : $this -> option ( 'name' ),
description : $this -> option ( 'description' ),
author : $this -> option ( 'author' ),
ui : ! $this -> option ( 'no-ui' ),
outDir : $this -> option ( 'out' ),
force : ( bool ) $this -> option ( 'force' ),
prefix : $this -> option ( 'prefix' ),
2026-10-12 07:47:42 -04:00
theme : ( bool ) $this -> option ( 'theme' ),
2026-10-12 17:58:43 -04:00
path : $this -> option ( 'path' ),
2026-10-12 18:21:55 -04:00
cssOnly : ( bool ) $this -> option ( 'css-only' ),
2026-10-12 19:13:11 -04:00
extends : $this -> option ( 'extends' ),
2026-10-05 18:10:18 -04:00
);
} catch ( InvalidExtensionException $invalidExtensionException ) {
$this -> components -> error ( $invalidExtensionException -> getMessage ());
return self :: FAILURE ;
}
$this -> components -> info ( "Extension scaffolded at { $target } ." );
foreach ( $scaffolder -> files () as $file ) {
$this -> components -> twoColumnDetail ( $file , '<fg=green>created</>' );
}
$this -> line ( '' );
$this -> components -> info ( 'Next steps:' );
2026-10-12 19:14:14 -04:00
// p:extension:dev builds, installs and enables the package where it is; p:extension:install takes archives.
2026-10-05 18:10:18 -04:00
$this -> components -> bulletList ( array_filter ([
2026-10-12 19:14:14 -04:00
$this -> option ( 'no-ui' ) && ! $this -> option ( 'theme' ) ? null : "cd { $target } && npm install" ,
"php artisan p:extension:dev { $target } --enable" ,
2026-10-12 07:47:42 -04:00
$this -> option ( 'theme' ) ? "php artisan p:theme:activate { $this -> argument ( 'id' ) } " : null ,
2026-10-05 18:10:18 -04:00
]));
return self :: SUCCESS ;
}
/** @return array<string, array<int, string>> */
protected function promptForMissingArgumentsUsing () : array
{
return [
'id' => [ 'What should the extension be identified as?' , 'E.g. my-extension' ],
];
}
}