-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.php
More file actions
47 lines (40 loc) · 1.36 KB
/
Copy pathtools.php
File metadata and controls
47 lines (40 loc) · 1.36 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
<?php
function removeComments($content, $isBlade = false) {
$standardPattern = '/(\/\*[\s\S]*?\*\/)|((?<![:"\'\/])\/\/.*)/';
if ($isBlade) {
$bladePattern = '/\{\{--[\s\S]*?--\}\}/';
$content = preg_replace($bladePattern, '', $content);
}
return preg_replace($standardPattern, '', $content);
}
function processPath($targetPath) {
if (!file_exists($targetPath)) {
die("worng path");
}
if (is_file($targetPath)) {
cleanFile($targetPath);
}else {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($targetPath));
foreach ($files as $file) {
if ($file->isFile()) {
cleanFile($file->getRealPath());
}
}
}
echo "successfully done";
}
function cleanFile($filePath) {
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
$fileName = basename($filePath);
$isBlade = (str_contains($fileName, '.blade.php'));
$allowedExtensions = ['php', 'js', 'jsx', 'ts', 'tsx', 'vue'];
if (in_array($extension, $allowedExtensions) || $isBlade) {
$content = file_get_contents($filePath);
$cleaned = removeComments($content, $isBlade);
file_put_contents($filePath, $cleaned);
echo "Cleaned: $filePath\n";
}
}
// add your folder or file.ext name
$inputPath = './delete.php';
processPath($inputPath);