2 if(!defined('sugarEntry'))define('sugarEntry', true);
4 //assumes jsmin.php is in same directory
5 if(isset($_REQUEST['root_directory'])){
6 require_once('jssource/minify_utils.php');
8 require_once('minify_utils.php');
11 //if we are coming from browser
13 if(isset($_REQUEST['root_directory'])){
14 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
16 require_once('include/utils/sugar_file_utils.php');
18 //get the root directory to process
19 $from = $_REQUEST['root_directory'];
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 require_once('jssource/minify_utils.php');
30 require('JSGroupings.php');
31 require_once('minify_utils.php');
34 //iterate through array of grouped files
35 $grp_array = $js_groupings;//from JSGroupings.php;
37 //for each item in array, concatenate the source files
38 foreach($grp_array as $grp){
39 foreach($grp as $original =>$concat){
40 $concat = sugar_cached($concat);
41 //make sure both files are still valid
42 if(is_file($original) && is_file($concat)){
43 //if individual file has been modifed date later than modified date of
44 //concatenated file, then force a rebuild
45 if(filemtime($original) > filemtime($concat)){
47 //no need to continue, we will rebuild
51 //if files are not valid, rebuild as one file could have been deleted
53 //no need to continue, we will rebuild
60 //if boolean has been set, concatenate files
62 ConcatenateFiles("$from");
67 //We are only allowing rebuilding of concat files from browser.
72 //run via command line
76 if(isset($argv[1]) && !empty($argv[1])){
79 //Root Directory was not specified
80 echo 'Root Directory Input was not provided';
84 if ($argv[1] != '-?') {
86 require_once('include/utils.php');
87 require_once('include/utils/file_utils.php');
88 require_once('include/utils/sugar_file_utils.php');
90 if(!function_exists('sugar_cached')) {
91 if ($argv[1] != '-?') {
92 require_once($from.'/./include/utils.php');
93 require_once($from.'/./include/utils/file_utils.php');
94 require_once($from.'/./include/utils/sugar_file_utils.php');
96 if(!function_exists('sugar_cached')) {
97 function sugar_cached($dir) { return "cache/$dir"; }
101 if($argv[1] == '-?'){
105 //if second argument is set, then process commands
106 if(!empty($argv[2])){
108 if($argv[2] == '-r'){
109 //replace the compressed scripts with the backed up version
110 reverseScripts("$from/jssource/src_files",$from);
112 }elseif($argv[2] == '-m'){
113 //replace the scripts, and then minify the scripts again
114 reverseScripts("$from/jssource/src_files",$from);
115 BackUpAndCompressScriptFiles($from,"",false,true);
117 }elseif($argv[2] == '-c'){
118 //replace the scripts, concatenate the files, and then minify the scripts again
119 reverseScripts("$from/jssource/src_files",$from);
120 BackUpAndCompressScriptFiles($from,"",false,true);
121 ConcatenateFiles($from,true);
122 }elseif($argv[2] == '-mo'){
123 //do not replace the scriptsjust minify the existing scripts again
124 BackUpAndCompressScriptFiles($from,"",false,true);
126 }elseif($argv[2] == '-co'){
127 //concatenate the files only
128 ConcatenateFiles($from,true);
130 }elseif($argv[2] == '-?'){
132 Usage : minify <root path> [[-r]|[-m]|[-c]]
134 <root path> = path of directory to process. Should be root of sugar instance.
135 -r = replace javascript of root with scripts from backed up jssource/src_files directory
136 -m = same as r, only the script is minified and then copied
137 -c = same as m, only the concatenated files are processed again.
138 -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.
139 -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.
141 *** note that options are mutually exclusive. You would use -r OR -m OR -c
143 examples: say your patch is located in 'c:/sugar'
144 You wish to have files from root directory concatenated according to file grouping array, as well as all js files compressed and backed up:
147 You wish to have backed up jssource files replace your current javascript files:
150 You wish to have backed up jssource files minified, and replace your current javascript files:
153 You wish to have backed up jssource files concatenated, minified, and replace your current javascript files:
160 //default is to concatenate the files, then back up and compress them
162 echo("directory root to process was not specified");
165 BackUpAndCompressScriptFiles($from, '', true, true);
166 ConcatenateFiles($from,true);