Skip to content

Commit 9c8f156

Browse files
committed
Display list of generates files
1 parent a74246c commit 9c8f156

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

src/Blueprint.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ public function analyze(array $tokens)
3333
return $registry;
3434
}
3535

36-
public function generate(array $tree)
36+
public function generate(array $tree): array
3737
{
38+
$components = [];
39+
3840
foreach ($this->generators as $generator) {
39-
$generator->output($tree);
41+
$components = array_merge_recursive($components, $generator->output($tree));
4042
}
43+
44+
return $components;
4145
}
4246

4347
public function registerLexer(Lexer $lexer)

src/BlueprintCommand.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Filesystem\Filesystem;
7+
use Illuminate\Support\Str;
78
use Symfony\Component\Console\Input\InputArgument;
89

910
class BlueprintCommand extends Command
@@ -55,7 +56,16 @@ public function handle()
5556

5657
$tokens = $blueprint->parse($contents);
5758
$registry = $blueprint->analyze($tokens);
58-
$blueprint->generate($registry);
59+
$generated = $blueprint->generate($registry);
60+
61+
collect($generated)->each(function ($files, $action) {
62+
$this->line(Str::studly($action) . ':', $this->outputStyle($action));
63+
collect($files)->each(function ($file) {
64+
$this->line('- ' . $file);
65+
});
66+
67+
$this->line('');
68+
});
5969
}
6070

6171

@@ -80,4 +90,15 @@ protected function getOptions()
8090
{
8191
return [];
8292
}
93+
94+
private function outputStyle($action)
95+
{
96+
if ($action === 'deleted') {
97+
return 'error';
98+
} elseif ($action === 'updated') {
99+
return 'warning';
100+
}
101+
102+
return 'info';
103+
}
83104
}

tests/Feature/BlueprintTest.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,34 @@ public function analyze_uses_register_lexers_to_analyze_tokens()
171171
/**
172172
* @test
173173
*/
174-
public function generate_uses_register_generators_to_generate_code()
174+
public function generate_uses_registered_generators_and_returns_generated_files()
175175
{
176-
$generator = \Mockery::mock(Generator::class);
176+
$generatorOne = \Mockery::mock(Generator::class);
177177
$tree = ['branch' => ['code', 'attributes']];
178-
$generator->expects('output')
179-
->with($tree);
178+
$generatorOne->expects('output')
179+
->with($tree)
180+
->andReturn([
181+
'created' => ['one/new.php'],
182+
'updated' => ['one/existing.php'],
183+
'deleted' => ['one/trashed.php']
184+
]);
185+
186+
$generatorTwo = \Mockery::mock(Generator::class);
187+
$generatorTwo->expects('output')
188+
->with($tree)
189+
->andReturn([
190+
'created' => ['two/new.php'],
191+
'updated' => ['two/existing.php'],
192+
'deleted' => ['two/trashed.php']
193+
]);
194+
195+
$this->subject->registerGenerator($generatorOne);
196+
$this->subject->registerGenerator($generatorTwo);
180197

181-
$this->subject->registerGenerator($generator);
182-
183-
$this->subject->generate($tree);
198+
$this->assertEquals([
199+
'created' => ['one/new.php', 'two/new.php'],
200+
'updated' => ['one/existing.php', 'two/existing.php'],
201+
'deleted' => ['one/trashed.php', 'two/trashed.php'],
202+
], $this->subject->generate($tree));
184203
}
185204
}

0 commit comments

Comments
 (0)