Skip to content

Commit b4f1387

Browse files
committed
Add publish command
1 parent b92e59e commit b4f1387

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/Commands/Publish.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php namespace Tatter\Assets\Commands;
2+
3+
use CodeIgniter\CLI\BaseCommand;
4+
use CodeIgniter\CLI\CLI;
5+
use Config\Services;
6+
7+
class Publish extends BaseCommand
8+
{
9+
protected $group = 'Publication';
10+
protected $name = 'assets:publish';
11+
protected $description = "Scans for manifest files and publishes matching assets.";
12+
protected $usage = "assets:publish";
13+
14+
public function run(array $params)
15+
{
16+
helper('inflector');
17+
$manifests = Services::manifests();
18+
19+
$count = 0;
20+
foreach ($manifests->locate() as $path)
21+
{
22+
if (! $manifest = $manifests->parse($path))
23+
{
24+
CLI::write('Unable to parse manifest from ' . $path);
25+
$this->displayMessages($manifests->getMessages());
26+
continue;
27+
}
28+
29+
if (! $manifests->publish($manifest))
30+
{
31+
CLI::write('Unable to publish manifest from ' . $path);
32+
$this->displayMessages($manifests->getMessages());
33+
continue;
34+
}
35+
36+
CLI::write('Published ' . basename($path));
37+
$count++;
38+
}
39+
40+
if ($count == 0)
41+
{
42+
CLI::write('No manifests published.');
43+
}
44+
else
45+
{
46+
CLI::write(counted($count, 'manifests') . ' published.', 'green');
47+
}
48+
}
49+
50+
protected function displayMessages(array $messages)
51+
{
52+
foreach ($messages as $message)
53+
{
54+
CLI::write(...$message);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)