| [773] | 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | require_once 'phing/Task.php'; |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | class stubJsMinTask extends Task |
|---|
| 20 | { |
|---|
| 21 | |
|---|
| [787] | 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | protected $jsMinPath; |
|---|
| 27 | |
|---|
| [773] | 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | protected $filesets = array(); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | protected $failonerror = false; |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | protected $targetDir; |
|---|
| 46 | |
|---|
| 47 | |
|---|
| [787] | 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | public function setJsMinPath($jsMinPath) |
|---|
| 53 | { |
|---|
| 54 | $this->jsMinPath = $jsMinPath; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| [773] | 58 | |
|---|
| 59 | |
|---|
| 60 | public function createFileSet() |
|---|
| 61 | { |
|---|
| 62 | $num = array_push($this->filesets, new FileSet()); |
|---|
| 63 | return $this->filesets[$num - 1]; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | public function setFailonerror($value) |
|---|
| 72 | { |
|---|
| 73 | $this->failonerror = $value; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | public function setTargetDir($targetDir) |
|---|
| 82 | { |
|---|
| 83 | $this->targetDir = $targetDir; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | public function init() |
|---|
| 90 | { |
|---|
| [787] | 91 | return true; |
|---|
| [773] | 92 | } |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | public function main() |
|---|
| 98 | { |
|---|
| [787] | 99 | if (class_exists('JSMin', false) == false) { |
|---|
| 100 | require_once $this->jsMinPath; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| [773] | 103 | foreach ($this->filesets as $fs) { |
|---|
| 104 | try { |
|---|
| 105 | $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles(); |
|---|
| 106 | $fullPath = realpath($fs->getDir($this->project)); |
|---|
| 107 | foreach ($files as $file) { |
|---|
| 108 | $this->log('Minifying file ' . $file); |
|---|
| 109 | try { |
|---|
| [787] | 110 | $target = $this->targetDir . '/' . str_replace($fullPath, '', str_replace('.js', '-min.js', $file)); |
|---|
| [773] | 111 | if (file_exists(dirname($target)) == false) { |
|---|
| 112 | mkdir(dirname($target), 0700, true); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | file_put_contents($target, JSMin::minify(file_get_contents($fullPath . '/' . $file))); |
|---|
| 116 | } catch (JSMinException $jsme) { |
|---|
| 117 | $this->log("Could not minify file $file: " . $jsme->getMessage(), Project::MSG_ERR); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | } catch (BuildException $be) { |
|---|
| 121 | |
|---|
| 122 | if ($this->failonerror) { |
|---|
| 123 | throw $be; |
|---|
| 124 | } else { |
|---|
| 125 | $this->log($be->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN); |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | ?> |
|---|