-
Notifications
You must be signed in to change notification settings - Fork 6
/
hardcoded.php
72 lines (60 loc) · 2.42 KB
/
hardcoded.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
<?php
// Used to generate data for consts.php INSTALLER_TO_REPO_MINOR_VERSIONS
// Copy .cow.pat.json from the current release into the directory this script is being run from (file is .gitignored)
use SilverStripe\SupportedModules\MetaData;
$autoloadPath = __DIR__ . '/vendor/autoload.php';
if (!file_exists($autoloadPath)) {
throw new RuntimeException('Run composer install before this script');
}
require_once $autoloadPath;
include 'consts.php';
$filename = '.cow.pat.json';
if (!file_exists($filename)) {
throw new \RuntimeException("Copy $filename into the directory this is being called from");
}
$versions = [];
function repoName(string $name)
{
$prefix = '';
if (!preg_match('#^(cwp/)#', $name) &&
!preg_match('#(/recipe-|/silverstripe-|/comment-notifications$)#', $name)
) {
$prefix = 'silverstripe-';
}
if (preg_match('#(/agency-extensions|/starter-theme|/watea-theme)$#', $name)) {
$prefix = 'cwp-';
}
$name = preg_replace('#/agency-extensions$#', '/agencyextensions', $name);
return $prefix . explode('/', $name)[1];
}
function parseNode(string $name, stdClass $node, array &$versions)
{
$repoData = MetaData::getMetaDataByPackagistName($name);
$repoName = repoName($name);
if (
(!isset($repoData['lockstepped']) || !$repoData['lockstepped']) &&
(!isset($repoData['type']) || $repoData['type'] !== 'recipe') &&
!in_array($repoName, NO_INSTALLER_REPOS)
) {
preg_match('#^([0-9]+\.[0-9]+)#', $node->Version, $m);
$versions[$repoName] = $m[1];
}
foreach ((array) $node->Items as $itemName => $item) {
parseNode($itemName, $item, $versions);
}
}
foreach (json_decode(file_get_contents($filename)) as $itemName => $item) {
parseNode($itemName, $item, $versions);
}
ksort($versions);
foreach ($versions as $repoName => $version) {
echo " '$repoName' => '$version',\n";
}
// Find any repositories which were in the previous version that aren't in this one
$missing = array_diff(array_keys(INSTALLER_TO_REPO_MINOR_VERSIONS[array_key_last(INSTALLER_TO_REPO_MINOR_VERSIONS)]), array_keys($versions));
if (!empty($missing)) {
$formatColor = "\033[31m";
$endFormat = "\033[0m";
echo "\n" . $formatColor . 'Warning: The following modules were in the last release in INSTALLER_TO_REPO_MINOR_VERSIONS but are missing from .cow.pat.json:' . $endFormat . "\n";
echo implode("\n", $missing) . "\n";
}