-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathbuild.php
98 lines (79 loc) · 2.69 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
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
<?php
/*******************************************************************************
* Copyright (c) 2022. Ankio. All Rights Reserved.
******************************************************************************/
/**
* File build.php
* Created By ankio.
* Date : 2023/10/6
* Time : 21:34
* Description :
*/
use cleanphp\release\js\CompressJs;
include "src/cleanphp/file/File.php";
include "src/cleanphp/release/js/ParseMaster.php";
include "src/cleanphp/release/js/JavascriptPacker.php";
include "src/cleanphp/release/js/CompressJs.php";
const APP_DIR = __DIR__.DIRECTORY_SEPARATOR."src";
function compress(): void
{
$dir = APP_DIR . "/app";
$file = $dir . "/public/app.min.js";
$array = [
"/public/pack/jquery.min.js",
"/public/pack/log.js",
"/public/mdb/js/mdb.min.js",
"/public/pack/theme.js",
"/public/pack/mdbAdmin.js",
"/public/pack/form.js",
"/public/pack/requests.js",
"/public/pack/resource.js",
"/public/pack/lang.js",
];
$array[] = "/public/pack/route.js";
foreach (scandir($dir . "/public/pack/routes") as $item) {
if (str_starts_with($item, ".")) {
continue;
}
$array[] = "/public/pack/routes/$item";
}
foreach (scandir($dir . "/public/pack/frames") as $item) {
if (str_starts_with($item, ".")) {
continue;
}
$array[] = "/public/pack/frames/$item";
}
$array[] = "/public/main.js";
combineFilesStream($dir, $array, $file);
}
function combineFilesStream($dir, $files, $outputPath): void
{
$outputFile = fopen($outputPath, 'w'); // 打开输出文件进行写入
if (!$outputFile) {
die("Unable to open the output file for writing.");
}
$tempDir = __DIR__.DIRECTORY_SEPARATOR."temp";
foreach ($files as $file) {
$file__ = $dir . $file;
if (is_file($file__)) {
$temp = $tempDir.$file;
\cleanphp\file\File::mkDir( dirname($temp));
copy($file__,$temp);
CompressJs::compress($temp);
$inputFile = fopen($temp, 'r'); // 打开当前文件进行读取
if ($inputFile) {
while (!feof($inputFile)) {
$buffer = fread($inputFile, 4096); // 读取4KB
fwrite($outputFile, $buffer); // 写入到输出文件
}
fwrite($outputFile, "\n"); // 在每个文件后面添加一个换行符,确保代码不会混在一起
fclose($inputFile);
}
} else {
echo "File not found: " . $file__ . "\n";
}
}
\cleanphp\file\File::del($tempDir);
fclose($outputFile);
}
compress();