Skip to content

Commit 7a657e4

Browse files
committed
Devlink Icons and verbose
1 parent c729bdc commit 7a657e4

File tree

3 files changed

+191
-155
lines changed

3 files changed

+191
-155
lines changed

src/Console/Traits/Check.php

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,139 @@ private function checkUpdated(): bool
145145

146146
return true;
147147
}
148+
149+
private function getInstalledVersion(string $name, array $package): ?string
150+
{
151+
$packageName = $this->getPackageName($name, $package);
152+
if (! $packageName) {
153+
return null;
154+
}
155+
156+
$path = $package['path'] ?? '';
157+
if ($path && ! str_contains($path, 'disabled/')) {
158+
$composerJson = realpath(base_path($path)).'/composer.json';
159+
if (file_exists($composerJson)) {
160+
$composerData = json_decode(file_get_contents($composerJson), true);
161+
162+
return $composerData['version'] ?? 'dev-main';
163+
}
164+
}
165+
166+
$composerLock = base_path('composer.lock');
167+
if (! file_exists($composerLock)) {
168+
return null;
169+
}
170+
171+
$lockData = json_decode(file_get_contents($composerLock), true);
172+
if (json_last_error() !== JSON_ERROR_NONE) {
173+
info("Invalid composer.lock JSON for $name");
174+
175+
return null;
176+
}
177+
178+
foreach ([$lockData['packages'] ?? [], $lockData['packages-dev'] ?? []] as $packages) {
179+
foreach ($packages as $pkg) {
180+
if (($pkg['name'] ?? '') === $packageName) {
181+
return $pkg['version'] ?? null;
182+
}
183+
}
184+
}
185+
186+
return null;
187+
}
188+
189+
private function getShortPath(array $row): string
190+
{
191+
if (($row['type'] ?? '') === 'local') {
192+
return '-';
193+
}
194+
195+
$privateBasePath = config('devlink.private_base_path');
196+
if (($row['type'] ?? '') === 'private' && $privateBasePath === 'disabled') {
197+
return '- enable private path in config -';
198+
}
199+
200+
$path = $this->packages[$row['name']]['path'] ?? '';
201+
if (empty($path)) {
202+
return '-';
203+
}
204+
205+
if (str_starts_with($path, '../')) {
206+
return $path;
207+
}
208+
209+
$basePath = base_path();
210+
if (str_starts_with($path, $basePath)) {
211+
return substr($path, strlen($basePath) + 1);
212+
}
213+
214+
return $path;
215+
}
216+
217+
private function getPackageName(string $name, array $package): ?string
218+
{
219+
$isLocal = ($package['type'] ?? '') === 'local';
220+
$path = $isLocal ? "packages/$name" : ($package['path'] ?? '');
221+
222+
if (! $path || str_contains($path, 'disabled/')) {
223+
return null;
224+
}
225+
226+
if (str_starts_with($path, '../')) {
227+
$path = realpath(base_path($path));
228+
}
229+
230+
$composerJson = "$path/composer.json";
231+
if (! file_exists($composerJson)) {
232+
return null;
233+
}
234+
235+
$data = json_decode(file_get_contents($composerJson), true);
236+
237+
return $data['name'] ?? null;
238+
}
239+
240+
private function arePackagesInSync(array $packages): bool
241+
{
242+
$composerJson = base_path('composer.json');
243+
if (! file_exists($composerJson)) {
244+
return false;
245+
}
246+
247+
$composerData = json_decode(file_get_contents($composerJson), true);
248+
if (! $composerData) {
249+
return false;
250+
}
251+
252+
$composerRequire = array_merge(
253+
$composerData['require'] ?? [],
254+
$composerData['require-dev'] ?? []
255+
);
256+
257+
foreach ($packages as $package) {
258+
$packageName = $this->getPackageName($package['name'], $package['config']);
259+
if (! $packageName) {
260+
continue;
261+
}
262+
263+
$expectedPath = $package['config']['path'] ?? '';
264+
if (empty($expectedPath)) {
265+
continue;
266+
}
267+
268+
if (! isset($composerRequire[$packageName])) {
269+
return false;
270+
}
271+
272+
$composerPath = $composerRequire[$packageName];
273+
if (str_contains($composerPath, 'path:')) {
274+
$composerPath = trim(str_replace('path:', '', $composerPath));
275+
if ($composerPath !== $expectedPath) {
276+
return false;
277+
}
278+
}
279+
}
280+
281+
return true;
282+
}
148283
}

src/Console/Traits/Link.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -319,28 +319,6 @@ private function updateComposerJson(): void
319319
}
320320
}
321321

