-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.php
60 lines (46 loc) · 1.75 KB
/
build.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
<?php
$tdpcms = 'kernel.phar';
$target = strtr(__DIR__, '\\', '/') . '/tdpcms/';
PHP_SAPI == 'cli' || exit('Please run in CLI mode');
is_dir($target) && exit('Please delete dir: ' . $target);
mkdir($target, 0755, true) || exit('Create dir failed: ' . $target);
///////////////////////////////////////// 开始打包 /////////////////////////
$phar = new Phar($target . $tdpcms, 0, $tdpcms);
$phar->startBuffering();
$phar->buildFromDirectory('./', '%^./(index|library|modules|template)%i');
$phar->setDefaultStub('index.php', 'index.php');
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
///////////////////////////////////////// 创建入口 /////////////////////////
$index = <<<PHP
<?php
extension_loaded('phar') || exit('Phar extension is required!');
define('APP_WEBROOT', strtr(__DIR__, '\\\\', '/') . '/');
define('APP_DATASET', APP_WEBROOT . 'dataset/');
define('APP_RUNTIME', APP_WEBROOT . 'runtime/');
require 'phar://$tdpcms';
PHP;
file_put_contents($target . 'index.php', $index);
///////////////////////////////////////// 复制文件 /////////////////////////
recurse_copy('assets', $target . 'assets', '/\.map$/');
recurse_copy('dataset', $target . 'dataset', '/\.map$/');
function recurse_copy($src, $dst, $exclude = '')
{
$dir = opendir($src);
is_dir($dst) || mkdir($dst);
while ($file = readdir($dir)) {
if ($file == '.' || $file == '..') {
continue;
}
if ($exclude && preg_match($exclude, $file)) {
echo "skip $file\n";
continue;
}
if (is_dir($src . '/' . $file)) {
recurse_copy($src . '/' . $file, $dst . '/' . $file, $exclude);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
closedir($dir);
}