-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.php
133 lines (124 loc) · 4.99 KB
/
build.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
const INSTALLER_VERSION = "2";
$repoVersions = [2, 3];
$types = ["wpackagist-plugin", "wordpress-plugin", "wpackagist-muplugin", "wordpress-muplugin", "library"];
function createPackage($tag, $alias = null, $type = "wpackagist-plugin", $repoVersion = 2)
{
$dependencies = [
"pivvenit/acf-pro-installer" => getInstallerVersion($tag)
];
if ($repoVersion == 3) {
$dependencies["composer/installers"] = "^1.0 || ^2.0";
}
$downloadurl = getDownloadUrl($tag);
return [
"name" => "advanced-custom-fields/advanced-custom-fields-pro",
"description" => "Advanced Custom Fields PRO",
"version" => $alias ?? $tag,
"type" => $type,
"license" => "GPL-2.0-or-later",
"authors" => [
(object)[
"name" => "Elliot Condon",
"homepage" => "http://www.elliotcondon.com",
"role" => "Maintainer"
],
(object)[
"name" => "PivvenIT",
"homepage" => "https://pivvenit.nl",
"role" => "Composer Repository maintainer"
]
],
"support" => (object)[
"docs" => "https://www.advancedcustomfields.com/resources/",
"forum" => "https://support.advancedcustomfields.com/topics/"
],
"homepage" => "https://www.advancedcustomfields.com/",
"keywords" => "acf, advanced, custom, field, fields, form, repeater, content",
"dist" => (object)[
"type" => "zip",
"url" => "{$downloadurl}{$tag}"
],
"require" => (object)$dependencies
];
}
/**
* @return string
*/
function getInstallerVersion($tag): string
{
$semver = getSemver($tag);
['major' => $major, 'minor' => $minor, 'patch' => $patch] = $semver;
if (((int)$major == 5 && (int)$minor < 8) || ((int)$major == 5 && (int)$minor == 8 && (int)$patch < 8)) {
return "^" . INSTALLER_VERSION;
}
return "^2.4.0 || ^3.0";
}
/**
* @param $tag
* @return string
*/
function getDownloadUrl($tag): string
{
$semver = getSemver($tag);
$downloadurl = "https://connect.advancedcustomfields.com/v2/plugins/download?p=pro&t=";
['major' => $major, 'minor' => $minor, 'patch' => $patch] = $semver;
if (((int)$major == 5 && (int)$minor < 8) || ((int)$major == 5 && (int)$minor == 8 && (int)$patch < 8)) {
$downloadurl = "https://connect.advancedcustomfields.com/index.php?p=pro&a=download&t=";
}
return $downloadurl;
}
/**
* @param $tag
* @return array
*/
function getSemver($tag): array
{
$matches = [];
preg_match('/^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.*(?P<patch>0|[1-9]\d*)?(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/m',
$tag, $matches);
if (!array_key_exists('patch', $matches)) {
$matches['patch'] = 0;
}
return $matches;
}
// The url to retrieve all available Advanced Custom Fields packages from
$response = @file_get_contents("https://connect.advancedcustomfields.com/v2/plugins/get-info?p=pro");
if ($response === false) {
echo "Error retrieving package information";
die(1);
}
$json = json_decode($response);
foreach ($repoVersions as $repoVersion) {
foreach ($types as $type) {
$data = [];
$versions = [];
$versions['dev-master'] = createPackage($json->version, 'dev-master', $type, $repoVersion);
$versions[$json->version] = createPackage($json->version, null, $type, $repoVersion);
$availableVersions = $json->versions ?? [];
foreach ($availableVersions as $version) {
$versions[$version] = createPackage($version, null, $type, $repoVersion);
}
if (!is_array($availableVersions) || empty($availableVersions) || count($versions) == 2) {
echo "The list of packages is empty, probably the API has changed, not updating repository";
die(1);
}
$data['warning'] = "Advanced Custom fields has added native composer support, see https://www.advancedcustomfields.com/resources/installing-acf-pro-with-composer/." . PHP_EOL . "This repository will be shut down permanently on 1st of june 2023.";
$data["warning-versions"] = ">=0.0.0";
$data['packages'] = (object)[
"advanced-custom-fields/advanced-custom-fields-pro" => (object)$versions
];
$output = json_encode((object)$data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$outputDir = __DIR__ . "/composer/v" . $repoVersion;
if (!is_dir($outputDir . "/{$type}")) {
mkdir($outputDir . "/{$type}", 0777, true);
}
file_put_contents("{$outputDir}/{$type}/packages.json", $output);
if ($type == "wpackagist-plugin") {
file_put_contents("{$outputDir}/packages.json", $output);
}
}
}