123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- require_once 'phing/Task.php';
- require_once 'phing/tasks/ext/jsmin/JsMin.php';
- class JsMinTask extends Task
- {
-
- protected $filesets = array();
-
- protected $failonerror = false;
-
- protected $targetDir;
-
- public function createFileSet()
- {
- $num = array_push($this->filesets, new FileSet());
- return $this->filesets[$num - 1];
- }
-
- public function setFailonerror($value)
- {
- $this->failonerror = $value;
- }
-
- public function setTargetDir($targetDir)
- {
- $this->targetDir = $targetDir;
- }
-
- public function init()
- {
- return true;
- }
-
- public function main()
- {
- foreach ($this->filesets as $fs) {
- try {
- $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
- $fullPath = realpath($fs->getDir($this->project));
- foreach ($files as $file) {
- $this->log('Minifying file ' . $file);
- try {
- $target = $this->targetDir . '/' . str_replace($fullPath, '', str_replace('.js', '-min.js', $file));
- if (file_exists(dirname($target)) === false) {
- mkdir(dirname($target), 0700, true);
- }
-
- file_put_contents($target, JSMin::minify(file_get_contents($fullPath . '/' . $file)));
- } catch (JSMinException $jsme) {
- $this->log("Could not minify file $file: " . $jsme->getMessage(), Project::MSG_ERR);
- }
- }
- } catch (BuildException $be) {
-
- if ($this->failonerror) {
- throw $be;
- } else {
- $this->log($be->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN);
- }
- }
- }
- }
- }
- ?>
|