Skip to content

Commit

Permalink
Merge pull request #98 from AkrilliA/feature/add-windows-tests
Browse files Browse the repository at this point in the history
Feature/add windows tests
  • Loading branch information
regnerisch authored Nov 29, 2023
2 parents 89869a8 + d810bf7 commit 21153b5
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, windows-latest]
php: ['8.1', '8.2']

steps:
Expand All @@ -18,6 +18,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: fileinfo
tools: composer:v2
coverage: none

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
],
"require": {
"php": "^8.1",
"ext-fileinfo": "^8.1",
"illuminate/support": "^10.0",
"illuminate/console": "^10.0",
"illuminate/filesystem": "^10.0"
Expand Down
4 changes: 2 additions & 2 deletions src/Actions/CopyAndRefactorDirectoryAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function execute(string $sourcePath, string $targetPath, array $refactor

foreach ($files as $file) {
$this->copyAndRefactorFileAction->execute(
$sourcePath.'/'.$file->getFilename(),
$targetPath.'/'.$file->getFilename(),
beyond_os_aware_path($sourcePath.'/'.$file->getFilename()),
beyond_os_aware_path($targetPath.'/'.$file->getFilename()),
$refactor,
$force
);
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/CreateDirectoryAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function execute(string|array $directory): void
return;
}

(new Filesystem())->ensureDirectoryExists(base_path()."/modules/$directory");
(new Filesystem())->ensureDirectoryExists(beyond_os_aware_path(base_path()."/modules/$directory"));
}
}
2 changes: 1 addition & 1 deletion src/Commands/Abstracts/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ public function handle(): void

public function getTypeName(): string
{
return Str::afterLast($this->getType(), '/');
return Str::afterLast($this->getType(), DIRECTORY_SEPARATOR);
}
}
2 changes: 1 addition & 1 deletion src/Commands/MakeMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getStub(): string

public function getType(): string
{
return 'Database/Migration';
return beyond_os_aware_path('Database/Migration');
}

public function getFileNameTemplate(): string
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/MakeModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function setup(NameResolver $nameResolver): void

