new deployer command

This commit is contained in:
Mark Gregory
2026-09-16 11:01:02 +01:00
parent 0756b1de79
commit 45a370ed91
20 changed files with 193 additions and 161 deletions
+1 -2
View File
@@ -2,7 +2,6 @@
return [ return [
'name' => 'M3', 'name' => 'M3',
'features' => 'features' => [
[
], ],
]; ];
@@ -2,8 +2,8 @@
namespace Modules\M3\Database\Seeders; namespace Modules\M3\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class M3DatabaseSeeder extends Seeder class M3DatabaseSeeder extends Seeder
{ {
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
use Modules\M3\Support\ModuleInfo; use Modules\M3\Support\ModuleInfo;
if (! function_exists('m3_feature_enabled')) { if (! function_exists('m3_feature_enabled')) {
@@ -10,6 +10,7 @@ class M3Controller extends Controller
{ {
/** /**
* Display a listing of the resource. * Display a listing of the resource.
*
* @return Renderable * @return Renderable
*/ */
public function index() public function index()
@@ -19,6 +20,7 @@ class M3Controller extends Controller
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
*
* @return Renderable * @return Renderable
*/ */
public function create() public function create()
@@ -28,7 +30,9 @@ class M3Controller extends Controller
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
*
* @param Request $request * @param Request $request
*
* @return Renderable * @return Renderable
*/ */
public function store(Request $request) public function store(Request $request)
@@ -38,7 +42,9 @@ class M3Controller extends Controller
/** /**
* Show the specified resource. * Show the specified resource.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function show($id) public function show($id)
@@ -48,7 +54,9 @@ class M3Controller extends Controller
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function edit($id) public function edit($id)
@@ -58,8 +66,10 @@ class M3Controller extends Controller
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
*
* @param Request $request * @param Request $request
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
@@ -69,7 +79,9 @@ class M3Controller extends Controller
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function destroy($id) public function destroy($id)
+11 -9
View File
@@ -2,25 +2,23 @@
namespace Modules\M3\Providers; namespace Modules\M3\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\Facades\File;
use Modules\M3\Support\ModuleInfo;
use Config; use Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Modules\M3\Support\ModuleInfo;
class M3ServiceProvider extends ServiceProvider class M3ServiceProvider extends ServiceProvider
{ {
/** /**
* @var string $moduleName * @var string
*/ */
protected string $moduleName = 'M3'; protected string $moduleName = 'M3';
/** /**
* @var string $moduleNameLower * @var string
*/ */
protected string $moduleNameLower = 'm3'; protected string $moduleNameLower = 'm3';
/** /**
* Get the services provided by the provider. * Get the services provided by the provider.
* *
@@ -82,6 +80,7 @@ class M3ServiceProvider extends ServiceProvider
$commands = collect(File::allFiles($commandPath)) $commands = collect(File::allFiles($commandPath))
->map(function ($file) { ->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension(); $class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class; return $class;
}) })
->filter(function ($class) { ->filter(function ($class) {
@@ -103,7 +102,8 @@ class M3ServiceProvider extends ServiceProvider
module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower() . '.php'), module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower() . '.php'),
], 'config'); ], 'config');
$this->mergeConfigFrom( $this->mergeConfigFrom(
module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower() module_path(ModuleInfo::name(), 'Config/config.php'),
ModuleInfo::nameLower(),
); );
} }
@@ -117,7 +117,7 @@ class M3ServiceProvider extends ServiceProvider
$viewPath = resource_path('views/modules/' . ModuleInfo::nameLower()); $viewPath = resource_path('views/modules/' . ModuleInfo::nameLower());
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views'); $sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
$this->publishes([ $this->publishes([
$sourcePath => $viewPath $sourcePath => $viewPath,
], ['views', ModuleInfo::nameLower() . '-module-views']); ], ['views', ModuleInfo::nameLower() . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower()); $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
} }
@@ -140,6 +140,7 @@ class M3ServiceProvider extends ServiceProvider
/** /**
* Regsiter View Paths * Regsiter View Paths
*
* @return array * @return array
*/ */
private function getPublishableViewPaths(): array private function getPublishableViewPaths(): array
@@ -150,6 +151,7 @@ class M3ServiceProvider extends ServiceProvider
$paths[] = $path . '/modules/' . ModuleInfo::nameLower(); $paths[] = $path . '/modules/' . ModuleInfo::nameLower();
} }
} }
return $paths; return $paths;
} }
} }
@@ -2,8 +2,8 @@
namespace Modules\M3\Providers; namespace Modules\M3\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider class RouteServiceProvider extends ServiceProvider
{ {
+2
View File
@@ -8,6 +8,7 @@ class ModuleInfo
/** /**
* defines the Module Name * defines the Module Name
*
* @return string * @return string
*/ */
public static function name(): string public static function name(): string
@@ -17,6 +18,7 @@ class ModuleInfo
/** /**
* define the lowercase version * define the lowercase version
*
* @return string * @return string
*/ */
public static function nameLower(): string public static function nameLower(): string
+1 -2
View File
@@ -2,7 +2,6 @@
return [ return [
'name' => 'OTM', 'name' => 'OTM',
'features' => 'features' => [
[
], ],
]; ];
@@ -2,8 +2,8 @@
namespace Modules\OTM\Database\Seeders; namespace Modules\OTM\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class OTMDatabaseSeeder extends Seeder class OTMDatabaseSeeder extends Seeder
{ {
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
use Modules\OTM\Support\ModuleInfo; use Modules\OTM\Support\ModuleInfo;
if (! function_exists('otm_feature_enabled')) { if (! function_exists('otm_feature_enabled')) {
@@ -10,6 +10,7 @@ class OTMController extends Controller
{ {
/** /**
* Display a listing of the resource. * Display a listing of the resource.
*
* @return Renderable * @return Renderable
*/ */
public function index() public function index()
@@ -19,6 +20,7 @@ class OTMController extends Controller
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
*
* @return Renderable * @return Renderable
*/ */
public function create() public function create()
@@ -28,7 +30,9 @@ class OTMController extends Controller
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
*
* @param Request $request * @param Request $request
*
* @return Renderable * @return Renderable
*/ */
public function store(Request $request) public function store(Request $request)
@@ -38,7 +42,9 @@ class OTMController extends Controller
/** /**
* Show the specified resource. * Show the specified resource.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function show($id) public function show($id)
@@ -48,7 +54,9 @@ class OTMController extends Controller
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function edit($id) public function edit($id)
@@ -58,8 +66,10 @@ class OTMController extends Controller
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
*
* @param Request $request * @param Request $request
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
@@ -69,7 +79,9 @@ class OTMController extends Controller
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*
* @param int $id * @param int $id
*
* @return Renderable * @return Renderable
*/ */
public function destroy($id) public function destroy($id)
+11 -9
View File
@@ -2,25 +2,23 @@
namespace Modules\OTM\Providers; namespace Modules\OTM\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\Facades\File;
use Modules\OTM\Support\ModuleInfo;
use Config; use Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Modules\OTM\Support\ModuleInfo;
class OTMServiceProvider extends ServiceProvider class OTMServiceProvider extends ServiceProvider
{ {
/** /**
* @var string $moduleName * @var string
*/ */
protected string $moduleName = 'OTM'; protected string $moduleName = 'OTM';
/** /**
* @var string $moduleNameLower * @var string
*/ */
protected string $moduleNameLower = 'otm'; protected string $moduleNameLower = 'otm';
/** /**
* Get the services provided by the provider. * Get the services provided by the provider.
* *
@@ -82,6 +80,7 @@ class OTMServiceProvider extends ServiceProvider
$commands = collect(File::allFiles($commandPath)) $commands = collect(File::allFiles($commandPath))
->map(function ($file) { ->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension(); $class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class; return $class;
}) })
->filter(function ($class) { ->filter(function ($class) {
@@ -103,7 +102,8 @@ class OTMServiceProvider extends ServiceProvider
module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower() . '.php'), module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower() . '.php'),
], 'config'); ], 'config');
$this->mergeConfigFrom( $this->mergeConfigFrom(
module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower() module_path(ModuleInfo::name(), 'Config/config.php'),
ModuleInfo::nameLower(),
); );
} }
@@ -117,7 +117,7 @@ class OTMServiceProvider extends ServiceProvider
$viewPath = resource_path('views/modules/' . ModuleInfo::nameLower()); $viewPath = resource_path('views/modules/' . ModuleInfo::nameLower());
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views'); $sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
$this->publishes([ $this->publishes([
$sourcePath => $viewPath $sourcePath => $viewPath,
], ['views', ModuleInfo::nameLower() . '-module-views']); ], ['views', ModuleInfo::nameLower() . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower()); $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
} }
@@ -140,6 +140,7 @@ class OTMServiceProvider extends ServiceProvider
/** /**
* Regsiter View Paths * Regsiter View Paths
*
* @return array * @return array
*/ */
private function getPublishableViewPaths(): array private function getPublishableViewPaths(): array
@@ -150,6 +151,7 @@ class OTMServiceProvider extends ServiceProvider
$paths[] = $path . '/modules/' . ModuleInfo::nameLower(); $paths[] = $path . '/modules/' . ModuleInfo::nameLower();
} }
} }
return $paths; return $paths;
} }
} }
@@ -2,8 +2,8 @@
namespace Modules\OTM\Providers; namespace Modules\OTM\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider class RouteServiceProvider extends ServiceProvider
{ {
+2
View File
@@ -8,6 +8,7 @@ class ModuleInfo
/** /**
* defines the Module Name * defines the Module Name
*
* @return string * @return string
*/ */
public static function name(): string public static function name(): string
@@ -17,6 +18,7 @@ class ModuleInfo
/** /**
* define the lowercase version * define the lowercase version
*
* @return string * @return string
*/ */
public static function nameLower(): string public static function nameLower(): string
+21 -21
View File
@@ -69,14 +69,14 @@ class DatabaseStage extends Command
['Stage server', "{$stage['ssh_user']}@{$stage['ssh_host']}"], ['Stage server', "{$stage['ssh_user']}@{$stage['ssh_host']}"],
['Stage database', $stage['database']], ['Stage database', $stage['database']],
['Stage owner', $stage['username']], ['Stage owner', $stage['username']],
] ],
); );
if ( if (
! $this->option('force') && ! $this->option('force') &&
! $this->confirm( ! $this->confirm(
"This will DROP and completely RECREATE '{$stage['database']}'. Continue?", "This will DROP and completely RECREATE '{$stage['database']}'. Continue?",
false false,
) )
) { ) {
$this->warn('Cancelled.'); $this->warn('Cancelled.');
@@ -134,7 +134,7 @@ class DatabaseStage extends Command
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"pg_dump failed:\n".$result->errorOutput() "pg_dump failed:\n" . $result->errorOutput(),
); );
} }
@@ -143,7 +143,7 @@ class DatabaseStage extends Command
} }
return true; return true;
} },
); );
$dumpSize = $this->formatBytes(filesize($localDump)); $dumpSize = $this->formatBytes(filesize($localDump));
@@ -167,12 +167,12 @@ class DatabaseStage extends Command
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Invalid PostgreSQL archive:\n".$result->errorOutput() "Invalid PostgreSQL archive:\n" . $result->errorOutput(),
); );
} }
return true; return true;
} },
); );
/* /*
@@ -194,12 +194,12 @@ class DatabaseStage extends Command
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Upload failed:\n".$result->errorOutput() "Upload failed:\n" . $result->errorOutput(),
); );
} }
return true; return true;
} },
); );
/* /*
@@ -220,7 +220,7 @@ class DatabaseStage extends Command
$terminateDatabase = str_replace( $terminateDatabase = str_replace(
"'", "'",
"''", "''",
$stage['database'] $stage['database'],
); );
$sql = <<<SQL $sql = <<<SQL
@@ -238,7 +238,7 @@ SQL;
$remoteCommand = sprintf( $remoteCommand = sprintf(
'sudo -u %s psql --set ON_ERROR_STOP=on --dbname=postgres', 'sudo -u %s psql --set ON_ERROR_STOP=on --dbname=postgres',
escapeshellarg($stage['admin_username']) escapeshellarg($stage['admin_username']),
); );
$result = Process::input($sql) $result = Process::input($sql)
@@ -254,12 +254,12 @@ SQL;
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Unable to recreate stage database:\n" . "Unable to recreate stage database:\n" .
$result->errorOutput() $result->errorOutput(),
); );
} }
return true; return true;
} },
); );
/* /*
@@ -301,12 +301,12 @@ SQL;
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Database restore failed:\n" . "Database restore failed:\n" .
$result->errorOutput() $result->errorOutput(),
); );
} }
return true; return true;
} },
); );
/* /*
@@ -332,7 +332,7 @@ SQL;
escapeshellarg($stage['username']), escapeshellarg($stage['username']),
escapeshellarg($stage['database']), escapeshellarg($stage['database']),
escapeshellarg( escapeshellarg(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';" "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';",
), ),
); );
@@ -347,7 +347,7 @@ SQL;
if ($result->failed()) { if ($result->failed()) {
throw new RuntimeException( throw new RuntimeException(
"Database verification failed:\n" . "Database verification failed:\n" .
$result->errorOutput() $result->errorOutput(),
); );
} }
@@ -356,7 +356,7 @@ SQL;
$this->line(" Stage public tables: {$count}"); $this->line(" Stage public tables: {$count}");
return true; return true;
} },
); );
/* /*
@@ -381,11 +381,11 @@ SQL;
$this->newLine(); $this->newLine();
$this->components->info( $this->components->info(
'Stage PostgreSQL database cloned successfully.' 'Stage PostgreSQL database cloned successfully.',
); );
$this->line( $this->line(
"Local {$local['database']} → Stage {$stage['database']}" "Local {$local['database']} → Stage {$stage['database']}",
); );
return self::SUCCESS; return self::SUCCESS;
@@ -396,7 +396,7 @@ SQL;
$this->newLine(); $this->newLine();
$this->warn( $this->warn(
"The dump may still exist at {$localDump} and/or {$remoteDump}." "The dump may still exist at {$localDump} and/or {$remoteDump}.",
); );
return self::FAILURE; return self::FAILURE;
@@ -419,7 +419,7 @@ SQL;
return number_format( return number_format(
$bytes / (1024 ** $power), $bytes / (1024 ** $power),
$power === 0 ? 0 : 2 $power === 0 ? 0 : 2,
) . ' ' . $units[$power]; ) . ' ' . $units[$power];
} }
} }
+3 -3
View File
@@ -48,7 +48,7 @@ task('build', function (): void {
run( run(
$node $node
. ' && cd {{release_path}}' . ' && cd {{release_path}}'
.' && npm ci --no-audit --no-fund' . ' && npm ci --no-audit --no-fund',
); );
run( run(
@@ -59,13 +59,13 @@ task('build', function (): void {
. ' module_dir="$(dirname "$lock")";' . ' module_dir="$(dirname "$lock")";'
. ' echo "[Modules] npm ci: $module_dir";' . ' echo "[Modules] npm ci: $module_dir";'
. ' (cd "$module_dir" && npm ci --no-audit --no-fund);' . ' (cd "$module_dir" && npm ci --no-audit --no-fund);'
.' done' . ' done',
); );
run( run(
$node $node
. ' && cd {{release_path}}' . ' && cd {{release_path}}'
.' && npm run build' . ' && npm run build',
); );
}); });