Skip to content

Commit

Permalink
Merge branch '8.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Oct 9, 2023
2 parents 7cbf8ef + 397880c commit cf266cd
Show file tree
Hide file tree
Showing 72 changed files with 1,389 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Ignore following folder/file.
/.github export-ignore
/bin export-ignore
/tests export-ignore
/workbench export-ignore
/.gitattributes export-ignore
Expand All @@ -11,7 +12,6 @@
/phpstan-baseline.neon export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml export-ignore
/sync.sh export-ignore
/testbench.yaml export-ignore
/CHANGELOG-*.md export-ignore
/CODE_OF_CONDUCT.md export-ignore
Expand Down
4 changes: 2 additions & 2 deletions .github/FUNDING.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: crynobone
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand All @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: crynobone
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ["https://paypal.me/crynobone"]
custom: # ["https://paypal.me/crynobone"]
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- "windows-latest"
php:
- 8.2
- 8.3
dependencies:
- "highest"
- "lowest"
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/update-stubs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "update-stubs"

on:
workflow_dispatch:

jobs:
update:
name: Update Stubs

runs-on: ubuntu-latest
continue-on-error: false

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress

- name: Installed dependencies
run: composer show -D

- name: Sync changes
run: |
php bin/sync
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update Stubs

16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Code Generators for Laravel Applications and Packages
**Canvas** replicates all of the `make` artisan commands available in your basic Laravel application. It allows everyone to use it:

* outside of Laravel installation such as when building Laravel packages.
* with Laravel by allowing few customization to the stub resolved class and namespace.
* with Laravel by allowing a few customizations to the stub resolved class and namespace.