322-
private function getPackageName(string $name, array $package): ?string
323-
{
324-
$isLocal = ($package['type'] ?? '') === 'local';
325-
$path = $isLocal ? "packages/$name" : ($package['path'] ?? '');
326-
327-
if (! $path || ! is_dir($path)) {
328-
return null;
329-
}
330-
331-
$composerJson = "$path/composer.json";
332-
if (! file_exists($composerJson)) {
333-
return null;
334-
}
335-
336-
$data = json_decode(file_get_contents($composerJson), true);
337-
if (! isset($data['name'])) {
338-
return null;
339-
}
340-
341-
return $data['name'];
342-
}
343-
344322
private function createLinkedComposerJson(): void
345323
{
346324
if (! file_exists($this->composerJsonPath)) {

src/Console/Traits/Show.php

Lines changed: 56 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ trait Show
1111

1212
private const CROSS_MARK = "\u{2718}"; // ✘
1313

14+
private const STOP = "\u{1F6AB}"; // 🚫
15+
16+
private const ROCKET = "\u{1F680}"; // 🚀
17+
18+
private const FIRE = "\u{1F525}"; // 🔥
19+
20+
private const LINK = "\u{1F517}"; // 🔗
21+
22+
private const STAR = "\u{2B50}"; // ⭐
23+
1424
private function show(): void
1525
{
1626
$fullStatus = $this->check();
@@ -41,164 +51,77 @@ private function show(): void
4151

4252
table($headers, $rows);
4353

44-
$badge = '<fg=black;bg=yellow;options=bold> ';
45-
$updateBadge = '<fg=black;bg=yellow;options=bold> ';
54+
$icon = self::STOP;
55+
$badge = '<fg=gray;bg=black;options=bold> ';
56+
$updateBadge = '<fg=gray;bg=black;options=bold> ';
4657

4758
if ($fullStatus['status'] === 'error') {
48-
$badge = '<fg=black;bg=red;options=bold> ';
59+
$icon = self::STOP;
60+
$badge = '<fg=red;bg=black;options=bold> ';
4961
}
5062

5163
if ($fullStatus['status'] === 'deploy') {
52-
$badge = '<fg=black;bg=blue;options=bold> ';
64+
$icon = self::ROCKET;
65+
$badge = '<fg=blue;bg=black;options=bold> ';
5366
}
5467

5568
if ($fullStatus['status'] === 'linked') {
56-
$badge = '<fg=black;bg=green;options=bold> ';
69+
$icon = self::LINK;
70+
$badge = '<fg=green;bg=black;options=bold> ';
5771
}
5872

5973
if ($isInSync) {
60-
$updateBadge = '<fg=black;bg=green;options=bold> ';
74+
$updateIcon = self::STAR;
75+
$updateBadge = '<fg=green;bg=black;options=bold> ';
6176
} else {
62-
$updateBadge = '<fg=black;bg=red;options=bold> ';
77+
$updateIcon = self::FIRE;
78+
$updateBadge = '<fg=red;bg=black;options=bold> ';
6379
}
6480

65-
info(' '.$badge.strtoupper($fullStatus['status']).' </> '.$fullStatus['message']);
66-
info(' '.$updateBadge.'UPDATE </> '.($isInSync ? 'All packages are in sync with composer.json' : 'You need to run `php artisan devlink:link` to update the packages'));
67-
info(' ');
68-
}
81+
info(' '.$icon.$badge.strtoupper($fullStatus['status']).' </> '.$fullStatus['message']);
82+
info(' '.$updateIcon.$updateBadge.'UPDATE </> '.($isInSync ? 'All packages are in sync with composer.json' : 'You need to run `php artisan devlink:link` to update the packages'));
6983

70-
private function getInstalledVersion(string $name, array $package): ?string
71-
{
72-
$packageName = $this->getPackageName($name, $package);
73-
if (! $packageName) {
74-
return null;
75-
}
76-
77-
$path = $package['path'] ?? '';
78-
if ($path && ! str_contains($path, 'disabled/')) {
79-
$composerJson = realpath(base_path($path)).'/composer.json';
80-
if (file_exists($composerJson)) {
81-
$composerData = json_decode(file_get_contents($composerJson), true);
82-
83-
return $composerData['version'] ?? 'dev-main';
84-
}
85-
}
86-
87-
$composerLock = base_path('composer.lock');
88-
if (! file_exists($composerLock)) {
89-
return null;
90-
}
84+
if (! $isInSync && $this->getOutput()->isVerbose()) {
85+
info(' ');
86+
info('Detailed sync status:');
9187

92-
$lockData = json_decode(file_get_contents($composerLock), true);
93-
if (json_last_error() !== JSON_ERROR_NONE) {
94-
info("Invalid composer.lock JSON for $name");
95-
96-
return null;
97-
}
98-
99-
foreach ([$lockData['packages'] ?? [], $lockData['packages-dev'] ?? []] as $packages) {
100-
foreach ($packages as $pkg) {
101-
if (($pkg['name'] ?? '') === $packageName) {
102-
return $pkg['version'] ?? null;
88+
foreach ($fullStatus['packages'] as $package) {
89+
$packageName = $this->getPackageName($package['name'], $package['config']);
90+
if (! $packageName) {
91+
continue;
10392
}
104-
}
105-
}
106-
107-
return null;
108-
}
109-
110-
private function getShortPath(array $row): string
111-
{
112-
if (($row['type'] ?? '') === 'local') {
113-
return '-';
114-
}
115-
116-
$privateBasePath = config('devlink.private_base_path');
117-
if (($row['type'] ?? '') === 'private' && $privateBasePath === 'disabled') {
118-
return '- enable private path in config -';
119-
}
120-
121-
$path = $this->packages[$row['name']]['path'] ?? '';
122-
if (empty($path)) {
123-
return '-';
124-
}
12593

126-
if (str_starts_with($path, '../')) {
127-
return $path;
128-
}
129-
130-
$basePath = base_path();
131-
if (str_starts_with($path, $basePath)) {
132-
return substr($path, strlen($basePath) + 1);
133-
}
134-
135-
return $path;
136-
}
137-
138-
private function getPackageName(string $name, array $package): ?string
139-
{
140-
$isLocal = ($package['type'] ?? '') === 'local';
141-
$path = $isLocal ? "packages/$name" : ($package['path'] ?? '');
142-
143-
if (! $path || str_contains($path, 'disabled/')) {
144-
return null;
145-
}
146-
147-
if (str_starts_with($path, '../')) {
148-
$path = realpath(base_path($path));
149-
}
150-
151-
$composerJson = "$path/composer.json";
152-
if (! file_exists($composerJson)) {
153-
return null;
154-
}
155-
156-
$data = json_decode(file_get_contents($composerJson), true);
157-
158-
return $data['name'] ?? null;
159-
}
160-
161-
private function arePackagesInSync(array $packages): bool
162-
{
163-
$composerJson = base_path('composer.json');
164-
if (! file_exists($composerJson)) {
165-
return false;
166-
}
167-
168-
$composerData = json_decode(file_get_contents($composerJson), true);
169-
if (! $composerData) {
170-
return false;
171-
}
172-
173-
$composerRequire = array_merge(
174-
$composerData['require'] ?? [],
175-
$composerData['require-dev'] ?? []
176-
);
94+
$expectedPath = $package['config']['path'] ?? '';
95+
if (empty($expectedPath)) {
96+
continue;
97+
}
17798

178-
foreach ($packages as $package) {
179-
$packageName = $this->getPackageName($package['name'], $package['config']);
180-
if (! $packageName) {
181-
continue;
182-
}
99+
$composerJson = json_decode(file_get_contents($this->composerJsonPath), true);
100+
$composerRequire = array_merge(
101+
$composerJson['require'] ?? [],
102+
$composerJson['require-dev'] ?? []
103+
);
183104

184-
$expectedPath = $package['config']['path'] ?? '';
185-
if (empty($expectedPath)) {
186-
continue;
187-
}
105+
if (! isset($composerRequire[$packageName])) {
106+
info(" <fg=red>✘</> {$packageName}: Not found in composer.json requirements");
188107

189-
if (! isset($composerRequire[$packageName])) {
190-
return false;
191-
}
108+
continue;
109+
}
192110

193-
$composerPath = $composerRequire[$packageName];
194-
if (str_contains($composerPath, 'path:')) {
195-
$composerPath = trim(str_replace('path:', '', $composerPath));
196-
if ($composerPath !== $expectedPath) {
197-
return false;
111+
$composerPath = $composerRequire[$packageName];
112+
if (str_contains($composerPath, 'path:')) {
113+
$composerPath = trim(str_replace('path:', '', $composerPath));
114+
if ($composerPath !== $expectedPath) {
115+
info(" <fg=red>✘</> {$packageName}: Path mismatch");
116+
info(" Expected: {$expectedPath}");
117+
info(" Found: {$composerPath}");
118+
} else {
119+
info(" <fg=green>✓</> {$packageName}: Correctly linked");
120+
}
198121
}
199122
}
200123
}
201124

202-
return true;
125+
info(' ');
203126
}
204127
}

0 commit comments

Comments
 (0)