forked from overvis/opencart-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assemble.php
72 lines (59 loc) · 1.64 KB
/
assemble.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
<?php
/**
* Script for automatic assembling of plugins into zip
*/
$root = dirname(__FILE__);
$excludeDirs = ['.git', '.github', '.idea'];
$excludeFromZip = ['docs'];
/**
* @param SplFileInfo $file
* @param string $key
* @param RecursiveDirectoryIterator $iterator
*
* @return bool
*/
$filter = function (
SplFileInfo $file,
string $key,
RecursiveDirectoryIterator $iterator
) use ($excludeFromZip): bool {
if (
$iterator->hasChildren()
&& !in_array($file->getFilename(), $excludeFromZip)
) {
return true;
}
return $file->isFile();
};
foreach (glob($root . '/*', GLOB_ONLYDIR) as $dirPath) {
$dirName = basename($dirPath);
if (!in_array($dirName, $excludeDirs)) {
$zip = new ZipArchive();
$zipName = sprintf(
'%s/%s.ocmod.zip',
$dirPath,
$dirName
);
if (file_exists($zipName)) unlink($zipName);
$zip->open($zipName, ZipArchive::CREATE);
$innerIterator = new RecursiveDirectoryIterator(
$dirPath,
RecursiveDirectoryIterator::SKIP_DOTS
);
$filesToZip = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
$innerIterator,
$filter
)
);
foreach ($filesToZip as $file) {
if (!is_dir($file)) {
$filePath = realpath($file);
$relativePath = substr($filePath, strlen($dirPath) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->addFile($root . '/LICENSE', 'LICENSE');
$zip->close();
}
}