-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_woocommerce_plugin.php
68 lines (58 loc) · 1.66 KB
/
make_woocommerce_plugin.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
<?php
$plugin_name = 'cc-woocommerce-gateway-powertranz';
$target = "../".$plugin_name;
$zip = new ZipArchive();
if ($zip->open($plugin_name.".zip", ZipArchive::CREATE | ZipArchive::OVERWRITE)!==TRUE) {
exit("cannot open <$plugin_name.zip>\n");
}
function recursiveRemoveDirectory($directory)
{
foreach(glob("{$directory}/*") as $file)
{
if(is_dir($file)) {
recursiveRemoveDirectory($file);
} else {
unlink($file);
}
}
rmdir($directory);
}
function recursiveCopyDirectory($directory,$plugin_name)
{
mkdir($plugin_name."/".$directory);
foreach(glob("{$directory}/*") as $file)
{
if(is_dir($file) && !in_array($file, [".",".."])) {
recursiveCopyDirectory($file, $plugin_name);
} else {
copy($file, $plugin_name."/".$file);
}
}
}
function recursiveZipDirectory(ZipArchive $zip,$directory,$plugin_name)
{
foreach(glob("{$directory}/*") as $file)
{
if(is_dir($file) && !in_array($file, [".",".."])) {
$zip->addEmptyDir(str_replace("../$plugin_name/", "", $file));
recursiveZipDirectory($zip,$file,$plugin_name);
} else {
$zip->addFile(str_replace("../$plugin_name/","",str_replace("..\\$plugin_name\\", "", $file)));
}
}
}
if (is_dir($target))
{
recursiveRemoveDirectory($target);
}
mkdir($target);
recursiveCopyDirectory("src",$target);
recursiveCopyDirectory("vendor",$target);
recursiveCopyDirectory("assets",$target);
recursiveZipDirectory($zip,$target, $plugin_name);
$zip->addFile($plugin_name.".php");
$zip->close();
if (is_dir($target))
{
recursiveRemoveDirectory($target);
}