-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.php
97 lines (79 loc) · 3.06 KB
/
generate.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
<?php
declare(strict_types=1);
namespace Inpsyde\WpStubs;
const WP_STUBS_DIR = __DIR__;
try {
if (!is_file(WP_STUBS_DIR . '/vendor/autoload.php')) {
throw new \Error("Please install via Composer first.");
}
require_once 'vendor/autoload.php';
if (!class_exists(\Symfony\Component\Process\ExecutableFinder::class)) {
throw new \Error("Please update Composer dependencies first.");
}
findZipMethods();
$toDownload = retrieveDownloadUrls(20);
$all = count($toDownload);
if ($all === 0) {
$repoBuilt = null;
if (!file_exists(__DIR__ . '/packages.json')) {
fwrite(STDOUT, "\nStubs generation completed. Updating now Composer repo");
$repoBuilt = buildComposerRepo(__DIR__);
}
exit(finalMessage(0, 0, $repoBuilt));
}
$success = 0;
$stubsDir = str_replace('\\', '/', WP_STUBS_DIR . '/stubs');
$latestDone = false;
$shortDone = [];
foreach ($toDownload as [$fullVer, $shortVer, $url]) {
fwrite(STDOUT, "\n");
$errMessage = "Stubs for WordPress '{$fullVer}' not created.";
try {
$wpPath = downloadWp($fullVer, $url);
if (!$wpPath) {
fwrite(STDOUT, "\n{$errMessage}");
continue;
}
fwrite(STDOUT, "\nGenerating stubs for WP '{$fullVer}'...");
$output = generateForWpPath($wpPath);
writeOutput($output, "{$stubsDir}/{$fullVer}.php", $fullVer)
? $success++
: fwrite(STDERR, "\nStubs for WP '{$fullVer}' not created.");
if (!$latestDone) {
$latestDone = true;
$all++;
writeOutput($output, "{$stubsDir}/latest.php", 'latest')
? $success++
: fwrite(STDERR, "\nStubs for WP latest not written.");
}
if ($shortVer === $fullVer) {
continue;
}
if (!empty($shortDone[$shortVer])) {
$doneShort = $shortDone[$shortVer];
fwrite(STDERR, "\nStubs for WP '{$shortVer}' already written from '{$doneShort}'.");
continue;
}
if (!writeOutput($output, "{$stubsDir}/{$shortVer}.php", $shortVer)) {
fwrite(STDERR, "\nStubs for WP '{$shortVer}' not written.");
continue;
}
$shortDone[$shortVer] = $fullVer;
} catch (\Throwable $throwable) {
describeFailure($throwable, $errMessage);
continue;
}
}
fwrite(STDOUT, "\n");
$repoBuilt = null;
if (($all > 0) || !file_exists(__DIR__ . '/packages.json')) {
fwrite(STDOUT, "\nStubs generation completed. Updating now Composer repo");
$repoBuilt = buildComposerRepo(__DIR__);
}
exit(finalMessage($all, $success, $repoBuilt));
} catch (\Throwable $throwable) {
function_exists(__NAMESPACE__ . '\\describeFailure')
? describeFailure($throwable)
: fwrite(STDERR, sprintf("\n%s\n", $throwable->getMessage()));
exit(1);
}