-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·133 lines (110 loc) · 2.52 KB
/
build
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
#!/usr/bin/env php
<?php
// by @leaskh
// config
error_reporting(E_ALL ^ E_NOTICE);
$binFolder = 'bin';
$sources = [
'ActionController.php',
'api_controllers',
'common.php',
'controllers',
'Classes',
'DataModel.php',
'default_avatar_portrait',
'FrontController.php',
'helpers',
'index.php',
'init',
'intl',
'lib',
'logrotate.conf',
'models',
'router.php',
'rebuild_autocomplete_index',
'rebuild_cache',
'rebuild_geoip_datas',
'share',
'third_party_libraries',
'views',
'xbgutilitie',
'wechat',
];
// define
function delDir($path) {
$files = array_diff(scandir($path), ['.', '..']);
foreach ($files as $file) {
$curPath = "{$path}/{$file}";
is_dir($curPath) ? delDir($curPath) : unlink($curPath);
}
return rmdir($path);
}
function copyDir($src, $dst) {
@mkdir($dst);
$files = array_diff(scandir($src), ['.', '..']);
foreach ($files as $file) {
copyAny("{$src}/{$file}", "{$dst}/{$file}");
}
}
function copyAny($src, $dst) {
is_dir($src) ? copyDir($src, $dst) : copy($src, $dst);
}
function lintFile($path) {
if (preg_match('/^.*\.php$/i', $path)) {
$result = shell_exec("php -l {$path}");
if (preg_match('/No syntax errors detected/', $result)) {
return 0;
}
$arrResult = explode("\n", $result);
foreach ($arrResult as $item) {
if ($item) {
echo "❌ $item\n";
}
}
return 1;
}
return -1;
}
function lintDir($path) {
$files = array_diff(scandir($path), ['.', '..']);
foreach ($files as $file) {
if (lintAny("{$path}/{$file}") === 1) {
return 1;
}
}
return 0;
}
function lintAny($path) {
return is_dir($path) ? lintDir($path) : lintFile($path);
}
// start
echo "Build started:\n";
$curDir = dirname(__FILE__);
$binDir = "{$curDir}/{$binFolder}";
// flush bin
echo "* Flush bin folder\n";
if (file_exists($binDir) && is_dir($binDir)) {
if (!delDir($binDir)) {
echo "❌ Failed on making bin folder\n";
exit(1);
}
}
@mkdir($binDir);
// lint
echo "* Lint codes\n";
foreach ($sources as $item) {
if (lintAny("{$curDir}/{$item}") === 1) {
exit(1);
}
}
// make
echo "* Make codes\n";
foreach ($sources as $item) {
if (copyAny("{$curDir}/{$item}", "{$binDir}/{$item}")) {
echo "❌ Failed making codes\n";
exit(1);
}
}
// finished
echo "⭕ Built successfully\n";
return 0;