-
Notifications
You must be signed in to change notification settings - Fork 10
/
tasks
executable file
·66 lines (44 loc) · 1.37 KB
/
tasks
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
#!/usr/bin/php
<?php
$ignore = [
'./Test',
'./docs',
'./vendor',
'./tasks',
'./.idea',
'./.git'
];
$newVersion = '1.4.5';
if (!$newVersion) {
$tags = glob('.git/refs/tags/*');
if (count($tags) < 1)
throw new Exception(
"No tags found. Make sure the .git directory is there and you have any tags yet."
);
sort($tags);
$lastTag = basename(end($tags));
}
$dirIterator = new RecursiveDirectoryIterator('./');
$itIterator = new RecursiveIteratorIterator($dirIterator);
$codeFiles = new RegexIterator($itIterator, '/\.php$/');
$ignore = array_map(function($val) {
return str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $val);
}, $ignore);
echo "Set Version: $newVersion\n";
//Do eeet
foreach ($codeFiles as $codeFile) {
foreach ($ignore as $ignored) {
if (strncmp($ignored, $codeFile, strlen($ignored)) === 0) {
continue 2;
}
}
echo "Handling $codeFile\n";
$content = file_get_contents($codeFile);
//Convert the file to UTF-8 always!
$content = mb_convert_encoding($content, 'UTF-8');
//Strip \r and \0 anywhere
$content = str_replace(["\r", "\0"], '', $content);
//Automatically append version to @version (auto): tags
$content = preg_replace("/@version.*\n/iU", "@version {$newVersion}\n", $content);
file_put_contents($codeFile, $content);
}