Skip to content

Commit b221989

Browse files
New command to load existing models for reference (#69)
1 parent ffb97b1 commit b221989

File tree

17 files changed

+870
-42
lines changed

17 files changed

+870
-42
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"symfony/yaml": "^4.3|^5.0",
1212
"illuminate/console": "^6.0|^7.0",
1313
"illuminate/filesystem": "^6.0|^7.0",
14-
"illuminate/support": "^6.0|^7.0"
14+
"illuminate/support": "^6.0|^7.0",
15+
"doctrine/dbal": "^2.9"
1516
},
1617
"require-dev": {
1718
"phpunit/phpunit": "^8.0|^9.0",

composer.lock

Lines changed: 251 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BlueprintServiceProvider.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Blueprint;
44

5+
use Blueprint\Commands\BlueprintCommand;
6+
use Blueprint\Commands\EraseCommand;
7+
use Blueprint\Commands\TraceCommand;
58
use Illuminate\Contracts\Support\DeferrableProvider;
69
use Illuminate\Support\Facades\File;
710
use Illuminate\Support\ServiceProvider;
@@ -20,7 +23,7 @@ public function boot()
2023
}
2124

2225
$this->publishes([
23-
__DIR__.'/../config/blueprint.php' => config_path('blueprint.php'),
26+
__DIR__ . '/../config/blueprint.php' => config_path('blueprint.php'),
2427
]);
2528
}
2629

@@ -32,7 +35,7 @@ public function boot()
3235
public function register()
3336
{
3437
$this->mergeConfigFrom(
35-
__DIR__.'/../config/blueprint.php', 'blueprint'
38+
__DIR__ . '/../config/blueprint.php', 'blueprint'
3639
);
3740

3841
File::mixin(new FileMixins());
@@ -42,12 +45,16 @@ function ($app) {
4245
return new BlueprintCommand($app['files']);
4346
}
4447
);
45-
4648
$this->app->bind('command.blueprint.erase',
4749
function ($app) {
4850
return new EraseCommand($app['files']);
4951
}
5052
);
53+
$this->app->bind('command.blueprint.trace',
54+
function ($app) {
55+
return new TraceCommand($app['files']);
56+
}
57+
);
5158

5259
$this->app->singleton(Blueprint::class, function ($app) {
5360
$blueprint = new Blueprint();
@@ -74,6 +81,7 @@ function ($app) {
7481
$this->commands([
7582
'command.blueprint.build',
7683
'command.blueprint.erase',
84+
'command.blueprint.trace',
7785
]);
7886
}
7987

@@ -87,6 +95,7 @@ public function provides()
8795
return [
8896
'command.blueprint.build',
8997
'command.blueprint.erase',
98+
'command.blueprint.trace',
9099
Blueprint::class,
91100
];
92101
}

src/Builder.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22

33
namespace Blueprint;
44

5+
use Illuminate\Filesystem\Filesystem;
6+
57
class Builder
68
{
7-
public static function execute(Blueprint $blueprint, string $draft)
9+
public static function execute(Blueprint $blueprint, Filesystem $files, string $draft)
810
{
9-
// TODO: read in previous models...
11+
$cache = [];
12+
if ($files->exists('.blueprint')) {
13+
$cache = $blueprint->parse($files->get('.blueprint'));
14+
}
1015

11-
$tokens = $blueprint->parse($draft);
16+
$tokens = $blueprint->parse($files->get($draft));
17+
$tokens['cache'] = $cache['models'] ?? [];
1218
$registry = $blueprint->analyze($tokens);
1319
$generated = $blueprint->generate($registry);
1420

15-
// TODO: save to .blueprint
21+
$models = array_merge($tokens['cache'], $tokens['models'] ?? []);
22+
23+
$files->put(
24+
'.blueprint',
25+
$blueprint->dump($generated + ($models ? ['models' => $models] : []))
26+
);
1627

1728
return $generated;
1829
}

0 commit comments

Comments
 (0)