-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.php
70 lines (54 loc) · 1.48 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
<?php
/**
* Build module files
*
* 2019 ComproPago
* @author José Beltrán Solís <j.beltran@live.com.mx>
*
*/
echo "\n";
echo "\033[1;32mGenerating ComproPago module for Prestashop 1.7.x\033[0m";
echo "\n";
$filename = "compropago.zip";
$zip = new ZipArchive();
$ignore = [
'.', '..', # root directories
'.git', '.gitignore', # git files
'build.php', # Build file
'composer.json', 'composer.lock', # Composer files
'.DS_Store' # OS System files
];
if (file_exists($filename)) {
echo "\033[1;31mDeleting old file\033[0m\n";
unlink($filename);
}
if ($zip->open($filename, ZipArchive::CREATE) === TRUE)
{
foreach (list_files() as $file) {
$file = str_replace(__DIR__.'/', '', $file);
if (in_array(current(explode('/', $file)), $ignore)) continue;
else {
echo "\e[1mAdding:\e[0m '$file'\n";
$zip->addFile( $file, "compropago/$file");
}
}
$zip->close();
} else {
exit("Cannot open <$filename>\n");
}
echo "\e[1mFinish...\e[0m" . PHP_EOL;
/**
* Functions
*/
function list_files($directory=__DIR__) {
$list = [];
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($directory),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $file) {
$path = $file->getRealPath();
if (!is_dir($path)) $list[] = $path;
}
return $list;
}