Skip to content

Commit e005f33

Browse files
Daniel BerthereauDaniel Berthereau
authored andcommitted
Added script to install composer dependencies for add-ons installed manually.
1 parent e8ac17f commit e005f33

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* Install composer dependencies for a git-cloned module or theme.
5+
*
6+
* For add-ons installed via git clone in modules/ or themes/, dependencies
7+
* are not installed automatically. This script reads the add-on composer.json
8+
* and installs its dependencies via the root Omeka composer.
9+
*
10+
* Note: Add-ons installed via `composer require` (in composer-addons/modules/ or
11+
* composer-addons/themes/) have their dependencies installed automatically.
12+
*
13+
* Usage:
14+
* php application/data/scripts/install-addon-deps.php ModuleName
15+
* php application/data/scripts/install-addon-deps.php --theme theme-name
16+
* php application/data/scripts/install-addon-deps.php --dry-run ModuleName
17+
*
18+
* Options:
19+
* --theme Specify a theme instead of a module
20+
* --dry-run Show what would be installed without actually installing
21+
*/
22+
$args = array_slice($argv, 1);
23+
$dryRun = false;
24+
$isTheme = false;
25+
$addonName = null;
26+
27+
foreach ($args as $arg) {
28+
if ($arg === '--dry-run') {
29+
$dryRun = true;
30+
} elseif ($arg === '--theme') {
31+
$isTheme = true;
32+
} elseif (strpos($arg, '--') !== 0) {
33+
$addonName = $arg;
34+
}
35+
}
36+
37+
if (!$addonName) {
38+
echo "Usage: php application/data/scripts/install-addon-deps.php [--dry-run] [--theme] Name\n";
39+
echo "\nOptions:\n";
40+
echo " --theme Specify a theme instead of a module\n";
41+
echo " --dry-run Show what would be installed without actually installing\n";
42+
exit(1);
43+
}
44+
45+
// Find addon path
46+
if ($isTheme) {
47+
$possiblePaths = [
48+
dirname(__DIR__, 3) . '/themes/' . $addonName,
49+
dirname(__DIR__, 3) . '/composer-addons/themes/' . $addonName,
50+
];
51+
$addonType = 'Theme';
52+
} else {
53+
$possiblePaths = [
54+
dirname(__DIR__, 3) . '/modules/' . $addonName,
55+
dirname(__DIR__, 3) . '/composer-addons/modules/' . $addonName,
56+
];
57+
$addonType = 'Module';
58+
}
59+
60+
$addonPath = null;
61+
foreach ($possiblePaths as $path) {
62+
if (is_dir($path)) {
63+
$addonPath = $path;
64+
break;
65+
}
66+
}
67+
68+
if (!$addonPath) {
69+
echo "Error: $addonType '$addonName' not found.\n";
70+
exit(1);
71+
}
72+
73+
$composerJson = $addonPath . '/composer.json';
74+
if (!file_exists($composerJson)) {
75+
echo "Error: No composer.json found in $addonPath\n";
76+
exit(1);
77+
}
78+
79+
$json = json_decode(file_get_contents($composerJson), true);
80+
if (!$json) {
81+
echo "Error: Invalid composer.json\n";
82+
exit(1);
83+
}
84+
85+
$require = $json['require'] ?? [];
86+
87+
if (empty($require)) {
88+
echo "No dependencies to install for $addonName.\n";
89+
exit(0);
90+
}
91+
92+
// Filter out packages provided by Omeka or PHP
93+
$toInstall = [];
94+
foreach ($require as $package => $version) {
95+
// Skip Omeka core packages (provided by Omeka)
96+
if (in_array($package, ['omeka/omeka-s', 'omeka/omeka-s-core'])) {
97+
continue;
98+
}
99+
// Skip PHP extensions
100+
if (strpos($package, 'ext-') === 0) {
101+
continue;
102+
}
103+
// Skip PHP version constraint
104+
if ($package === 'php') {
105+
continue;
106+
}
107+
$toInstall[$package] = $version;
108+
}
109+
110+
if (empty($toInstall)) {
111+
echo "No external dependencies to install for $addonName.\n";
112+
exit(0);
113+
}
114+
115+
echo "Dependencies for $addonName:\n";
116+
foreach ($toInstall as $package => $version) {
117+
echo " - $package: $version\n";
118+
}
119+
120+
if ($dryRun) {
121+
echo "\n[Dry run] Would run:\n";
122+
echo " composer require " . implode(' ', array_keys($toInstall)) . "\n";
123+
exit(0);
124+
}
125+
126+
echo "\nInstalling...\n";
127+
128+
$packages = implode(' ', array_map(function ($pkg, $ver) {
129+
// Use version constraint if specific, otherwise let composer decide
130+
if (preg_match('/^\^|~|>=|<=|>|<|\*/', $ver)) {
131+
return escapeshellarg("$pkg:$ver");
132+
}
133+
return escapeshellarg($pkg);
134+
}, array_keys($toInstall), $toInstall));
135+
136+
$command = "cd " . escapeshellarg(dirname(__DIR__, 3)) . " && composer require $packages --no-interaction 2>&1";
137+
138+
echo "Running: composer require " . implode(' ', array_keys($toInstall)) . "\n\n";
139+
140+
passthru($command, $exitCode);
141+
142+
exit($exitCode);

0 commit comments

Comments
 (0)