]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/minify.php
Release 6.2.2
[Github/sugarcrm.git] / jssource / minify.php
1 <?php
2 if(!defined('sugarEntry'))define('sugarEntry', true);
3
4 //assumes jsmin.php is in same directory
5     if(isset($_REQUEST['root_directory'])){
6         require_once('jssource/minify_utils.php');
7     }else{
8         require_once('minify_utils.php');
9     }
10
11 //if we are coming from browser
12     
13 if(isset($_REQUEST['root_directory'])){
14         if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
15         
16     require_once('include/utils/sugar_file_utils.php');
17         
18     //get the root directory to process
19     $from = $_REQUEST['root_directory'];
20     $forceReb = false;
21     //make sure that the rebuild option has been chosen
22     if(isset($_REQUEST['js_rebuild_concat'])){
23         if($_REQUEST['js_rebuild_concat'] == 'rebuild'){
24              //rebuild if files have changed
25              $js_groupings = array();
26             if(isset($_REQUEST['root_directory'])){
27                 require('jssource/JSGroupings.php');
28             }else{
29                 require('JSGroupings.php');
30             }
31
32             //iterate through array of grouped files
33             $grp_array = $js_groupings;//from JSGroupings.php;
34
35             //for each item in array, concatenate the source files
36             foreach($grp_array as $grp){
37                 foreach($grp as $original =>$concat){
38                     //make sure both files are still valid
39                     if(is_file($original)  &&  is_file($concat)){
40                         //if individual file has been modifed date later than modified date of
41                         //concatenated file, then force a rebuild
42                         if(filemtime($original) > filemtime($concat)){
43                             $forceReb = true;
44                             //no need to continue, we will rebuild
45                             break;
46                         }
47                     }else{
48                         //if files are not valid, rebuild as one file could have been deleted
49                         $forceReb = true; 
50                         //no need to continue, we will rebuild
51                         break;
52                     }
53                 }
54             }
55          
56         }
57         //if boolean has been set, concatenate files
58         if($forceReb){
59         ConcatenateFiles("$from");
60             
61         }   
62
63     }else{
64         //We are only allowing rebuilding of concat files from browser.
65             
66     }        
67     return;
68 }else{
69     //run via command line
70     //print_r($argv);
71     $from="";
72
73     if(isset($argv[1]) && !empty($argv[1])){
74          $from = $argv[1];   
75     }else{
76      //Root Directory was not specified
77      echo 'Root Directory Input was not provided';
78      return;   
79     }
80     
81 //    require_once($argv[1].'/include/utils/sugar_file_utils.php');
82
83     if($argv[1] == '-?'){
84         $argv[2] = '-?';
85     }
86
87     //if second argument is set, then process commands    
88     if(!empty($argv[2])){
89     
90            if($argv[2] == '-r'){
91                 //replace the compressed scripts with the backed up version
92                 reverseScripts("$from/jssource/src_files","$from");
93                         
94            }elseif($argv[2] == '-m'){
95                 //replace the scripts, and then minify the scripts again
96                 reverseScripts("$from/jssource/src_files","$from");
97                 BackUpAndCompressScriptFiles("$from","",false,true);        
98             
99            }elseif($argv[2] == '-c'){
100                 //replace the scripts, concatenate the files, and then minify the scripts again
101                 reverseScripts("$from/jssource/src_files","$from");
102                 BackUpAndCompressScriptFiles("$from","",false,true);        
103                 ConcatenateFiles("$from",true);           
104            }elseif($argv[2] == '-mo'){
105                 //do not replace the scriptsjust minify the existing scripts again
106                 BackUpAndCompressScriptFiles("$from","",false,true);        
107             
108            }elseif($argv[2] == '-co'){
109                 //concatenate the files only
110                 ConcatenateFiles("$from",true);
111             
112            }elseif($argv[2] == '-?'){
113                 die("
114     Usage : minify <root path> [[-r]|[-m]|[-c]]
115     
116     <root path> = path of directory to process.  Should be root of sugar instance.   
117      -r  = replace javascript of root with scripts from backed up jssource/src_files directory   
118      -m  = same as r, only the script is minified and then copied   
119      -c  = same as m, only the concatenated files are processed again.
120      -co = concatenates only the js files that are to be concatenated.  Main use is for development when files that make up a concatenated file have been modified.
121      -mo = minifies only the existing js files.  Will not use source files and will not back up scripts.  Main use is for development, when changes have been made to working javascript and you wish to recompress your scripts.
122             
123     *** note that options are mutually exclusive.  You would use -r OR -m OR -c          
124     
125     examples: say your patch is located in 'c:/sugar'
126     You wish to have files from root directory concatenated according to file grouping array, as well as all js files compressed and backed up:
127         minify 'c:/sugar'                                
128             
129     You wish to have backed up jssource files replace your current javascript files:
130         minify 'c:/sugar' -r                                
131             
132     You wish to have backed up jssource files minified, and replace your current javascript files:
133         minify 'c:/sugar' -m                               
134             
135     You wish to have backed up jssource files concatenated, minified, and replace your current javascript files:
136         minify 'c:/sugar' -c                               
137                                         ");
138                         
139            }
140            
141     }else{
142         //default is to concatenate the files, then back up and compress them
143         if(empty($from)){
144             echo("directory root to process was not specified");   
145         }
146
147         BackUpAndCompressScriptFiles("$from", '', true, true);        
148         ConcatenateFiles("$from",true);        
149         
150     }
151 }
152
153
154 ?>