Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Dec 27, 2023
1 parent 14289d2 commit fe457bb
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 33 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
"composer/semver": "^3.0",
"illuminate/console": "^10.38.1",
"illuminate/database": "^10.38.1",
"illuminate/filesystem": "^10.38.1",
"illuminate/support": "^10.38.1",
"orchestra/canvas-core": "^8.10.1",
"orchestra/testbench-core": "^8.18",
"orchestra/testbench-core": "^8.19",
"symfony/polyfill-php83": "^1.28",
"symfony/yaml": "^6.2"
},
Expand Down
6 changes: 4 additions & 2 deletions src/CanvasServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Orchestra\Canvas\Core\PresetManager;
use Symfony\Component\Yaml\Yaml;

use function Illuminate\Filesystem\join_paths;

class CanvasServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
Expand All @@ -33,8 +35,8 @@ public function register(): void

$config = ['preset' => 'laravel'];

if (file_exists($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml')) {
$config = Yaml::parseFile($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml');
if (file_exists(join_paths($workingPath, 'canvas.yaml'))) {
$config = Yaml::parseFile(join_paths($workingPath, 'canvas.yaml'));
} else {
Arr::set($config, 'testing.extends', [
'unit' => 'PHPUnit\Framework\TestCase',
Expand Down
6 changes: 4 additions & 2 deletions src/Console/CodeMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

use function Illuminate\Filesystem\join_paths;

#[AsCommand(name: 'make:class', description: 'Create a new class')]
class CodeMakeCommand extends GeneratorCommand
{
Expand All @@ -24,7 +26,7 @@ class CodeMakeCommand extends GeneratorCommand
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/class.stub');
return $this->resolveStubPath(join_paths('stubs', 'class.stub'));
}

/**
Expand All @@ -35,7 +37,7 @@ protected function getStub()
*/
protected function resolveDefaultStubPath($stub)
{
return __DIR__.$stub;
return join_paths(__DIR__, $stub);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Console/FactoryMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
use Symfony\Component\Console\Attribute\AsCommand;

use function Illuminate\Filesystem\join_paths;

/**
* @see https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php
*/
Expand Down Expand Up @@ -51,7 +53,7 @@ public function handle()
*/
protected function resolveDefaultStubPath($stub)
{
return __DIR__.$stub;
return join_paths(__DIR__, $stub);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Console/GeneratorMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

use function Illuminate\Filesystem\join_paths;

#[AsCommand(name: 'make:generator', description: 'Create a new generator command')]
class GeneratorMakeCommand extends GeneratorCommand
{
Expand Down Expand Up @@ -46,7 +48,7 @@ protected function replaceClass($stub, $name)
#[\Override]
protected function getStub()
{
return $this->resolveStubPath('/stubs/generator.stub');
return $this->resolveStubPath(join_paths('stubs', 'generator.stub'));
}

/**
Expand All @@ -57,7 +59,7 @@ protected function getStub()
*/
protected function resolveDefaultStubPath($stub)
{
return __DIR__.$stub;
return join_paths(__DIR__, $stub);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Console/PresetMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

use function Illuminate\Filesystem\join_paths;

#[AsCommand(name: 'preset', description: 'Create canvas.yaml for the project')]
class PresetMakeCommand extends GeneratorCommand
{
Expand All @@ -29,7 +31,7 @@ protected function getStub()
{
$name = Str::lower($this->getNameInput());

$stub = __DIR__.'/stubs/preset';
$stub = join_paths(__DIR__, 'stubs', 'preset');

return $this->files->exists("{$stub}.{$name}.stub")
? "{$stub}.{$name}.stub"
Expand All @@ -45,7 +47,7 @@ protected function getStub()
#[\Override]
protected function getPath($name)
{
return $this->generatorPreset()->basePath().'/canvas.yaml';
return join_paths($this->generatorPreset()->basePath(), 'canvas.yaml');
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Console/TestMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Orchestra\Canvas\GeneratorPreset;
use Symfony\Component\Console\Attribute\AsCommand;

use function Illuminate\Filesystem\join_paths;

/**
* @see https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Console/TestMakeCommand.php
*/
Expand Down Expand Up @@ -104,7 +106,7 @@ protected function resolveStubPath($stub)
return parent::resolveStubPath($stub);
}

return $preset->hasCustomStubPath() && file_exists($customPath = implode('/', [$preset->basePath(), trim($stub, '/')]))
return $preset->hasCustomStubPath() && file_exists($customPath = join_paths($preset->basePath(), $stub))
? $customPath
: $this->resolveDefaultStubPath($stub);
}
Expand All @@ -117,7 +119,7 @@ protected function resolveStubPath($stub)
*/
protected function resolveDefaultStubPath($stub)
{
return __DIR__.$stub;
return join_paths(__DIR__, $stub);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Console/UserFactoryMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

use function Illuminate\Filesystem\join_paths;

#[AsCommand(name: 'make:user-factory', description: 'Create the User factory class')]
class UserFactoryMakeCommand extends GeneratorCommand
{
Expand All @@ -26,7 +28,7 @@ class UserFactoryMakeCommand extends GeneratorCommand
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/user-factory.stub');
return $this->resolveStubPath(join_paths('stubs', 'user-factory.stub'));
}

/**
Expand All @@ -37,7 +39,7 @@ protected function getStub()
*/
protected function resolveDefaultStubPath($stub)
{
return __DIR__.$stub;
return join_paths(__DIR__, $stub);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Console/UserModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

use function Illuminate\Filesystem\join_paths;

#[AsCommand(name: 'make:user-model', description: 'Create the User model class')]
class UserModelMakeCommand extends GeneratorCommand
{
Expand All @@ -26,7 +28,7 @@ class UserModelMakeCommand extends GeneratorCommand
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/user-model.stub');
return $this->resolveStubPath(join_paths('stubs', 'user-model.stub'));
}

/**
Expand All @@ -37,7 +39,7 @@ protected function getStub()
*/
protected function resolveDefaultStubPath($stub)
{
return __DIR__.$stub;
return join_paths(__DIR__, $stub);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Console/ViewMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Orchestra\Canvas\GeneratorPreset;
use Symfony\Component\Console\Attribute\AsCommand;

use function Illuminate\Filesystem\join_paths;

#[AsCommand(name: 'make:view', description: 'Create a new view')]
class ViewMakeCommand extends \Illuminate\Foundation\Console\ViewMakeCommand
{
Expand Down Expand Up @@ -58,7 +60,7 @@ protected function resolveStubPath($stub)
return parent::resolveStubPath($stub);
}

return $preset->hasCustomStubPath() && file_exists($customPath = implode('/', [$preset->basePath(), trim($stub, '/')]))
return $preset->hasCustomStubPath() && file_exists($customPath = join_paths($preset->basePath(), $stub))
? $customPath
: $this->resolveDefaultStubPath($stub);
}
Expand All @@ -71,7 +73,7 @@ protected function resolveStubPath($stub)
*/
protected function resolveDefaultStubPath($stub)
{
return __DIR__.$stub;
return join_paths(__DIR__, $stub);
}

/**
Expand Down Expand Up @@ -185,6 +187,6 @@ protected function getTestStub()
{
$stubName = 'view.'.($this->option('pest') ? 'pest' : 'test').'.stub';

return $this->resolveStubPath("/stubs/{$stubName}");
return $this->resolveStubPath(join_paths('stubs', $stubName));
}
}
4 changes: 3 additions & 1 deletion src/GeneratorPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Orchestra\Canvas\Core\Presets\Preset;

use function Illuminate\Filesystem\join_paths;

class GeneratorPreset extends Preset
{
/**
Expand Down Expand Up @@ -63,7 +65,7 @@ public function resourcePath()
*/
public function viewPath()
{
return implode('/', [$this->resourcePath(), 'views']);
return join_paths($this->resourcePath(), 'views');
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Presets/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Orchestra\Canvas\Presets;

use function Illuminate\Filesystem\join_paths;

class Laravel extends Preset
{
/**
Expand All @@ -17,7 +19,7 @@ public function name(): string
*/
public function sourcePath(): string
{
return implode('/', [$this->basePath(), $this->config('paths.src', 'app')]);
return join_paths($this->basePath(), $this->config('paths.src', 'app'));
}

/**
Expand Down Expand Up @@ -67,6 +69,6 @@ public function testingNamespace(): string
*/
public function getCustomStubPath(): ?string
{
return sprintf('%s/%s', $this->basePath(), 'stubs');
return join_paths($this->basePath(), 'stubs');
}
}
5 changes: 3 additions & 2 deletions src/Presets/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use InvalidArgumentException;

use function Illuminate\Filesystem\join_paths;

class Package extends Preset
{
/**
Expand All @@ -19,8 +21,7 @@ public function name(): string
*/
public function sourcePath(): string
{
return sprintf(
'%s/%s',
return join_paths(
$this->basePath(),
$this->config('paths.src', 'src')
);
Expand Down
16 changes: 7 additions & 9 deletions src/Presets/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\Arr;

use function Illuminate\Filesystem\join_paths;

abstract class Preset
{
/**
Expand Down Expand Up @@ -53,16 +55,15 @@ public function basePath(): string
*/
public function testingPath(): string
{
return "{$this->basePath}/tests";
return join_paths($this->basePath, 'tests');
}

/**
* Get the path to the resource directory.
*/
public function resourcePath(): string
{
return sprintf(
'%s/%s',
return join_paths(
$this->basePath(),
$this->config('paths.resource', 'resources')
);
Expand All @@ -73,8 +74,7 @@ public function resourcePath(): string
*/
public function factoryPath(): string
{
return sprintf(
'%s/%s',
return join_paths(
$this->basePath(),
$this->config('factory.path', 'database/factories')
);
Expand All @@ -85,8 +85,7 @@ public function factoryPath(): string
*/
public function migrationPath(): string
{
return sprintf(
'%s/%s',
return join_paths(
$this->basePath(),
$this->config('migration.path', 'database/migrations')
);
Expand All @@ -97,8 +96,7 @@ public function migrationPath(): string
*/
public function seederPath(): string
{
return sprintf(
'%s/%s',
return join_paths(
$this->basePath(),
$this->config('seeder.path', 'database/seeders')
);
Expand Down

0 comments on commit fe457bb

Please sign in to comment.