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
36 changes: 18 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,20 @@
],
"license": "MIT",
"require": {
"doctrine/dbal": "^2.9 || ^3.0",
"illuminate/console": "^6.0 || ^7.0 || ^8.0",
"illuminate/filesystem": "^6.0 || ^7.0 || ^8.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0",
"laravel-shift/faker-registry": "^0.1",
"symfony/yaml": "^4.3|^5.0",
"illuminate/console": "^6.0|^7.0|^8.0",
"illuminate/filesystem": "^6.0|^7.0|^8.0",
"illuminate/support": "^6.0|^7.0|^8.0",
"doctrine/dbal": "^2.9|^3.0"
"symfony/yaml": "^4.3 || ^5.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.3",
"mockery/mockery": "^1.3",
"orchestra/testbench": "^4.0|^5.0|^6.0"
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0",
"phpunit/phpunit": "^8.0 || ^9.3"
},
"autoload": {
"psr-4": {
"Blueprint\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
"suggest": {
"jasonmccreary/laravel-test-assertions": "Required to use additional assertions in generated tests (^1.0)."
},
"config": {
"sort-packages": true
Expand All @@ -40,7 +33,14 @@
]
}
},
"suggest": {
"jasonmccreary/laravel-test-assertions": "Required to use additional assertions in generated tests (^1.0)."
"autoload": {
"psr-4": {
"Blueprint\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}
58 changes: 39 additions & 19 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,45 @@ public function parse($content, $strip_dashes = true)
$content = preg_replace('/^(\s*)-\s*/m', '\1', $content);
}

$content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?)$/mi', function ($matches) {
return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2];
}, $content);

$content = preg_replace_callback('/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?): true$/mi', function ($matches) {
return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2];
}, $content);

$content = preg_replace_callback('/^(\s+)resource?$/mi', function ($matches) {
return $matches[1] . 'resource: web';
}, $content);

$content = preg_replace_callback('/^(\s+)invokable?$/mi', function ($matches) {
return $matches[1].'invokable: true';
}, $content);

$content = preg_replace_callback('/^(\s+)uuid(: true)?$/mi', function ($matches) {
return $matches[1] . 'id: uuid primary';
}, $content);
$content = preg_replace_callback(
'/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?)$/mi',
function ($matches) {
return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2];
},
$content
);

$content = preg_replace_callback(
'/^(\s+)(id|timestamps(Tz)?|softDeletes(Tz)?): true$/mi',
function ($matches) {
return $matches[1] . strtolower($matches[2]) . ': ' . $matches[2];
},
$content
);

$content = preg_replace_callback(
'/^(\s+)resource?$/mi',
function ($matches) {
return $matches[1] . 'resource: web';
},
$content
);

$content = preg_replace_callback(
'/^(\s+)invokable?$/mi',
function ($matches) {
return $matches[1] . 'invokable: true';
},
$content
);

$content = preg_replace_callback(
'/^(\s+)uuid(: true)?$/mi',
function ($matches) {
return $matches[1] . 'id: uuid primary';
},
$content
);

return Yaml::parse($content);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

