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
+2 -3
View File
@@ -2,7 +2,6 @@
return [
'name' => 'M3',
'features' =>
[
],
'features' => [
],
];
@@ -2,8 +2,8 @@
namespace Modules\M3\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class M3DatabaseSeeder extends Seeder
{
+2 -1
View File
@@ -1,4 +1,5 @@
<?php
use Modules\M3\Support\ModuleInfo;
if (! function_exists('m3_feature_enabled')) {
@@ -7,6 +8,6 @@ if (! function_exists('m3_feature_enabled')) {
*/
function m3_feature_enabled(string $key): bool
{
return (bool) config(ModuleInfo::nameLower().".features.{$key}", false);
return (bool) config(ModuleInfo::nameLower() . ".features.{$key}", false);
}
}
+13 -1
View File
@@ -10,6 +10,7 @@ class M3Controller extends Controller
{
/**
* Display a listing of the resource.
*
* @return Renderable
*/
public function index()
@@ -19,6 +20,7 @@ class M3Controller extends Controller
/**
* Show the form for creating a new resource.
*
* @return Renderable
*/
public function create()
@@ -28,7 +30,9 @@ class M3Controller extends Controller
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return Renderable
*/
public function store(Request $request)
@@ -38,7 +42,9 @@ class M3Controller extends Controller
/**
* Show the specified resource.
*
* @param int $id
*
* @return Renderable
*/
public function show($id)
@@ -48,7 +54,9 @@ class M3Controller extends Controller
/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return Renderable
*/
public function edit($id)
@@ -58,8 +66,10 @@ class M3Controller extends Controller
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @param int $id
*
* @return Renderable
*/
public function update(Request $request, $id)
@@ -69,7 +79,9 @@ class M3Controller extends Controller
/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return Renderable
*/
public function destroy($id)
+40 -38
View File
@@ -2,31 +2,29 @@
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 Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Modules\M3\Support\ModuleInfo;
class M3ServiceProvider extends ServiceProvider
{
/**
* @var string $moduleName
* @var string
*/
protected string $moduleName = 'M3';
/**
* @var string $moduleNameLower
* @var string
*/
protected string $moduleNameLower = 'm3';
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides():array
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides(): array
{
return [];
}
@@ -36,7 +34,7 @@ class M3ServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot() : void
public function boot(): void
{
$this->registerTranslations();
$this->registerConfig();
@@ -63,34 +61,35 @@ class M3ServiceProvider extends ServiceProvider
*/
protected function registerHelpers(): void
{
foreach (glob(__DIR__.'/../Helpers/*.php') as $filename) {
foreach (glob(__DIR__ . '/../Helpers/*.php') as $filename) {
require_once $filename;
}
}
/**
/**
* Dynamically Register Commands.
*
* @return void
*/
public function registerCommands(): void
{
if (!$this->app->runningInConsole()) {
return;
}
$commandPath = __DIR__ . '/../Console';
$commands = collect(File::allFiles($commandPath))
->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class;
})
->filter(function ($class) {
return class_exists($class);
})
->values()
->all();
$this->commands($commands);
{
if (! $this->app->runningInConsole()) {
return;
}
$commandPath = __DIR__ . '/../Console';
$commands = collect(File::allFiles($commandPath))
->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class;
})
->filter(function ($class) {
return class_exists($class);
})
->values()
->all();
$this->commands($commands);
}
/**
* Register config.
@@ -100,10 +99,11 @@ class M3ServiceProvider extends ServiceProvider
protected function registerConfig(): void
{
$this->publishes([
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');
$this->mergeConfigFrom(
module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower()
module_path(ModuleInfo::name(), 'Config/config.php'),
ModuleInfo::nameLower(),
);
}
@@ -117,9 +117,9 @@ class M3ServiceProvider extends ServiceProvider
$viewPath = resource_path('views/modules/' . ModuleInfo::nameLower());
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
$this->publishes([
$sourcePath => $viewPath
$sourcePath => $viewPath,
], ['views', ModuleInfo::nameLower() . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
}
/**
@@ -129,10 +129,10 @@ class M3ServiceProvider extends ServiceProvider
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/' . ModuleInfo::nameLower());
$langPath = resource_path('lang/modules/' . ModuleInfo::nameLower());
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
} else {
$this->loadTranslationsFrom(module_path(ModuleInfo::name(), 'Resources/lang'), ModuleInfo::nameLower());
}
@@ -140,6 +140,7 @@ class M3ServiceProvider extends ServiceProvider
/**
* Regsiter View Paths
*
* @return array
*/
private function getPublishableViewPaths(): array
@@ -150,6 +151,7 @@ class M3ServiceProvider extends ServiceProvider
$paths[] = $path . '/modules/' . ModuleInfo::nameLower();
}
}
return $paths;
}
}
@@ -2,8 +2,8 @@
namespace Modules\M3\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
+1 -1
View File
@@ -15,4 +15,4 @@ use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/m3', function (Request $request) {
return $request->user();
});
});
+1 -1
View File
@@ -11,6 +11,6 @@
|
*/
Route::prefix('m3')->group(function() {
Route::prefix('m3')->group(function () {
Route::get('/', 'M3Controller@index');
});
+3 -1
View File
@@ -4,10 +4,11 @@ namespace Modules\M3\Support;
class ModuleInfo
{
protected static string $moduleName = 'M3';
protected static string $moduleName = 'M3';
/**
* defines the Module Name
*
* @return string
*/
public static function name(): string
@@ -17,6 +18,7 @@ class ModuleInfo
/**
* define the lowercase version
*
* @return string
*/
public static function nameLower(): string
+2 -3
View File
@@ -2,7 +2,6 @@
return [
'name' => 'OTM',
'features' =>
[
],
'features' => [
],
];
@@ -2,8 +2,8 @@
namespace Modules\OTM\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class OTMDatabaseSeeder extends Seeder
{
+2 -1
View File
@@ -1,4 +1,5 @@
<?php
use Modules\OTM\Support\ModuleInfo;
if (! function_exists('otm_feature_enabled')) {
@@ -7,6 +8,6 @@ if (! function_exists('otm_feature_enabled')) {
*/
function otm_feature_enabled(string $key): bool
{
return (bool) config(ModuleInfo::nameLower().".features.{$key}", false);
return (bool) config(ModuleInfo::nameLower() . ".features.{$key}", false);
}
}
+13 -1
View File
@@ -10,6 +10,7 @@ class OTMController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Renderable
*/
public function index()
@@ -19,6 +20,7 @@ class OTMController extends Controller
/**
* Show the form for creating a new resource.
*
* @return Renderable
*/
public function create()
@@ -28,7 +30,9 @@ class OTMController extends Controller
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return Renderable
*/
public function store(Request $request)
@@ -38,7 +42,9 @@ class OTMController extends Controller
/**
* Show the specified resource.
*
* @param int $id
*
* @return Renderable
*/
public function show($id)
@@ -48,7 +54,9 @@ class OTMController extends Controller
/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return Renderable
*/
public function edit($id)
@@ -58,8 +66,10 @@ class OTMController extends Controller
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @param int $id
*
* @return Renderable
*/
public function update(Request $request, $id)
@@ -69,7 +79,9 @@ class OTMController extends Controller
/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return Renderable
*/
public function destroy($id)
+40 -38
View File
@@ -2,31 +2,29 @@
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 Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
use Modules\OTM\Support\ModuleInfo;
class OTMServiceProvider extends ServiceProvider
{
/**
* @var string $moduleName
* @var string
*/
protected string $moduleName = 'OTM';
/**
* @var string $moduleNameLower
* @var string
*/
protected string $moduleNameLower = 'otm';
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides():array
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides(): array
{
return [];
}
@@ -36,7 +34,7 @@ class OTMServiceProvider extends ServiceProvider
*
* @return void
*/
public function boot() : void
public function boot(): void
{
$this->registerTranslations();
$this->registerConfig();
@@ -63,34 +61,35 @@ class OTMServiceProvider extends ServiceProvider
*/
protected function registerHelpers(): void
{
foreach (glob(__DIR__.'/../Helpers/*.php') as $filename) {
foreach (glob(__DIR__ . '/../Helpers/*.php') as $filename) {
require_once $filename;
}
}
/**
/**
* Dynamically Register Commands.
*
* @return void
*/
public function registerCommands(): void
{
if (!$this->app->runningInConsole()) {
return;
}
$commandPath = __DIR__ . '/../Console';
$commands = collect(File::allFiles($commandPath))
->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class;
})
->filter(function ($class) {
return class_exists($class);
})
->values()
->all();
$this->commands($commands);
{
if (! $this->app->runningInConsole()) {
return;
}
$commandPath = __DIR__ . '/../Console';
$commands = collect(File::allFiles($commandPath))
->map(function ($file) {
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
return $class;
})
->filter(function ($class) {
return class_exists($class);
})
->values()
->all();
$this->commands($commands);
}
/**
* Register config.
@@ -100,10 +99,11 @@ class OTMServiceProvider extends ServiceProvider
protected function registerConfig(): void
{
$this->publishes([
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');
$this->mergeConfigFrom(
module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower()
module_path(ModuleInfo::name(), 'Config/config.php'),
ModuleInfo::nameLower(),
);
}
@@ -117,9 +117,9 @@ class OTMServiceProvider extends ServiceProvider
$viewPath = resource_path('views/modules/' . ModuleInfo::nameLower());
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
$this->publishes([
$sourcePath => $viewPath
$sourcePath => $viewPath,
], ['views', ModuleInfo::nameLower() . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
}
/**
@@ -129,10 +129,10 @@ class OTMServiceProvider extends ServiceProvider
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/' . ModuleInfo::nameLower());
$langPath = resource_path('lang/modules/' . ModuleInfo::nameLower());
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
} else {
$this->loadTranslationsFrom(module_path(ModuleInfo::name(), 'Resources/lang'), ModuleInfo::nameLower());
}
@@ -140,6 +140,7 @@ class OTMServiceProvider extends ServiceProvider
/**
* Regsiter View Paths
*
* @return array
*/
private function getPublishableViewPaths(): array
@@ -150,6 +151,7 @@ class OTMServiceProvider extends ServiceProvider
$paths[] = $path . '/modules/' . ModuleInfo::nameLower();
}
}
return $paths;
}
}
@@ -2,8 +2,8 @@
namespace Modules\OTM\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
+1 -1
View File
@@ -15,4 +15,4 @@ use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/otm', function (Request $request) {
return $request->user();
});
});
+1 -1
View File
@@ -11,6 +11,6 @@
|
*/
Route::prefix('otm')->group(function() {
Route::prefix('otm')->group(function () {
Route::get('/', 'OTMController@index');
});
+3 -1
View File
@@ -4,10 +4,11 @@ namespace Modules\OTM\Support;
class ModuleInfo
{
protected static string $moduleName = 'OTM';
protected static string $moduleName = 'OTM';
/**
* defines the Module Name
*
* @return string
*/
public static function name(): string
@@ -17,6 +18,7 @@ class ModuleInfo
/**
* define the lowercase version
*
* @return string
*/
public static function nameLower(): string
+51 -51
View File
@@ -40,11 +40,11 @@ class DatabaseStage extends Command
];
foreach ([
'STAGE_SSH_HOST' => $stage['ssh_host'],
'STAGE_SSH_USER' => $stage['ssh_user'],
'STAGE_DB_DATABASE' => $stage['database'],
'STAGE_DB_USERNAME' => $stage['username'],
] as $name => $value) {
'STAGE_SSH_HOST' => $stage['ssh_host'],
'STAGE_SSH_USER' => $stage['ssh_user'],
'STAGE_DB_DATABASE' => $stage['database'],
'STAGE_DB_USERNAME' => $stage['username'],
] as $name => $value) {
if (! $value) {
$this->error("Missing {$name}.");
@@ -69,14 +69,14 @@ class DatabaseStage extends Command
['Stage server', "{$stage['ssh_user']}@{$stage['ssh_host']}"],
['Stage database', $stage['database']],
['Stage owner', $stage['username']],
]
],
);
if (
! $this->option('force') &&
! $this->confirm(
"This will DROP and completely RECREATE '{$stage['database']}'. Continue?",
false
false,
)
) {
$this->warn('Cancelled.');
@@ -110,9 +110,9 @@ class DatabaseStage extends Command
'PGPASSWORD' => $local['password'],
])->timeout(3600)->run([
'pg_dump',
'--host='.$local['host'],
'--port='.$local['port'],
'--username='.$local['username'],
'--host=' . $local['host'],
'--port=' . $local['port'],
'--username=' . $local['username'],
// Custom archive format.
'--format=custom',
@@ -127,14 +127,14 @@ class DatabaseStage extends Command
'--no-acl',
// Include everything in the database.
'--file='.$localDump,
'--file=' . $localDump,
$local['database'],
]);
if ($result->failed()) {
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;
}
},
);
$dumpSize = $this->formatBytes(filesize($localDump));
@@ -167,12 +167,12 @@ class DatabaseStage extends Command
if ($result->failed()) {
throw new RuntimeException(
"Invalid PostgreSQL archive:\n".$result->errorOutput()
"Invalid PostgreSQL archive:\n" . $result->errorOutput(),
);
}
return true;
}
},
);
/*
@@ -194,12 +194,12 @@ class DatabaseStage extends Command
if ($result->failed()) {
throw new RuntimeException(
"Upload failed:\n".$result->errorOutput()
"Upload failed:\n" . $result->errorOutput(),
);
}
return true;
}
},
);
/*
@@ -220,7 +220,7 @@ class DatabaseStage extends Command
$terminateDatabase = str_replace(
"'",
"''",
$stage['database']
$stage['database'],
);
$sql = <<<SQL
@@ -238,7 +238,7 @@ SQL;
$remoteCommand = sprintf(
'sudo -u %s psql --set ON_ERROR_STOP=on --dbname=postgres',
escapeshellarg($stage['admin_username'])
escapeshellarg($stage['admin_username']),
);
$result = Process::input($sql)
@@ -253,13 +253,13 @@ SQL;
if ($result->failed()) {
throw new RuntimeException(
"Unable to recreate stage database:\n".
$result->errorOutput()
"Unable to recreate stage database:\n" .
$result->errorOutput(),
);
}
return true;
}
},
);
/*
@@ -272,15 +272,15 @@ SQL;
'Restoring complete stage database',
function () use ($stage, $remoteDump) {
$restore = sprintf(
'PGPASSWORD=%s pg_restore '.
'--host=%s '.
'--port=%s '.
'--username=%s '.
'--dbname=%s '.
'--no-owner '.
'--no-acl '.
'--exit-on-error '.
'--verbose '.
'PGPASSWORD=%s pg_restore ' .
'--host=%s ' .
'--port=%s ' .
'--username=%s ' .
'--dbname=%s ' .
'--no-owner ' .
'--no-acl ' .
'--exit-on-error ' .
'--verbose ' .
'%s',
escapeshellarg($stage['password']),
escapeshellarg($stage['db_host']),
@@ -300,13 +300,13 @@ SQL;
if ($result->failed()) {
throw new RuntimeException(
"Database restore failed:\n".
$result->errorOutput()
"Database restore failed:\n" .
$result->errorOutput(),
);
}
return true;
}
},
);
/*
@@ -319,12 +319,12 @@ SQL;
'Verifying restored database',
function () use ($stage) {
$command = sprintf(
'PGPASSWORD=%s psql '.
'--host=%s '.
'--port=%s '.
'--username=%s '.
'--dbname=%s '.
'--tuples-only '.
'PGPASSWORD=%s psql ' .
'--host=%s ' .
'--port=%s ' .
'--username=%s ' .
'--dbname=%s ' .
'--tuples-only ' .
'--command=%s',
escapeshellarg($stage['password']),
escapeshellarg($stage['db_host']),
@@ -332,7 +332,7 @@ SQL;
escapeshellarg($stage['username']),
escapeshellarg($stage['database']),
escapeshellarg(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';"
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public';",
),
);
@@ -346,8 +346,8 @@ SQL;
if ($result->failed()) {
throw new RuntimeException(
"Database verification failed:\n".
$result->errorOutput()
"Database verification failed:\n" .
$result->errorOutput(),
);
}
@@ -356,7 +356,7 @@ SQL;
$this->line(" Stage public tables: {$count}");
return true;
}
},
);
/*
@@ -381,11 +381,11 @@ SQL;
$this->newLine();
$this->components->info(
'Stage PostgreSQL database cloned successfully.'
'Stage PostgreSQL database cloned successfully.',
);
$this->line(
"Local {$local['database']} → Stage {$stage['database']}"
"Local {$local['database']} → Stage {$stage['database']}",
);
return self::SUCCESS;
@@ -396,7 +396,7 @@ SQL;
$this->newLine();
$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;
@@ -405,7 +405,7 @@ SQL;
private function quoteSqlIdentifier(string $identifier): string
{
return '"'.str_replace('"', '""', $identifier).'"';
return '"' . str_replace('"', '""', $identifier) . '"';
}
private function formatBytes(int $bytes): string
@@ -418,8 +418,8 @@ SQL;
: 0;
return number_format(
$bytes / (1024 ** $power),
$power === 0 ? 0 : 2
).' '.$units[$power];
$bytes / (1024 ** $power),
$power === 0 ? 0 : 2,
) . ' ' . $units[$power];
}
}
+14 -14
View File
@@ -41,31 +41,31 @@ host('stage')
*/
task('build', function (): void {
$node = 'export NVM_DIR="$HOME/.nvm"'
.' && [ -s "$NVM_DIR/nvm.sh" ]'
.' && . "$NVM_DIR/nvm.sh"'
.' && nvm use {{node_version}}';
. ' && [ -s "$NVM_DIR/nvm.sh" ]'
. ' && . "$NVM_DIR/nvm.sh"'
. ' && nvm use {{node_version}}';
run(
$node
.' && cd {{release_path}}'
.' && npm ci --no-audit --no-fund'
. ' && cd {{release_path}}'
. ' && npm ci --no-audit --no-fund',
);
run(
$node
.' && cd {{release_path}}'
.' && for lock in Modules/*/package-lock.json; do'
.' [ -f "$lock" ] || continue;'
.' module_dir="$(dirname "$lock")";'
.' echo "[Modules] npm ci: $module_dir";'
.' (cd "$module_dir" && npm ci --no-audit --no-fund);'
.' done'
. ' && cd {{release_path}}'
. ' && for lock in Modules/*/package-lock.json; do'
. ' [ -f "$lock" ] || continue;'
. ' module_dir="$(dirname "$lock")";'
. ' echo "[Modules] npm ci: $module_dir";'
. ' (cd "$module_dir" && npm ci --no-audit --no-fund);'
. ' done',
);
run(
$node
.' && cd {{release_path}}'
.' && npm run build'
. ' && cd {{release_path}}'
. ' && npm run build',
);
});