From f601e2ad93e09a99cad3521b727b439493d10064 Mon Sep 17 00:00:00 2001 From: Alf Drollinger Date: Thu, 5 Dec 2024 12:46:27 +0100 Subject: [PATCH] Go Pro --- packages/builder/src/Blocks/Author.php | 68 ------ .../builder/src/BuilderServiceProvider.php | 4 + .../AbstractPackageBuilderCommand.php | 12 -- .../src/Commands/ActivatePackageCommand.php | 16 -- .../src/Commands/CreatePackageCommand.php | 16 -- .../Commands/PrepareAppForPackagesCommand.php | 19 -- .../src/Commands/PublishPackageCommand.php | 16 -- .../src/Commands/RemovePackageCommand.php | 15 -- .../Package/AbstractPackageGenerator.php | 10 - .../Generators/Package/ArchTestGenerator.php | 10 - .../Generators/Package/ChangelogGenerator.php | 10 - .../Package/ComposerJsonGenerator.php | 10 - .../Package/ConfigFileGenerator.php | 10 - .../Generators/Package/FundingGenerator.php | 10 - .../Generators/Package/GitignoreGenerator.php | 10 - .../Generators/Package/InstallGenerator.php | 10 - .../Generators/Package/LicenceGenerator.php | 10 - .../Package/PanelProviderGenerator.php | 10 - .../src/Generators/Package/PestGenerator.php | 10 - .../Generators/Package/ReadmeGenerator.php | 10 - .../Generators/Package/SecurityGenerator.php | 10 - .../Package/ServiceProviderGenerator.php | 10 - .../Generators/Package/TestCaseGenerator.php | 10 - .../Package/TranslationGenerator.php | 10 - .../builder/src/Presets/FullItemPreset.php | 52 ----- .../src/Presets/PublishableItemPreset.php | 33 --- .../src/Services/Entity/EntityImporter.php | 88 -------- .../Services/Migration/MigrationAnalyzer.php | 126 ----------- .../Services/Migration/MigrationFinder.php | 69 ------ .../Package/AbstractPackageService.php | 26 --- .../src/Services/Package/PackageActivator.php | 14 -- .../src/Services/Package/PackageGenerator.php | 10 - .../Services/Package/PackageGitPublisher.php | 11 - .../Package/PackageGithubPublisher.php | 11 - .../Package/PackagePackagistPublisher.php | 11 - .../src/Services/Package/PackageRemover.php | 14 -- .../src/Services/Version/VersionManager.php | 113 ---------- .../src/Templates/App/composerrepos.stub | 6 - .../src/Templates/Package/archtest.php.stub | 15 -- .../src/Templates/Package/changelog.md.stub | 3 - .../src/Templates/Package/composer.json.stub | 75 ------- .../src/Templates/Package/config.php.stub | 59 ----- .../src/Templates/Package/funding.yml.stub | 13 -- .../src/Templates/Package/gitignore.stub | 49 ----- .../src/Templates/Package/install.php.stub | 203 ------------------ .../src/Templates/Package/licence.md.stub | 21 -- .../Templates/Package/panelprovider.php.stub | 2 - .../src/Templates/Package/pest.php.stub | 47 ---- .../src/Templates/Package/readme.md.stub | 46 ---- .../src/Templates/Package/security.md.stub | 13 -- .../Package/serviceprovider.php.stub | 23 -- .../src/Templates/Package/testcase.php.stub | 21 -- .../Templates/Package/translation.php.stub | 5 - packages/builder/src/Types/AbstractType.php | 34 --- packages/builder/src/Types/ArrayType.php | 19 -- packages/builder/src/Types/BooleanType.php | 19 -- packages/builder/src/Types/DateTimeType.php | 18 -- packages/builder/src/Types/EnumType.php | 18 -- packages/builder/src/Types/FileType.php | 17 -- packages/builder/src/Types/ImageType.php | 17 -- packages/builder/src/Types/NumericType.php | 19 -- packages/builder/src/Types/PasswordType.php | 16 -- packages/builder/src/Types/RelationType.php | 18 -- packages/builder/src/Types/StringType.php | 23 -- packages/builder/src/Types/TextType.php | 18 -- packages/builder/src/Types/UrlType.php | 17 -- 66 files changed, 4 insertions(+), 1754 deletions(-) delete mode 100644 packages/builder/src/Blocks/Author.php delete mode 100644 packages/builder/src/Commands/AbstractPackageBuilderCommand.php delete mode 100644 packages/builder/src/Commands/ActivatePackageCommand.php delete mode 100644 packages/builder/src/Commands/CreatePackageCommand.php delete mode 100644 packages/builder/src/Commands/PrepareAppForPackagesCommand.php delete mode 100644 packages/builder/src/Commands/PublishPackageCommand.php delete mode 100644 packages/builder/src/Commands/RemovePackageCommand.php delete mode 100644 packages/builder/src/Generators/Package/AbstractPackageGenerator.php delete mode 100644 packages/builder/src/Generators/Package/ArchTestGenerator.php delete mode 100644 packages/builder/src/Generators/Package/ChangelogGenerator.php delete mode 100644 packages/builder/src/Generators/Package/ComposerJsonGenerator.php delete mode 100644 packages/builder/src/Generators/Package/ConfigFileGenerator.php delete mode 100644 packages/builder/src/Generators/Package/FundingGenerator.php delete mode 100644 packages/builder/src/Generators/Package/GitignoreGenerator.php delete mode 100644 packages/builder/src/Generators/Package/InstallGenerator.php delete mode 100644 packages/builder/src/Generators/Package/LicenceGenerator.php delete mode 100644 packages/builder/src/Generators/Package/PanelProviderGenerator.php delete mode 100644 packages/builder/src/Generators/Package/PestGenerator.php delete mode 100644 packages/builder/src/Generators/Package/ReadmeGenerator.php delete mode 100644 packages/builder/src/Generators/Package/SecurityGenerator.php delete mode 100644 packages/builder/src/Generators/Package/ServiceProviderGenerator.php delete mode 100644 packages/builder/src/Generators/Package/TestCaseGenerator.php delete mode 100644 packages/builder/src/Generators/Package/TranslationGenerator.php delete mode 100644 packages/builder/src/Presets/FullItemPreset.php delete mode 100644 packages/builder/src/Presets/PublishableItemPreset.php delete mode 100644 packages/builder/src/Services/Entity/EntityImporter.php delete mode 100644 packages/builder/src/Services/Migration/MigrationAnalyzer.php delete mode 100644 packages/builder/src/Services/Migration/MigrationFinder.php delete mode 100644 packages/builder/src/Services/Package/AbstractPackageService.php delete mode 100644 packages/builder/src/Services/Package/PackageActivator.php delete mode 100644 packages/builder/src/Services/Package/PackageGenerator.php delete mode 100644 packages/builder/src/Services/Package/PackageGitPublisher.php delete mode 100644 packages/builder/src/Services/Package/PackageGithubPublisher.php delete mode 100644 packages/builder/src/Services/Package/PackagePackagistPublisher.php delete mode 100644 packages/builder/src/Services/Package/PackageRemover.php delete mode 100644 packages/builder/src/Services/Version/VersionManager.php delete mode 100644 packages/builder/src/Templates/App/composerrepos.stub delete mode 100644 packages/builder/src/Templates/Package/archtest.php.stub delete mode 100644 packages/builder/src/Templates/Package/changelog.md.stub delete mode 100644 packages/builder/src/Templates/Package/composer.json.stub delete mode 100644 packages/builder/src/Templates/Package/config.php.stub delete mode 100644 packages/builder/src/Templates/Package/funding.yml.stub delete mode 100644 packages/builder/src/Templates/Package/gitignore.stub delete mode 100644 packages/builder/src/Templates/Package/install.php.stub delete mode 100644 packages/builder/src/Templates/Package/licence.md.stub delete mode 100644 packages/builder/src/Templates/Package/panelprovider.php.stub delete mode 100644 packages/builder/src/Templates/Package/pest.php.stub delete mode 100644 packages/builder/src/Templates/Package/readme.md.stub delete mode 100644 packages/builder/src/Templates/Package/security.md.stub delete mode 100644 packages/builder/src/Templates/Package/serviceprovider.php.stub delete mode 100644 packages/builder/src/Templates/Package/testcase.php.stub delete mode 100644 packages/builder/src/Templates/Package/translation.php.stub delete mode 100644 packages/builder/src/Types/AbstractType.php delete mode 100644 packages/builder/src/Types/ArrayType.php delete mode 100644 packages/builder/src/Types/BooleanType.php delete mode 100644 packages/builder/src/Types/DateTimeType.php delete mode 100644 packages/builder/src/Types/EnumType.php delete mode 100644 packages/builder/src/Types/FileType.php delete mode 100644 packages/builder/src/Types/ImageType.php delete mode 100644 packages/builder/src/Types/NumericType.php delete mode 100644 packages/builder/src/Types/PasswordType.php delete mode 100644 packages/builder/src/Types/RelationType.php delete mode 100644 packages/builder/src/Types/StringType.php delete mode 100644 packages/builder/src/Types/TextType.php delete mode 100644 packages/builder/src/Types/UrlType.php diff --git a/packages/builder/src/Blocks/Author.php b/packages/builder/src/Blocks/Author.php deleted file mode 100644 index 781cf3fc0..000000000 --- a/packages/builder/src/Blocks/Author.php +++ /dev/null @@ -1,68 +0,0 @@ -searchable = $searchable; - $this->toggleable = $toggleable; - $this->sortable = $sortable; - $this->userModel = $userModel; - - $this->useStatements = [ - 'resource' => [ - 'forms' => [ - 'use Filament\Forms\Components\Select;', - ], - 'columns' => [ - 'use Filament\Tables\Columns\TextColumn;', - ], - ], - 'model' => [ - 'use Moox\Core\Traits\HasAuthor;', - ], - ]; - - $this->traits['model'] = ['HasAuthor']; - - $this->formFields['resource'] = [ - "Select::make('author_id') - ->relationship('author', 'name')" - .($this->nullable ? '' : '->required()'), - ]; - - $this->tableColumns['resource'] = [ - "TextColumn::make('author.name') - ->label(__('core::core.author'))" - .($this->sortable ? '' : '->sortable()') - .($this->searchable ? '' : '->searchable()') - .($this->toggleable ? '' : '->toggleable()'), - ]; - - $this->migrations['fields'] = [ - '$table->foreignId("author_id")->constrained()->cascadeOnDelete()', - ]; - } -} diff --git a/packages/builder/src/BuilderServiceProvider.php b/packages/builder/src/BuilderServiceProvider.php index b55448d06..dff947b96 100644 --- a/packages/builder/src/BuilderServiceProvider.php +++ b/packages/builder/src/BuilderServiceProvider.php @@ -32,6 +32,10 @@ public function register(): void { parent::register(); + $this->app->bind('moox.builder.path', function () { + return dirname(__DIR__); + }); + $this->mergeConfigFrom(__DIR__.'/../config/builder.php', 'builder'); $this->app->register(BuilderPanelProvider::class); diff --git a/packages/builder/src/Commands/AbstractPackageBuilderCommand.php b/packages/builder/src/Commands/AbstractPackageBuilderCommand.php deleted file mode 100644 index a8c43607a..000000000 --- a/packages/builder/src/Commands/AbstractPackageBuilderCommand.php +++ /dev/null @@ -1,12 +0,0 @@ -info('Activating package...'); - // activate the package by using the PackageActivator service - } -} diff --git a/packages/builder/src/Commands/CreatePackageCommand.php b/packages/builder/src/Commands/CreatePackageCommand.php deleted file mode 100644 index fec506b19..000000000 --- a/packages/builder/src/Commands/CreatePackageCommand.php +++ /dev/null @@ -1,16 +0,0 @@ -info('Creating package...'); - // create the package using the PackageGenerator service - } -} diff --git a/packages/builder/src/Commands/PrepareAppForPackagesCommand.php b/packages/builder/src/Commands/PrepareAppForPackagesCommand.php deleted file mode 100644 index 7b4072e6e..000000000 --- a/packages/builder/src/Commands/PrepareAppForPackagesCommand.php +++ /dev/null @@ -1,19 +0,0 @@ -info('Preparing app for packages...'); - // create packages directory - // paste composerrepos.stub into composer.json - } -} diff --git a/packages/builder/src/Commands/PublishPackageCommand.php b/packages/builder/src/Commands/PublishPackageCommand.php deleted file mode 100644 index f9627cc8d..000000000 --- a/packages/builder/src/Commands/PublishPackageCommand.php +++ /dev/null @@ -1,16 +0,0 @@ -info('Publishing package...'); - // use the services from the config array package_entity_publisher to publish the package - } -} diff --git a/packages/builder/src/Commands/RemovePackageCommand.php b/packages/builder/src/Commands/RemovePackageCommand.php deleted file mode 100644 index c505caa57..000000000 --- a/packages/builder/src/Commands/RemovePackageCommand.php +++ /dev/null @@ -1,15 +0,0 @@ -info('Removing package...'); - } -} diff --git a/packages/builder/src/Generators/Package/AbstractPackageGenerator.php b/packages/builder/src/Generators/Package/AbstractPackageGenerator.php deleted file mode 100644 index bea5bc797..000000000 --- a/packages/builder/src/Generators/Package/AbstractPackageGenerator.php +++ /dev/null @@ -1,10 +0,0 @@ -blocks = [ - new Text( - name: 'title', - label: 'Title', - description: 'The title of the item', - length: 255, - nullable: false, - unique: true, - searchable: true, - sortable: true - ), - new Text( - name: 'slug', - label: 'Slug', - description: 'The URL slug for the item', - length: 255, - nullable: false, - unique: true - ), - new TextArea( - name: 'content', - label: 'Content', - description: 'The content of the item' - ), - new FileUpload( - name: 'featured_image_url', - label: 'Featured Image', - description: 'The featured image for the item', - acceptedFileTypes: ['image/jpeg', 'image/png', 'image/webp'], - directory: 'images' - ), - //new Author, - new Publish, - ]; - } -} diff --git a/packages/builder/src/Presets/PublishableItemPreset.php b/packages/builder/src/Presets/PublishableItemPreset.php deleted file mode 100644 index 998ff2ac3..000000000 --- a/packages/builder/src/Presets/PublishableItemPreset.php +++ /dev/null @@ -1,33 +0,0 @@ -blocks = [ - new TitleWithSlug( - titleFieldName: 'title', - slugFieldName: 'slug', - label: 'Title', - description: 'The title of the item', - nullable: false - ), - new Tabs, - new Publish, - new MarkdownEditor( - name: 'content', - label: 'Content', - description: 'The content of the item', - ), - ]; - } -} diff --git a/packages/builder/src/Services/Entity/EntityImporter.php b/packages/builder/src/Services/Entity/EntityImporter.php deleted file mode 100644 index fabe02251..000000000 --- a/packages/builder/src/Services/Entity/EntityImporter.php +++ /dev/null @@ -1,88 +0,0 @@ -finder->findMigrationForTable($tableName); - if (! $migrationPath) { - return null; - } - - $blueprint = $this->finder->extractBlueprintFromFile($migrationPath); - if (! $blueprint) { - return null; - } - - return $this->importFromBlueprint($blueprint); - } - - public function importFromBlueprint(Blueprint $blueprint): array - { - $analysis = $this->analyzer->analyzeBlueprint($blueprint); - $blocks = []; - - foreach ($analysis['columns'] as $name => $type) { - $blocks[] = $this->createBlockFromType($name, $type); - } - - foreach ($analysis['relationships'] as $relation) { - $blocks[] = new Relationship( - name: $relation['name'], - label: ucfirst($relation['name']), - description: '', - nullable: $relation['nullable'], - relatedModel: ucfirst($relation['related_table']), - multiple: $relation['multiple'] - ); - } - - return $blocks; - } - - private function createBlockFromType(string $name, AbstractType $type): AbstractBlock - { - $label = ucfirst(str_replace('_', ' ', $name)); - - return match (get_class($type)) { - FileType::class => new FileUpload($name, $label, ''), - ImageType::class => new Image($name, $label, ''), - EnumType::class => new Radio($name, $label, ''), - ArrayType::class => $this->createArrayBlock($name, $label), - TextType::class => new MarkdownEditor($name, $label, ''), - default => new Text($name, $label, '') - }; - } - - private function createArrayBlock(string $name, string $label): AbstractBlock - { - return new MultiSelect($name, $label, ''); - } -} diff --git a/packages/builder/src/Services/Migration/MigrationAnalyzer.php b/packages/builder/src/Services/Migration/MigrationAnalyzer.php deleted file mode 100644 index 4062569fb..000000000 --- a/packages/builder/src/Services/Migration/MigrationAnalyzer.php +++ /dev/null @@ -1,126 +0,0 @@ - StringType::class, - 'text' => TextType::class, - 'mediumText' => TextType::class, - 'longText' => TextType::class, - 'json' => ArrayType::class, - 'jsonb' => ArrayType::class, - 'boolean' => BooleanType::class, - 'integer' => NumericType::class, - 'bigInteger' => NumericType::class, - 'decimal' => NumericType::class, - 'float' => NumericType::class, - 'date' => DateTimeType::class, - 'datetime' => DateTimeType::class, - 'timestamp' => DateTimeType::class, - ]; - - private array $specialNamePatterns = [ - 'password' => PasswordType::class, - 'url' => UrlType::class, - 'link' => UrlType::class, - 'image' => ImageType::class, - 'photo' => ImageType::class, - 'picture' => ImageType::class, - 'file' => FileType::class, - 'attachment' => FileType::class, - 'document' => FileType::class, - ]; - - public function analyzeBlueprint(Blueprint $blueprint): array - { - $columns = []; - $relationships = []; - - foreach ($blueprint->getColumns() as $column) { - $name = $column->get('name'); - - if (in_array($name, self::SYSTEM_COLUMNS)) { - continue; - } - - if ($this->isRelationship($column)) { - $relationships[] = $this->analyzeRelationship($column); - - continue; - } - - $columns[$name] = $this->analyzeColumn($column); - } - - return [ - 'columns' => $columns, - 'relationships' => $relationships, - ]; - } - - private function analyzeColumn(ColumnDefinition $column): AbstractType - { - $name = $column->get('name'); - - foreach ($this->specialNamePatterns as $pattern => $typeClass) { - if (str_contains($name, $pattern)) { - return new $typeClass; - } - } - - $attributes = $column->getAttributes(); - if (! empty($attributes['allowed'] ?? [])) { - return new EnumType; - } - - $baseType = $column->get('type'); - $typeClass = $this->columnTypeMap[$baseType] ?? StringType::class; - - return new $typeClass; - } - - private function isRelationship(ColumnDefinition $column): bool - { - $name = $column->get('name'); - $attributes = $column->getAttributes(); - - return str_ends_with($name, '_id') - || ($attributes['foreign'] ?? false); - } - - private function analyzeRelationship(ColumnDefinition $column): array - { - $name = str_replace('_id', '', $column->get('name')); - $attributes = $column->getAttributes(); - - return [ - 'name' => $name, - 'type' => new RelationType, - 'nullable' => $attributes['nullable'] ?? false, - 'multiple' => false, - 'related_table' => $attributes['on'] ?? $name.'s', - ]; - } -} diff --git a/packages/builder/src/Services/Migration/MigrationFinder.php b/packages/builder/src/Services/Migration/MigrationFinder.php deleted file mode 100644 index 9e8332522..000000000 --- a/packages/builder/src/Services/Migration/MigrationFinder.php +++ /dev/null @@ -1,69 +0,0 @@ -ensureContextIsSet(); - $this->migrations = $this->fileManager->findMigrationFiles( - $this->context->getPath('migrations') - ); - } - - public function getMigrations(): array - { - return $this->migrations; - } - - public function findMigrationForTable(string $tableName): ?string - { - $pattern = str_replace( - $this->context->getTableName(), - $tableName, - $this->getMigrationPattern() - ); - - $files = glob($pattern); - - return $files ? end($files) : null; - } - - public function extractBlueprintFromFile(string $path): ?Blueprint - { - if (! file_exists($path)) { - return null; - } - - $content = file_get_contents($path); - if (preg_match('/Schema::create\([\'"](.+?)[\'"]\s*,\s*function\s*\(Blueprint\s+\$table\)\s*{(.+?)}\);/s', $content, $matches)) { - return $this->createBlueprintFromContent($matches[1], $matches[2]); - } - - return null; - } - - protected function createBlueprintFromContent(string $table, string $content): Blueprint - { - $blueprint = new Blueprint($table); - eval('$blueprint->'.trim($content).';'); - - return $blueprint; - } -} diff --git a/packages/builder/src/Services/Package/AbstractPackageService.php b/packages/builder/src/Services/Package/AbstractPackageService.php deleted file mode 100644 index 851d50fc6..000000000 --- a/packages/builder/src/Services/Package/AbstractPackageService.php +++ /dev/null @@ -1,26 +0,0 @@ -ensureContextIsSet(); - } - - public function createVersion(array $data): int - { - $contextType = $this->context->getContextType(); - - return match ($contextType) { - 'package' => $this->createPackageVersion($data), - 'app', 'preview' => $this->createEntityVersion($data), - default => throw new RuntimeException("Unsupported context type: {$contextType}"), - }; - } - - public function getLatestVersion(): ?object - { - $contextType = $this->context->getContextType(); - - return match ($contextType) { - 'package' => $this->getLatestPackageVersion(), - 'app', 'preview' => $this->getLatestEntityVersion(), - default => throw new RuntimeException("Unsupported context type: {$contextType}"), - }; - } - - protected function createPackageVersion(array $data): int - { - return DB::table('builder_package_versions')->insertGetId([ - 'package_id' => $this->getPackageId(), - 'version' => $this->generateVersionNumber(), - 'data' => json_encode($data), - 'created_at' => now(), - 'updated_at' => now(), - ]); - } - - protected function createEntityVersion(array $data): int - { - return DB::table('builder_entity_builds')->insertGetId([ - 'entity_id' => $this->getEntityId(), - 'build_context' => $this->context->getContextType(), - 'version' => $this->generateVersionNumber(), - 'data' => json_encode($data), - 'created_at' => now(), - 'updated_at' => now(), - ]); - } - - protected function getLatestPackageVersion(): ?object - { - return DB::table('builder_package_versions') - ->where('package_id', $this->getPackageId()) - ->orderBy('created_at', 'desc') - ->first(); - } - - protected function getLatestEntityVersion(): ?object - { - return DB::table('builder_entity_builds') - ->where('entity_id', $this->getEntityId()) - ->where('build_context', $this->context->getContextType()) - ->orderBy('created_at', 'desc') - ->first(); - } - - protected function getPackageId(): int - { - $name = $this->context->getEntityName(); - $package = DB::table('builder_packages') - ->where('name', $name) - ->first(); - - return $package ? $package->id : 0; - } - - protected function getEntityId(): int - { - $name = $this->context->getEntityName(); - $entity = DB::table('builder_entities') - ->where('singular', $name) - ->whereNull('deleted_at') - ->first(); - - return $entity ? $entity->id : 0; - } - - protected function generateVersionNumber(): string - { - $latestVersion = $this->getLatestVersion(); - if (! $latestVersion) { - return '1.0.0'; - } - - $parts = explode('.', $latestVersion->version); - $parts[2] = (int) $parts[2] + 1; - - return implode('.', $parts); - } -} diff --git a/packages/builder/src/Templates/App/composerrepos.stub b/packages/builder/src/Templates/App/composerrepos.stub deleted file mode 100644 index a1e3fb658..000000000 --- a/packages/builder/src/Templates/App/composerrepos.stub +++ /dev/null @@ -1,6 +0,0 @@ - "repositories": [ - { - "type": "path", - "url": "packages/*" - } - ], diff --git a/packages/builder/src/Templates/Package/archtest.php.stub b/packages/builder/src/Templates/Package/archtest.php.stub deleted file mode 100644 index c24e26f37..000000000 --- a/packages/builder/src/Templates/Package/archtest.php.stub +++ /dev/null @@ -1,15 +0,0 @@ -expect('{{ Namespace }}\{{ Package }}') - ->toUseStrictTypes() - ->not->toUse(['die', 'dd', 'dump']); - -arch() - ->expect('{{ Namespace }}\{{ Package }}\Models') - ->toBeClasses() - ->toExtend('Illuminate\Database\Eloquent\Model') - ->toOnlyBeUsedIn('{{ Namespace }}\{{ Package }}'); - -arch()->preset()->php(); -arch()->preset()->security()->ignoring('md5'); diff --git a/packages/builder/src/Templates/Package/changelog.md.stub b/packages/builder/src/Templates/Package/changelog.md.stub deleted file mode 100644 index 871fee1ca..000000000 --- a/packages/builder/src/Templates/Package/changelog.md.stub +++ /dev/null @@ -1,3 +0,0 @@ -# Changelog - -All notable changes to {{ Namespace }} {{ Package }} will be documented in this file. diff --git a/packages/builder/src/Templates/Package/composer.json.stub b/packages/builder/src/Templates/Package/composer.json.stub deleted file mode 100644 index 3925eeb91..000000000 --- a/packages/builder/src/Templates/Package/composer.json.stub +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "{{ LowercaseNamespace }}/{{ LowercasePackage }}", - "description": "This is a package generated by Moox Builder", - "keywords": [ - "Laravel", - "Filament", - "Filament plugin", - "Laravel package" - ], - "homepage": "{{ Homepage }}", - "license": "MIT", - "authors": [ - { - "name": "{{ AuthorName }}", - "email": "{{ AuthorEmail }}", - "role": "Developer" - } - ], - "require": { - "moox/core": "*" - }, - "autoload": { - "psr-4": { - "{{ Namespace }}\{{ Package }}\": "src", - "{{ Namespace }}\{{ Package }}\Database\\Factories\\": "database/factories" - } - }, - "extra": { - "laravel": { - "providers": [ - "{{ Namespace }}\{{ Package }}\{{ Package }}ServiceProvider" - ] - } - }, - "minimum-stability": "stable", - "prefer-stable": true, - "require-dev": { - "orchestra/testbench": "^9.5", - "pestphp/pest": "^3.2", - "pestphp/pest-plugin-livewire": "^3.0", - "pestphp/pest-plugin-laravel": "^3.0", - "ryangjchandler/blade-capture-directive": "^1.0" - }, - "autoload-dev": { - "psr-4": { - "{{ Namespace }}\{{ Package }}\Tests\\": "tests", - "{{ Namespace }}\{{ Package }}\Database\\Factories\\": "database/factories", - } - }, - "scripts": { - "post-autoload-dump": [ - "@clear", - "@prepare" - ], - "clear": "@php vendor/bin/testbench package:purge-skeleton --ansi", - "prepare": "@php vendor/bin/testbench package:discover --ansi", - "build": "@php vendor/bin/testbench workbench:build --ansi", - "serve": [ - "Composer\\Config::disableProcessTimeout", - "@build", - "@php vendor/bin/testbench serve --ansi" - ], - "lint": [ - "@php vendor/bin/phpstan analyse --verbose --ansi" - ], - "test": [ - "@php vendor/bin/phpunit" - ] - }, - "config": { - "allow-plugins": { - "pestphp/pest-plugin": true - } - } -} diff --git a/packages/builder/src/Templates/Package/config.php.stub b/packages/builder/src/Templates/Package/config.php.stub deleted file mode 100644 index 7d5f05a8b..000000000 --- a/packages/builder/src/Templates/Package/config.php.stub +++ /dev/null @@ -1,59 +0,0 @@ - [ - // Add your entities here - ], - - /* - |-------------------------------------------------------------------------- - | Navigation Group - |-------------------------------------------------------------------------- - | - | The translatable title of the navigation group in the - | Filament Admin Panel. Instead of a translatable - | string, you may also use a simple string. - | - */ - - 'navigation_group' => 'trans//{{ LowercasePackage }}::translations.{{ LowercasePackage }}', - - /* - |-------------------------------------------------------------------------- - | Navigation Sort - |-------------------------------------------------------------------------- - | - | This value is the sort order of the navigation item in the - | Filament Admin Panel. If you use a bunch of Moox - | plugins, everything should be in order. - | - */ - - 'navigation_sort' => 8500, - -]; diff --git a/packages/builder/src/Templates/Package/funding.yml.stub b/packages/builder/src/Templates/Package/funding.yml.stub deleted file mode 100644 index 0446fa42d..000000000 --- a/packages/builder/src/Templates/Package/funding.yml.stub +++ /dev/null @@ -1,13 +0,0 @@ -# These are supported funding model platforms - -github: [mooxphp] -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 -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/packages/builder/src/Templates/Package/gitignore.stub b/packages/builder/src/Templates/Package/gitignore.stub deleted file mode 100644 index 6a81cbb00..000000000 --- a/packages/builder/src/Templates/Package/gitignore.stub +++ /dev/null @@ -1,49 +0,0 @@ -# Environment -.env -.env.backup - -# Composer -/vendor -composer.lock -auth.json - -# NPM / Node -/node_modules -npm-debug.log -package-lock.json - -# Laravel -/public/hot -/public/storage -/storage/*.key - -# PHPUnit -.phpunit.result.cache -phpunit.xml - -# Yarn -yarn-error.log - -# PHPStan -/build -phpstan.neon - -# Testbench -testbench.yaml - -# PHP CS Fixer -.php-cs-fixer.cache - -# Homestead -Homestead.json -Homestead.yaml - -# IDEs -/.idea -/.vscode - -# MacOS -.DS_Store - -# Windows -Thumbs.db diff --git a/packages/builder/src/Templates/Package/install.php.stub b/packages/builder/src/Templates/Package/install.php.stub deleted file mode 100644 index 0cd94a294..000000000 --- a/packages/builder/src/Templates/Package/install.php.stub +++ /dev/null @@ -1,203 +0,0 @@ -art(); - $this->welcome(); - $this->publishConfiguration(); - $this->publishMigrations(); - $this->runMigrations(); - $providerPath = app_path('Providers/Filament'); - $panelsToregister = $this->getPanelProviderPath(); - if ($panelsToregister != null) { - if (is_array($panelsToregister)) { - foreach ($panelsToregister as $panelprovider) { - $this->registerPlugins($providerPath.'/'.$panelprovider); - } - } else { - $this->registerPlugins($panelsToregister); - } - } else { - $this->registerPlugins($panelsToregister[0]); - } - $this->sayGoodbye(); - } - - public function art(): void - { - info(' - - ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ - ▓▓▒░░▒▓▓▒▒░░░░░░▒▒▓▓▓▒░░░░░░░▒▓▓ ▓▓▓▓▒░░░░░░░▒▓▓▓▓ ▓▓▓▓▓▒░░░░░░░▒▒▓▓▓▓▓▒▒▒▒▓▓ ▓▓▓▒▒▒▒▓▓ - ▓▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓ ▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓░░░░░▒▓▓ ▓▓▒░░░░░▓▓ - ▓▒░░░░░░▒▓▓▓▓▒░░░░░░░▒▓▓▓▓░░░░░▒▓▓▓░░░░░▒▓▓▓▓▒░░░░░░░▓▓▓▓░░░░░░▒▓▓▓▓▓░░░░░░▒▓▓░░░░░▒▓▓▓▓▓░░░░░▒▓▓ - ▓▒░░░░▓▓▓▓ ▓▓░░░░░▓▓▓ ▓▓▓░░░░▒▓▓░░░░▒▓▓▓ ▓▓▓▓░░░░░▓░░░░░░▓▓▓▓ ▓▓▓▒░░░░▓▓▓▒░░░░░▓▓▓░░░░░▓▓▓ - ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓▓ ▓▓▓░░▒░░░░░▓▓▓ ▓▓░░░░▒▓▓▓▓░░░░░░░░░░░▓▓ - ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓ ▓▓▓░░░░░▒▓▓ ▓▓▒░░░░▓ ▓▓▓░░░░░░░░░▓▓ - ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓▓ ▓▓▒░░░░░▒░░▒▓▓ ▓▓░░░░▒▓▓▓▒░░░░░▒░░░░░▒▓ - ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓░░░░▒▓▓▓ ▓▓▓▒░░░░░▒▒░░░░░▒▓▓▓ ▓▓▓░░░░░▓▓▓░░░░░▒▓▓▓░░░░░▒▓▓ - ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓▓░░░░░░▒▒▓▓▒░░░░░░▒▓▓▓▓░░░░░░░▒▒▓▓▒░░░░░░▓▓▓░░░░░▒▓▓▓▓▓▒░░░░░▓▓ - ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓ ▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▒░░░░░▓▓▓ ▓▓▒░░░░░▒▓ - ▓▓░░░▒▓▓ ▓▓▒░░░▒▓▓ ▓▓░░░░▓▓ ▓▓▓▓▒░░░░░░▒▒▓▓▓▓ ▓▓▓▓▓▒▒░░░░░▒▒▓▓▓▓▓░░░░▒▓▓ ▓▓▓░░░░▒▓ - ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ - - '); - } - - public function welcome(): void - { - info('Welcome to {{ Namespace }} {{ Package }} Installer'); - } - - public function publishConfiguration(): void - { - if (confirm('Do you wish to publish the configuration?', true)) { - if (! File::exists('config/{{ LowercasePackage }}.php')) { - info('Publishing {{ Namespace }} {{ Package }} Configuration...'); - $this->callSilent('vendor:publish', ['--tag' => '{{ LowercasePackage }}-config']); - - return; - } - warning('The {{ Namespace }} {{ Package }} config already exist. The config will not be published.'); - } - } - - public function publishMigrations(): void - { - if (confirm('Do you wish to publish the migrations?', true)) { - info('Publishing {{ Namespace }} {{ Package }} Migrations...'); - $this->callSilent('vendor:publish', ['--tag' => '{{ LowercasePackage }}-migrations']); - } - } - - public function runMigrations(): void - { - if (confirm('Do you wish to run the migrations?', true)) { - info('Running {{ Namespace }} {{ Package }} Migrations...'); - $this->callSilent('migrate'); - } - } - - public function registerPlugins(string $providerPath): void - { - if (! File::exists($providerPath)) { - alert('Provider file not found.'); - - return; - } - - $content = File::get($providerPath); - $pluginPath = dirname(__DIR__).'/Plugins'; - $pluginFiles = File::glob($pluginPath.'/*Plugin.php'); - - if (empty($pluginFiles)) { - alert('No plugins found in src/Plugins directory.'); - - return; - } - - $availablePlugins = array_map(function ($file) { - return basename($file, '.php'); - }, $pluginFiles); - - $pluginsToAdd = multiselect( - label: 'These plugins will be installed:', - options: $availablePlugins, - default: $availablePlugins, - ); - - $intend = ' '; - $namespace = "\{{ Namespace }}\{{ Package }}\Plugins"; - $function = '::make(),'; - $pattern = '/->plugins\(\[([\s\S]*?)\]\);/'; - $newPlugins = ''; - - foreach ($pluginsToAdd as $plugin) { - $searchPlugin = '/'.$plugin.'/'; - if (preg_match($searchPlugin, $content)) { - warning("$plugin already registered."); - } else { - $newPlugins .= $intend.$namespace.'\\'.$plugin.$function."\n"; - } - } - - if ($newPlugins) { - if (preg_match($pattern, $content)) { - info('Plugins section found. Adding new plugins...'); - - $replacement = "->plugins([$1\n$newPlugins\n ]);"; - $newContent = preg_replace($pattern, $replacement, $content); - } else { - info('Plugins section created. Adding new plugins...'); - - $pluginsSection = " ->plugins([\n$newPlugins\n ]);"; - $placeholderPattern = '/(\->authMiddleware\(\[.*?\]\))\s*\;/s'; - $replacement = "$1\n".$pluginsSection; - $newContent = preg_replace($placeholderPattern, $replacement, $content, 1); - } - - File::put($providerPath, $newContent); - } - } - - public function getPanelProviderPath(): string|array - { - $providerPath = app_path('Providers/Filament'); - $providers = File::allFiles($providerPath); - if (count($providers) > 1) { - $providerNames = []; - foreach ($providers as $provider) { - $providerNames[] = $provider->getBasename(); - } - $providerPath = multiselect( - label: 'Which Panel should it be registered', - options: [...$providerNames], - default: [$providerNames[0]], - ); - } - if (count($providers) == 1) { - $providerPath .= '/'.$providers[0]->getBasename(); - } - - return $providerPath; - } - - public function sayGoodbye(): void - { - note('Moox Builder installed successfully. Enjoy!'); - } -} diff --git a/packages/builder/src/Templates/Package/licence.md.stub b/packages/builder/src/Templates/Package/licence.md.stub deleted file mode 100644 index 7dfc5ad0b..000000000 --- a/packages/builder/src/Templates/Package/licence.md.stub +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) Moox - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/builder/src/Templates/Package/panelprovider.php.stub b/packages/builder/src/Templates/Package/panelprovider.php.stub deleted file mode 100644 index a9cf11523..000000000 --- a/packages/builder/src/Templates/Package/panelprovider.php.stub +++ /dev/null @@ -1,2 +0,0 @@ -// Work in progress -// Will be used to generate a panel provider diff --git a/packages/builder/src/Templates/Package/pest.php.stub b/packages/builder/src/Templates/Package/pest.php.stub deleted file mode 100644 index 1ada1f642..000000000 --- a/packages/builder/src/Templates/Package/pest.php.stub +++ /dev/null @@ -1,47 +0,0 @@ -extends(TestCase::class) - ->beforeEach(function () { - $this->artisan('migrate'); - $user = User::factory()->create(); - $this->actingAs($user); - })->afterEach(function () { - $this->artisan('db:wipe'); - $this->artisan('optimize:clear'); - })->in('Feature'); - -/* -|-------------------------------------------------------------------------- -| Expectations -|-------------------------------------------------------------------------- -| -| When you're writing tests, you often need to check that values meet certain conditions. The -| "expect()" function gives you access to a set of "expectations" methods that you can use -| to assert different things. Of course, you may extend the Expectation API at any time. -| -*/ - -/* -|-------------------------------------------------------------------------- -| Functions -|-------------------------------------------------------------------------- -| -| While Pest is very powerful out-of-the-box, you may have some testing code specific to your -| project that you don't want to repeat in every file. Here you can also expose helpers as -| global functions to help you to reduce the number of lines of code in your test files. -| -*/ diff --git a/packages/builder/src/Templates/Package/readme.md.stub b/packages/builder/src/Templates/Package/readme.md.stub deleted file mode 100644 index c151ca34e..000000000 --- a/packages/builder/src/Templates/Package/readme.md.stub +++ /dev/null @@ -1,46 +0,0 @@ -![{{ Namespace }} {{ Package }}](https://github.com/mooxphp/moox/raw/main/art/banner/builderpackage.jpg) - -# {{ Namespace }} {{ Package }} - -{{ Description }} - -## Quick Installation - -These two commmands are all you need to install the package: - -```bash -composer require {{ LowercaseNamespace }}/{{ LowercasePackage }} -php artisan {{ LowercasePackage }}:install -``` - -Curious what the install command does? See manual installation below. - -## Manual Installation - -Instead of using the install-command `php artisan {{ LowercasePackage }}:install` you are able to install this package manually step by step: - -```bash -// Publish and run the migrations: -php artisan vendor:publish --tag="{{ LowercasePackage }}-migrations" -php artisan migrate - -// Publish the config file with: -php artisan vendor:publish --tag="{{ LowercasePackage }}-config" -``` - -## Changelog - -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. - -## Security Vulnerabilities - -Please review [our security policy](SECURITY.md) on how to report security vulnerabilities. - -## Credits - -- [{{ AuthorName }}]({{ Homepage }}) -- [All Contributors](../../contributors) - -## License - -The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/packages/builder/src/Templates/Package/security.md.stub b/packages/builder/src/Templates/Package/security.md.stub deleted file mode 100644 index bc4f49602..000000000 --- a/packages/builder/src/Templates/Package/security.md.stub +++ /dev/null @@ -1,13 +0,0 @@ -# Security Policy - -## Supported Versions - -We maintain the current version of `{{ Namespace }} {{ Package }}` actively. - -Do not expect security fixes for older versions. - -## Reporting a Vulnerability - -If you find any security-related bug, please report it to {{ AuthorEmail }}. - -Please do not use Github issues, to give us enough time to review and fix the issue, before others can use it, to do stupid things. diff --git a/packages/builder/src/Templates/Package/serviceprovider.php.stub b/packages/builder/src/Templates/Package/serviceprovider.php.stub deleted file mode 100644 index ad69e9451..000000000 --- a/packages/builder/src/Templates/Package/serviceprovider.php.stub +++ /dev/null @@ -1,23 +0,0 @@ -name('{{ LowercasePackage }}') - ->hasConfigFile() - ->hasViews() - ->hasTranslations() - ->hasMigrations(['create_items_table']) - ->hasCommand(InstallCommand::class); - } -} diff --git a/packages/builder/src/Templates/Package/testcase.php.stub b/packages/builder/src/Templates/Package/testcase.php.stub deleted file mode 100644 index 38de58ee6..000000000 --- a/packages/builder/src/Templates/Package/testcase.php.stub +++ /dev/null @@ -1,21 +0,0 @@ -artisan('migrate'); - $this->actingAs(User::factory()->create()); - } - - protected function getEnvironmentSetUp($app) {} -} diff --git a/packages/builder/src/Templates/Package/translation.php.stub b/packages/builder/src/Templates/Package/translation.php.stub deleted file mode 100644 index f92ec767e..000000000 --- a/packages/builder/src/Templates/Package/translation.php.stub +++ /dev/null @@ -1,5 +0,0 @@ - '{{ Package }}', -]; diff --git a/packages/builder/src/Types/AbstractType.php b/packages/builder/src/Types/AbstractType.php deleted file mode 100644 index b7116a36f..000000000 --- a/packages/builder/src/Types/AbstractType.php +++ /dev/null @@ -1,34 +0,0 @@ -availableFields; - } - - public function getDefaultField(): string - { - return $this->defaultField; - } - - public function getDatabaseType(): string - { - return $this->databaseType; - } - - public function canUseField(string $field): bool - { - return in_array($field, $this->availableFields); - } -} diff --git a/packages/builder/src/Types/ArrayType.php b/packages/builder/src/Types/ArrayType.php deleted file mode 100644 index 9b5b7e444..000000000 --- a/packages/builder/src/Types/ArrayType.php +++ /dev/null @@ -1,19 +0,0 @@ -