beyond_copy_stub(
'migration.create.stub',
base_path()."/modules/$module/Infrastructure/Database/Migrations/$fileName.php",
beyond_os_aware_path(base_path()."/modules/$module/Infrastructure/Database/Migrations/$fileName.php"),
[
'{{ table }}' => $tableName,
],
Expand All @@ -48,7 +48,7 @@ public function setup(NameResolver $nameResolver): void

beyond_copy_stub(
'factory.stub',
base_path()."/modules/$module/Infrastructure/factories/$fileName.php",
beyond_os_aware_path(base_path()."/modules/$module/Infrastructure/factories/$fileName.php"),
[
'{{ namespace }}' => $namespace,
'{{ model }}' => $fileName,
Expand Down
16 changes: 8 additions & 8 deletions src/Commands/MakeModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle(): void
$full = (bool) $this->option('full');

$this->copyDirectoryAction->execute(
__DIR__.'/../../stubs/Module',
beyond_os_aware_path(__DIR__.'/../../stubs/Module'),
beyond_modules_path($module),
$force,
);
Expand All @@ -44,17 +44,17 @@ public function handle(): void
private function moveAndRefactorModuleFiles(string $module, bool $force = false): void
{
$files = [
'Providers/ModuleAuthServiceProvider.stub' => "Providers/{$module}AuthServiceProvider.php",
'Providers/ModuleEventServiceProvider.stub' => "Providers/{$module}EventServiceProvider.php",
'Providers/ModuleRouteServiceProvider.stub' => "Providers/{$module}RouteServiceProvider.php",
'Providers/ModuleServiceProvider.stub' => "Providers/{$module}ServiceProvider.php",
'App/routes.stub' => 'App/routes.php',
beyond_os_aware_path('Providers/ModuleAuthServiceProvider.stub') => beyond_os_aware_path("Providers/{$module}AuthServiceProvider.php"),
beyond_os_aware_path('Providers/ModuleEventServiceProvider.stub') => beyond_os_aware_path("Providers/{$module}EventServiceProvider.php"),
beyond_os_aware_path('Providers/ModuleRouteServiceProvider.stub') => beyond_os_aware_path("Providers/{$module}RouteServiceProvider.php"),
beyond_os_aware_path('Providers/ModuleServiceProvider.stub' ) => beyond_os_aware_path("Providers/{$module}ServiceProvider.php"),
beyond_os_aware_path('App/routes.stub') => beyond_os_aware_path('App/routes.php'),
];

foreach ($files as $from => $to) {
$this->moveAndRefactorFileAction->execute(
beyond_modules_path("{$module}/{$from}"),
beyond_modules_path("{$module}/{$to}"),
beyond_modules_path("$module/$from"),
beyond_modules_path("$module/$to"),
[
'{{ module }}' => $module,
],
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelBeyondServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function beyondCommands(): array
$exclude = [];

$fs = new Filesystem();
$files = $fs->files(__DIR__.'/Commands');
$files = $fs->files(beyond_os_aware_path(__DIR__.'/Commands'));

return array_map(
fn ($file) => 'AkrilliA\\LaravelBeyond\\Commands\\'.$file->getBasename('.php'),
Expand Down
22 changes: 12 additions & 10 deletions src/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getPath(): string

public function getCommandNameArgument(): string
{
return $this->module.'.'.$this->className;
return $this->module . '.' . $this->className;
}

private function init(): void
Expand All @@ -59,15 +59,15 @@ private function init(): void

if (1 === $numParts) {
$this->module = $this->command->choice(
'On which module should we create your '.Str::studly($this->command->getTypeName()).'?',
'On which module should we create your ' . Str::studly($this->command->getTypeName()) . '?',
$modules,
attempts: 2
);

$this->setDirectoryAndClassName($parts[0]);
} elseif (2 === $numParts) {
$module = Str::of($parts[0])->ucfirst()->value();
if (! in_array($module, $modules, true)) {
if (!in_array($module, $modules, true)) {
throw new ModuleDoesNotExistsException($module);
}

Expand All @@ -78,16 +78,18 @@ private function init(): void
}

$this->namespace = sprintf(
$this->command->getNamespaceTemplate().'%s',
$this->command->getNamespaceTemplate() . '%s',
$this->module,
Str::pluralStudly($this->command->getType()),
$this->directory ? '\\'.$this->directory : '',
$this->directory ? '\\' . $this->directory : '',
);

$this->path = sprintf(
'%s/'.$this->command->getFileNameTemplate(),
Str::lcfirst(Str::replace('\\', '/', $this->namespace)),
$this->className,
$this->path = beyond_os_aware_path(
sprintf(
'%s/' . $this->command->getFileNameTemplate(),
Str::lcfirst(Str::replace('\\', '/', $this->namespace)),
$this->className,
)
);
}

Expand All @@ -97,6 +99,6 @@ private function setDirectoryAndClassName(string $name): void

$this->className = array_pop($parts);

$this->directory = implode('/', $parts);
$this->directory = beyond_os_aware_path(implode('/', $parts));
}
}
18 changes: 14 additions & 4 deletions src/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function beyond_path(): string
if (! function_exists('beyond_modules_path')) {
function beyond_modules_path(string $path = ''): string
{
return base_path("modules/$path");
return base_path(beyond_os_aware_path("modules/$path"));
}
}

Expand All @@ -33,9 +33,9 @@ function beyond_module_name(string $name): string
*/
function beyond_copy_stub(string $stub, string $path, array $refactor = [], bool $force = false): void
{
$stub = file_exists($stubPath = base_path('stubs/beyond.'.$stub))
$stub = file_exists($stubPath = base_path(beyond_os_aware_path('stubs/beyond.'.$stub)))
? $stubPath
: beyond_path().'/stubs/'.$stub;
: beyond_os_aware_path(beyond_path().'/stubs/'.$stub);

$action = new CopyAndRefactorFileAction(
new CopyFileAction(),
Expand Down Expand Up @@ -63,11 +63,21 @@ function beyond_get_choices(string $path): array

$directories = array_map(
function ($directory) {
return last(explode('/', $directory));
return last(explode(DIRECTORY_SEPARATOR, $directory));
},
$fs->directories($path)
);

return $directories;
}
}

if (! function_exists('beyond_os_aware_path')) {
/**
* @return string
*/
function beyond_os_aware_path(string $path): string
{
return Str::of($path)->replace('/', DIRECTORY_SEPARATOR)->value();
}
}

0 comments on commit 21153b5

Please sign in to comment.