forked from cayennes/kanji-colorize
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added php build script for anki addon zip
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
$zip = new ZipArchive(); | ||
$filename = './dist/anki__hanzi_colorizer.zip'; | ||
|
||
$rootPath = './hanzicolorizer'; | ||
|
||
if (!is_dir('./dist')) { | ||
mkdir('./dist'); | ||
} | ||
|
||
if (is_file($filename)) { | ||
unlink($filename); | ||
} | ||
|
||
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) { | ||
exit("cannot open <$filename>\n"); | ||
} | ||
|
||
$files = new RecursiveIteratorIterator( | ||
new RecursiveDirectoryIterator($rootPath), | ||
RecursiveIteratorIterator::LEAVES_ONLY | ||
); | ||
|
||
$zip->addFile('anki/hanzi_colorizer.py', 'hanzi_colorizer.py'); | ||
foreach ($files as $name => $file) | ||
{ | ||
// Skip directories (they would be added automatically) | ||
if ( | ||
!$file->isDir() | ||
&& ( | ||
(preg_match("@\.py$@", $file->getFileName())) | ||
|| (preg_match("@\.svg$@", $file->getFileName()) && preg_match("@" . preg_quote("data" . DIRECTORY_SEPARATOR . "hanzivg" . DIRECTORY_SEPARATOR . "hanzi") . "$@", dirname($file->getPathName()))) | ||
) | ||
) | ||
{ | ||
// Get real and relative path for current file | ||
$filePath = $file->getRealPath(); | ||
$relativePath = preg_replace("@^" . preg_quote('./') . "@", "" , $file->getPathName()); | ||
|
||
// Add current file to archive | ||
$zip->addFile($filePath, $relativePath); | ||
} | ||
} | ||
|
||
$zip->close(); |