Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace Blueprint;


use Blueprint\Contracts\Generator;
use Blueprint\Contracts\Lexer;
use Symfony\Component\Yaml\Yaml;
use Blueprint\Contracts\Generator;

class Blueprint
{
Expand All @@ -25,7 +24,7 @@ public function analyze(array $tokens)
{
$registry = [
'models' => [],
'controllers' => []
'controllers' => [],
];

foreach ($this->lexers as $lexer) {
Expand All @@ -46,6 +45,11 @@ public function generate(array $tree): array
return $components;
}

public function dump(array $generated)
{
return Yaml::dump($generated);
}

public function registerLexer(Lexer $lexer)
{
$this->lexers[] = $lexer;
Expand All @@ -55,4 +59,4 @@ public function registerGenerator(Generator $generator)
{
$this->generators[] = $generator;
}
}
}
8 changes: 6 additions & 2 deletions src/BlueprintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Blueprint;

use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputArgument;

class BlueprintCommand extends Command
Expand Down Expand Up @@ -80,8 +80,12 @@ public function handle()

$this->line('');
});
}

$this->files->put(
'.blueprint',
$blueprint->dump($generated)
);
}

/**
* Get the console command arguments.
Expand Down
19 changes: 14 additions & 5 deletions src/BlueprintServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class BlueprintServiceProvider extends ServiceProvider implements DeferrableProv
*/
public function boot()
{
// ...
if (!defined('STUBS_PATH')) {
define('STUBS_PATH', dirname(__DIR__) . '/stubs');
}
Expand All @@ -32,8 +31,16 @@ function ($app) {
return new BlueprintCommand($app['files']);
}
);
$this->app->bind('command.blueprint.erase',
function ($app) {
return new EraseCommand($app['files']);
}
);

$this->commands('command.blueprint.build');
$this->commands([
'command.blueprint.build',
'command.blueprint.erase',
]);
}

/**
Expand All @@ -43,7 +50,9 @@ function ($app) {
*/
public function provides()
{
return ['command.blueprint.build'];
return [
'command.blueprint.build',
'command.blueprint.erase',
];
}

}
}
98 changes: 98 additions & 0 deletions src/EraseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace Blueprint;

use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputArgument;

class EraseCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'blueprint:erase';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Erase components created from last Blueprint build';

/** @var Filesystem $files */
protected $files;

/**
* @param Filesystem $files
* @param \Illuminate\Contracts\View\Factory $view
*/
public function __construct(Filesystem $files)
{
parent::__construct();

$this->files = $files;
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$contents = $this->files->get('.blueprint');

$blueprint = new Blueprint();
$generated = $blueprint->parse($contents);

collect($generated)->each(function ($files, $action) {
if ($action === 'created') {
$this->line('Deleted:', $this->outputStyle($action));
$this->files->delete($files);
} elseif ($action === 'updated') {
$this->comment('The updates to the following files can not be erased automatically.');
}

collect($files)->each(function ($file) {
$this->line('- ' . $file);
});

$this->line('');
});
}

/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['draft', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Which models to include', []],
];
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [];
}

private function outputStyle($action)
{
if ($action === 'created') {
return 'error';
}

return 'comment';
}
}
7 changes: 3 additions & 4 deletions tests/Feature/Generator/ControllerGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Tests\Feature\Generators;

use Tests\TestCase;
use Blueprint\Blueprint;
use Blueprint\Generators\ControllerGenerator;
use Blueprint\Lexers\StatementLexer;
use Tests\TestCase;
use Blueprint\Generators\ControllerGenerator;

/**
* @see ControllerGenerator
Expand Down Expand Up @@ -70,10 +70,9 @@ public function output_writes_migration_for_controller_tree($definition, $path,
$tree = $this->blueprint->analyze($tokens);

$this->assertEquals(['created' => [$path]], $this->subject->output($tree));
++$iteration;
$iteration++;
}


public function controllerTreeDataProvider()
{
return [
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/Generator/FactoryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ public function output_writes_migration_for_model_tree($definition, $path, $migr
$this->assertEquals(['created' => [$path]], $this->subject->output($tree));
}


public function modelTreeDataProvider()
{
return [
['definitions/post.bp', 'database/factories/PostFactory.php', 'factories/post.php'],
['definitions/team.bp', 'database/factories/TeamFactory.php', 'factories/team.php']
];
}
}
}
5 changes: 2 additions & 3 deletions tests/Feature/Generator/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Tests\Feature\Generators;

use Tests\TestCase;
use Blueprint\Blueprint;
use Blueprint\Generators\ModelGenerator;
use Tests\TestCase;

class ModelGeneratorTest extends TestCase
{
Expand Down Expand Up @@ -81,10 +81,9 @@ public function output_writes_migration_for_model_tree($definition, $path, $mode
$tree = $this->blueprint->analyze($tokens);

$this->assertEquals(['created' => [$path]], $this->subject->output($tree));
++$iteration;
$iteration++;
}


public function modelTreeDataProvider()
{
return [
Expand Down
5 changes: 2 additions & 3 deletions tests/Feature/Generator/RouteGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Tests\Feature\Generators;

use Tests\TestCase;
use Blueprint\Blueprint;
use Blueprint\Generators\RouteGenerator;
use Blueprint\Lexers\StatementLexer;
use Tests\TestCase;
use Blueprint\Generators\RouteGenerator;

/**
* @see RouteGenerator
Expand Down Expand Up @@ -57,7 +57,6 @@ public function output_writes_migration_for_route_tree($definition, $routes)
$this->assertEquals(['updated' => [$path]], $this->subject->output($tree));
}


public function controllerTreeDataProvider()
{
return [
Expand Down