-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
PackageManifest.php
108 lines (93 loc) · 2.97 KB
/
PackageManifest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Roots\Acorn;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\PackageManifest as FoundationPackageManifest;
class PackageManifest extends FoundationPackageManifest
{
/**
* The composer.json paths.
*
* @var string[]
*/
public $composerPaths;
/**
* Create a new package manifest instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @param string[] $composerPaths
* @param string $manifestPath
* @return void
*/
public function __construct(Filesystem $files, array $composerPaths, $manifestPath)
{
$this->files = $files;
$this->composerPaths = $composerPaths;
$this->manifestPath = $manifestPath;
}
/**
* Get the current package manifest.
*
* @return array
*/
public function getManifest()
{
return parent::getManifest();
}
/**
* Build the manifest and write it to disk.
*
* @return void
*/
public function build()
{
$packages = array_reduce($this->composerPaths, function ($all, $path) {
$packages = [];
if ($this->files->exists($path)) {
$installed = json_decode($this->files->get($path), true);
$packages = $installed['packages'] ?? $installed;
}
$ignoreAll = in_array('*', $ignore = $this->packagesToIgnore());
return collect($packages)->mapWithKeys(function ($package) use ($path) {
return [
$this->format($package['name'], dirname($path, 2)) =>
$package['extra']['acorn'] ?? $package['extra']['laravel'] ?? []
];
})->each(function ($configuration) use (&$ignore) {
$ignore = array_merge($ignore, $configuration['dont-discover'] ?? []);
})->reject(function ($configuration, $package) use ($ignore, $ignoreAll) {
return $ignoreAll || in_array($package, $ignore);
})->filter()->merge($all)->all();
}, []);
$this->write($packages);
}
/**
* Format the given package name.
*
* @param string $package
* @param string $vendorPath
* @return string
*/
protected function format($package, $vendorPath = null)
{
return str_replace($vendorPath . '/', '', $package);
}
/**
* Get all of the package names that should be ignored.
*
* @return array
*/
protected function packagesToIgnore()
{
return array_reduce($this->composerPaths, function ($ignore, $path) {
if (! $this->files->exists($path)) {
return $ignore;
}
$package = json_decode($this->files->get($path), true);
return array_merge(
$ignore,
$package['extra']['laravel']['dont-discover'] ?? [],
$package['extra']['acorn']['dont-discover'] ?? []
);
}, []);
}
}