[![tests](https://github.com/orchestral/canvas/workflows/tests/badge.svg?branch=8.x)](https://github.com/orchestral/canvas/actions?query=workflow%3Atests+branch%3A8.x)
[![Latest Stable Version](https://poser.pugx.org/orchestra/canvas/v/stable)](https://packagist.org/packages/orchestra/canvas)
Expand All @@ -15,7 +15,7 @@ Code Generators for Laravel Applications and Packages

## Installation

To install through composer, run the following command from terminal:
To install through composer, run the following command from the terminal:

composer require --dev "orchestra/canvas"

Expand Down Expand Up @@ -47,13 +47,13 @@ As a Laravel developer, you should be familiar with the following commands:
| `make:seeder` | Create a new seeder class |
| `make:test` | Create a new test class |

Which can be execute via:
Which can be executed via:

php artisan make:migration CreatePostsTable --create

With **Canvas**, you can run the equivalent command via:

composer exec canvas make:migration CreatePostsTable -- --create
vendor/bin/canvas make:migration CreatePostsTable --create

### `canvas.yaml` Preset file

Expand All @@ -63,7 +63,7 @@ To get started you can first create `canvas.yaml` in the root directory of your

You can run the following command to create the file:

composer exec canvas preset laravel
vendor/bin/canvas preset laravel

Which will output the following as `canvas.yaml`:

Expand All @@ -80,7 +80,7 @@ model:
You can run the following command to create the file:
composer exec canvas preset package
vendor/bin/canvas preset package
Which will output the following as `canvas.yaml`:

Expand Down Expand Up @@ -119,7 +119,7 @@ testing:

Alternatively, you can set `--namespace` option to ensure the namespace is used in the file:

./vendor/bin/canvas preset package --namespace="Foo\Bar"
vendor/bin/canvas preset package --namespace="Foo\Bar"

```yaml
preset: package
Expand Down Expand Up @@ -153,4 +153,4 @@ testing:

### Integration with Laravel

By default, you can always use `composer exec canvas` for Laravel and Packages environment. However, with the Package Discovery `Orchestra\Canvas\LaravelServiceProvider` will be installed automatically and override all default `make` command available via artisan so you can use it without changing anything.
By default, you can always use `composer exec canvas` for Laravel and Packages environment. However, with the Package Discovery `Orchestra\Canvas\LaravelServiceProvider` will be installed automatically and override all default `make` commands available via artisan so you can use it without changing anything.
95 changes: 95 additions & 0 deletions bin/sync
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env php
<?php

$workingPath = getcwd();

require __DIR__.'/../vendor/autoload.php';

$input = new Symfony\Component\Console\Input\ArgvInput();
$files = new Illuminate\Filesystem\Filesystem();

$version = ($input->hasParameterOption('--dev') && $input->hasParameterOption('--stable') === false) ? '10.x-dev' : '^10.0';

Illuminate\Support\Collection::make([
'factory.stub' => 'Database/Console/Factories/stubs/factory.stub',
'pest.stub' => 'Foundation/Console/stubs/pest.stub',
'pest.unit.stub' => 'Foundation/Console/stubs/pest.unit.stub',
'test.stub' => 'Foundation/Console/stubs/test.stub',
'test.unit.stub' => 'Foundation/Console/stubs/test.unit.stub',
'view.stub' => 'Foundation/Console/stubs/view.stub',
'view.test.stub' => 'Foundation/Console/stubs/view.test.stub',
])->transform(fn ($file) => "{$workingPath}/vendor/laravel/framework/src/Illuminate/{$file}")
->each(function ($file, $name) use ($files, $workingPath) {
$files->copy($file, "{$workingPath}/src/Console/stubs/{$name}");
});

transform([
'use Illuminate\Database\Eloquent\Factories\Factory;' => 'use Illuminate\Database\Eloquent\Factories\Factory;'.PHP_EOL.'use {{ namespacedModel }};',
' * @extends \Illuminate\Database\Eloquent\Factories\Factory<\{{ namespacedModel }}>' => ' * @template TModel of \{{ namespacedModel }}
*
* @extends \Illuminate\Database\Eloquent\Factories\Factory<TModel>',
' /**
* Define the model\'s default state.'.PHP_EOL => ' /**
* The name of the factory\'s corresponding model.
*
* @var class-string<TModel>
*/
protected $model = {{ model }}::class;
/**
* Define the model\'s default state.'.PHP_EOL,
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/factory.stub"));

transform([
'use Tests\TestCase;' => 'use NamespacedDummyTestCase;',
'class {{ class }} extends TestCase' => 'class {{ class }} extends DummyTestCase',
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/test.stub"));

transform([
'use PHPUnit\Framework\TestCase;' => 'use NamespacedDummyTestCase;',
'class {{ class }} extends TestCase' => 'class {{ class }} extends DummyTestCase',
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/test.unit.stub"));

transform([
'use Tests\TestCase;' => 'use NamespacedDummyTestCase;'.PHP_EOL.'use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;',
'class {{ class }} extends TestCase'.PHP_EOL.'{' => 'class {{ class }} extends DummyTestCase'.PHP_EOL.'{'.PHP_EOL.' use InteractsWithViews;'.PHP_EOL,
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/view.test.stub"));

if ($files->isDirectory("{$workingPath}/vendor/laravel/framework/tests")) {
Illuminate\Support\Collection::make([
...$files->glob("{$workingPath}/vendor/laravel/framework/tests/Integration/Generators/*.php")
])->flatten()
->each(function ($file) use ($files, $workingPath) {
$files->copy($file, "{$workingPath}/workbench/tests/".basename($file));
});
}

$files->deleteDirectory("{$workingPath}/skeleton");

Symfony\Component\Process\Process::fromShellCommandline(
'composer create-project "laravel/laravel:'.$version.'" skeleton --no-install --no-scripts --no-plugins --quiet', $workingPath
)->mustRun();

$files->copy("{$workingPath}/skeleton/app/Models/User.php", "{$workingPath}/src/Console/stubs/user-model.stub");
transform([
'namespace App\Models;' => 'namespace {{ namespace }};',
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/user-model.stub"));

$files->copy("{$workingPath}/skeleton/database/factories/UserFactory.php", "{$workingPath}/src/Console/stubs/user-factory.stub");
transform([
'namespace Database\Factories;' => 'namespace {{ factoryNamespace }};',
'use Illuminate\Support\Str;'.PHP_EOL => 'use Illuminate\Support\Str;'.PHP_EOL.'use {{ namespacedModel }};'.PHP_EOL,
'\Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>' => '\Illuminate\Database\Eloquent\Factories\Factory<\{{ namespacedModel }}>',
' /**
* Define the model\'s default state.' => ' /**
* The name of the factory\'s corresponding model.
*
* @var string
*/
protected $model = {{ model }}::class;
/**
* Define the model\'s default state.'
], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/user-factory.stub"));

$files->deleteDirectory("{$workingPath}/skeleton");
2 changes: 1 addition & 1 deletion canvas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ paths:
src: src

console:
namespace: Orchestra\Canvas\Commands
namespace: Orchestra\Canvas\Console

provider:
namespace: Orchestra\Canvas
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"phpunit/phpunit": "^10.1"
},
"config": {
"preferred-install": {
"laravel/framework": "source",
"*": "auto"
},
"sort-packages": true
},
"extra": {
Expand Down Expand Up @@ -76,5 +80,6 @@
"@test"
]
},
"prefer-stable": true,
"minimum-stability": "dev"
}
53 changes: 53 additions & 0 deletions src/Console/BatchesTableCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Orchestra\Canvas\Console;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Composer;
use Orchestra\Canvas\Core\Concerns\MigrationGenerator;
use Symfony\Component\Console\Attribute\AsCommand;

/**
* @see https://github.com/laravel/framework/blob/9.x/src/Illuminate/Queue/Console/BatchesTableCommand.php
*/
#[AsCommand(name: 'queue:batches-table', description: 'Create a migration for the batches database table')]
class BatchesTableCommand extends \Illuminate\Queue\Console\BatchesTableCommand
{
use MigrationGenerator;

/**
* Create a new notifications table command instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param \Illuminate\Support\Composer $composer
* @return void
*/
public function __construct(Filesystem $files, Composer $composer)
{
parent::__construct($files, $composer);

Check failure on line 27 in src/Console/BatchesTableCommand.php

View workflow job for this annotation

GitHub Actions / PHP8.2 on ubuntu-latest

Method Illuminate\Console\MigrationGeneratorCommand::__construct() invoked with 2 parameters, 1 required.

$this->addGeneratorPresetOptions();
}

/**
* Create a base migration file for the table.
*
* @param string $table
* @return string
*/
protected function createBaseMigration($table)
{
return $this->createBaseMigrationUsingCanvas($table);
}

/**
* Determine whether a migration for the table already exists.
*
* @param string $table
* @return bool
*/
protected function migrationExists($table)
{
return $this->migrationExistsUsingCanvas($table);
}
}
53 changes: 53 additions & 0 deletions src/Console/CacheTableCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Orchestra\Canvas\Console;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Composer;
use Orchestra\Canvas\Core\Concerns\MigrationGenerator;
use Symfony\Component\Console\Attribute\AsCommand;

/**
* @see https://github.com/laravel/framework/blob/9.x/src/Illuminate/Cache/Console/CacheTableCommand.php
*/
#[AsCommand(name: 'cache:table', description: 'Create a migration for the cache database table')]
class CacheTableCommand extends \Illuminate\Cache\Console\CacheTableCommand
{
use MigrationGenerator;

/**
* Create a new session table command instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param \Illuminate\Support\Composer $composer
* @return void
*/
public function __construct(Filesystem $files, Composer $composer)
{
parent::__construct($files, $composer);

Check failure on line 27 in src/Console/CacheTableCommand.php

View workflow job for this annotation

GitHub Actions / PHP8.2 on ubuntu-latest

Method Illuminate\Console\MigrationGeneratorCommand::__construct() invoked with 2 parameters, 1 required.

$this->addGeneratorPresetOptions();
}

/**
* Create a base migration file for the table.
*
* @param string $table
* @return string
*/
protected function createBaseMigration($table)
{
return $this->createBaseMigrationUsingCanvas($table);
}

/**
* Determine whether a migration for the table already exists.
*
* @param string $table
* @return bool
*/
protected function migrationExists($table)
{
return $this->migrationExistsUsingCanvas($table);
}
}
2 changes: 1 addition & 1 deletion src/Console/CastMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CastMakeCommand extends \Illuminate\Foundation\Console\CastMakeCommand
use UsesGeneratorOverrides;

/**
* Create a new controller creator command instance.
* Create a new creator command instance.
*
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ChannelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ChannelMakeCommand extends \Illuminate\Foundation\Console\ChannelMakeComma
use UsesGeneratorOverrides;

/**
* Create a new controller creator command instance.
* Create a new creator command instance.
*
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ComponentMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ComponentMakeCommand extends \Illuminate\Foundation\Console\ComponentMakeC
use UsesGeneratorOverrides;

/**
* Create a new controller creator command instance.
* Create a new creator command instance.
*
* @return void
*/
Expand Down
Loading

0 comments on commit cf266cd

Please sign in to comment.