-
-
Notifications
You must be signed in to change notification settings - Fork 423
Expand file tree
/
Copy pathbuild-docs.php
More file actions
135 lines (106 loc) · 3.77 KB
/
Copy pathbuild-docs.php
File metadata and controls
135 lines (106 loc) · 3.77 KB
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
134
135
<?php
use DebugBar\Bridge\Symfony\SymfonyMailCollector;
use DebugBar\DataCollector\HttpCollector;
use DebugBar\DataCollector\PDO\PDOCollector;
use DebugBar\DataCollector\TemplateCollector;
use DebugBar\StandardDebugBar;
include __DIR__ . '/../vendor/autoload.php';
// Rquires `php vendor/bin/phpunit --filter=testDocs`
$generatedScripts = file_get_contents(__DIR__ . '/docs/render.html');
function getBetween(string $string, string $start, string $end): ?string {
if (preg_match('/' . preg_quote($start, '/') . '(.*?)' . preg_quote($end, '/') . '/s', $string, $matches)) {
return $matches[1];
}
return null;
}
$generatedScripts = getBetween($generatedScripts, '<!-- DebugBar Widget Start -->', '<!-- DebugBar Widget End -->');
// Remove first style/script
$generatedScripts = explode('</script>', $generatedScripts, 2)[1];
// Read the main.html template
$templatePath = __DIR__ . '/../docs/overrides/main.html';
$template = file_get_contents($templatePath);
// Replace the scripts block content between specific markers
$startMarker = "<!-- Start Debugbar -->";
$endMarker = "<!-- End Debugbar -->";
// Find the positions
$startPos = strpos($template, $startMarker);
$endPos = strpos($template, $endMarker);
if ($startPos !== false && $endPos !== false) {
$startPos += strlen($startMarker);
// Replace the content between markers
$newTemplate = substr($template, 0, $startPos)
. "\n{% raw %}\n" . $generatedScripts . "\n{% endraw %}\n"
. substr($template, $endPos);
// Write back to the file
file_put_contents($templatePath, $newTemplate);
echo "✓ Updated docs/overrides/main.html with generated debugbar scripts\n";
} else {
echo "✗ Could not find script markers in main.html\n";
exit(1);
}
// Copy dist folder to docs/assets/dist
$distSource = __DIR__ . '/../resources/dist';
$distDest = __DIR__ . '/../docs/assets/dist';
if (!is_dir($distSource)) {
echo "✗ dist folder not found at $distSource\n";
exit(1);
}
// Create docs/assets directory if it doesn't exist
if (!is_dir(__DIR__ . '/../docs/assets')) {
mkdir(__DIR__ . '/../docs/assets', 0755, true);
}
// Remove existing dist folder if it exists
if (is_dir($distDest)) {
deleteDirectory($distDest);
}
// Copy dist folder
copyDirectory($distSource, $distDest);
echo "✓ Copied dist folder to docs/assets/dist\n";
// Update mkdocs.yml with current timestamp
$mkdocsPath = __DIR__ . '/../mkdocs.yml';
$mkdocsContent = file_get_contents($mkdocsPath);
$timestamp = time();
$mkdocsContent = preg_replace(
'/debugbar\.min\.css\?v=\d+/',
'debugbar.min.css?v=' . $timestamp,
$mkdocsContent
);
$mkdocsContent = preg_replace(
'/debugbar\.min\.js\?v=\d+/',
'debugbar.min.js?v=' . $timestamp,
$mkdocsContent
);
file_put_contents($mkdocsPath, $mkdocsContent);
echo "✓ Updated mkdocs.yml with timestamp: $timestamp\n";
function copyDirectory($source, $dest) {
mkdir($dest, 0755, true);
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
$destPath = $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathname();
if ($item->isDir()) {
mkdir($destPath, 0755, true);
} else {
copy($item, $destPath);
}
}
}
function deleteDirectory($dir) {
if (!is_dir($dir)) {
return;
}
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $item) {
if ($item->isDir()) {
rmdir($item);
} else {
unlink($item);
}
}
rmdir($dir);
}