class Builder
{
public function execute(Blueprint $blueprint, Filesystem $files, string $draft, string $only = '', string $skip = '', $overwriteMigrations = false)
public function execute(Blueprint $blueprint, Filesystem $filesystem, string $draft, string $only = '', string $skip = '', $overwriteMigrations = false)
{
$cache = [];
if ($files->exists('.blueprint')) {
$cache = $blueprint->parse($files->get('.blueprint'));
if ($filesystem->exists('.blueprint')) {
$cache = $blueprint->parse($filesystem->get('.blueprint'));
}

$contents = $files->get($draft);
$contents = $filesystem->get($draft);
$using_indexes = preg_match('/^\s+indexes:\R/m', $contents) !== 1;

$tokens = $blueprint->parse($contents, $using_indexes);
Expand All @@ -27,7 +27,7 @@ public function execute(Blueprint $blueprint, Filesystem $files, string $draft,

$models = array_merge($tokens['cache'], $tokens['models'] ?? []);

$files->put(
$filesystem->put(
'.blueprint',
$blueprint->dump($generated + ($models ? ['models' => $models] : []))
);
Expand Down
36 changes: 20 additions & 16 deletions src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ class BuildCommand extends Command
protected $description = 'Build components from a Blueprint draft';

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

/** @var Builder */
private $builder;

/**
* @param Filesystem $files
* @param Builder $builder
* @param Filesystem $filesystem
* @param Builder $builder
*/
public function __construct(Filesystem $files, Builder $builder)
public function __construct(Filesystem $filesystem, Builder $builder)
{
parent::__construct();

$this->files = $files;
$this->filesystem = $filesystem;
$this->builder = $builder;
}

public function handle()
{
$file = $this->argument('draft') ?? $this->defaultDraftFile();

if (!$this->files->exists($file)) {
if (!$this->filesystem->exists($file)) {
$this->error('Draft file could not be found: ' . ($file ?: 'draft.yaml'));
return 1;
}
Expand All @@ -62,16 +62,20 @@ public function handle()
$overwriteMigrations = $this->option('overwrite-migrations') ?: false;

$blueprint = resolve(Blueprint::class);
$generated = $this->builder->execute($blueprint, $this->files, $file, $only, $skip, $overwriteMigrations);

collect($generated)->each(function ($files, $action) {
$this->line(Str::studly($action) . ':', $this->outputStyle($action));
collect($files)->each(function ($file) {
$this->line('- ' . $file);
});

$this->line('');
});
$generated = $this->builder->execute($blueprint, $this->filesystem, $file, $only, $skip, $overwriteMigrations);

collect($generated)->each(
function ($files, $action) {
$this->line(Str::studly($action) . ':', $this->outputStyle($action));
collect($files)->each(
function ($file) {
$this->line('- ' . $file);
}
);

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

/**
Expand Down
50 changes: 25 additions & 25 deletions src/Commands/EraseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ class EraseCommand extends Command
*/
protected $description = 'Erase components created from last Blueprint build';

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

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

$this->files = $files;
$this->filesystem = $filesystem;
}

/**
Expand All @@ -44,33 +40,37 @@ public function __construct(Filesystem $files)
*/
public function handle()
{
$contents = $this->files->get('.blueprint');
$contents = $this->filesystem->get('.blueprint');

$blueprint = resolve(Blueprint::class);

$generated = $blueprint->parse($contents, false);

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

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

$this->line('');
}

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

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

unset($generated['created']);
unset($generated['updated']);

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

$this->call('blueprint:trace');
}
Expand Down
12 changes: 6 additions & 6 deletions src/Commands/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ class NewCommand extends Command
protected $description = 'Create a draft.yaml file and load existing models';

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

/**
* @param Filesystem $files
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $files)
public function __construct(Filesystem $filesystem)
{
parent::__construct();

$this->files = $files;
$this->filesystem = $filesystem;
}

/**
Expand All @@ -41,8 +41,8 @@ public function __construct(Filesystem $files)
*/
public function handle()
{
if (!$this->files->exists('draft.yaml')) {
$this->files->put('draft.yaml', $this->files->stub('draft.stub'));
if (!$this->filesystem->exists('draft.yaml')) {
$this->filesystem->put('draft.yaml', $this->filesystem->stub('draft.stub'));

$this->info('Created example draft.yaml');
}
Expand Down
12 changes: 6 additions & 6 deletions src/Commands/TraceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ class TraceCommand extends Command
protected $description = 'Create definitions for existing models to reference in new drafts';

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

/** @var Tracer */
private $tracer;

/**
* @param Filesystem $files
* @param Tracer $tracer
* @param Filesystem $filesystem
* @param Tracer $tracer
*/
public function __construct(Filesystem $files, Tracer $tracer)
public function __construct(Filesystem $filesystem, Tracer $tracer)
{
parent::__construct();

$this->files = $files;
$this->filesystem = $filesystem;
$this->tracer = $tracer;
}

Expand All @@ -50,7 +50,7 @@ public function __construct(Filesystem $files, Tracer $tracer)
public function handle()
{
$blueprint = resolve(Blueprint::class);
$definitions = $this->tracer->execute($blueprint, $this->files);
$definitions = $this->tracer->execute($blueprint, $this->filesystem);

if (empty($definitions)) {
$this->error('No models found');
Expand Down
6 changes: 2 additions & 4 deletions src/Contracts/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace Blueprint\Contracts;

use Blueprint\Tree;
use Illuminate\Filesystem\Filesystem;

interface Generator
{
/**
* @param \Illuminate\Contracts\Filesystem\Filesystem
*/
public function __construct($files);
public function __construct(Filesystem $files);

public function output(Tree $tree): array;

Expand Down
Loading