示例#1
0
    if (!empty($argv[2])) {
        if ($argv[2] == '-r') {
            //replace the compressed scripts with the backed up version
            reverseScripts("{$from}/jssource/src_files", "{$from}");
        } elseif ($argv[2] == '-m') {
            //replace the scripts, and then minify the scripts again
            reverseScripts("{$from}/jssource/src_files", "{$from}");
            BackUpAndCompressScriptFiles("{$from}", "", false, true);
        } elseif ($argv[2] == '-c') {
            //replace the scripts, concatenate the files, and then minify the scripts again
            reverseScripts("{$from}/jssource/src_files", "{$from}");
            BackUpAndCompressScriptFiles("{$from}", "", false, true);
            ConcatenateFiles("{$from}", true);
        } elseif ($argv[2] == '-mo') {
            //do not replace the scriptsjust minify the existing scripts again
            BackUpAndCompressScriptFiles("{$from}", "", false, true);
        } elseif ($argv[2] == '-co') {
            //concatenate the files only
            ConcatenateFiles("{$from}", true);
        } elseif ($argv[2] == '-?') {
            die("\n    Usage : minify <root path> [[-r]|[-m]|[-c]]\n    \n    <root path> = path of directory to process.  Should be root of sugar instance.   \n     -r  = replace javascript of root with scripts from backed up jssource/src_files directory   \n     -m  = same as r, only the script is minified and then copied   \n     -c  = same as m, only the concatenated files are processed again.\n     -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.\n     -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.\n            \n    *** note that options are mutually exclusive.  You would use -r OR -m OR -c          \n    \n    examples: say your patch is located in 'c:/sugar'\n    You wish to have files from root directory concatenated according to file grouping array, as well as all js files compressed and backed up:\n        minify 'c:/sugar'                                \n            \n    You wish to have backed up jssource files replace your current javascript files:\n        minify 'c:/sugar' -r                                \n            \n    You wish to have backed up jssource files minified, and replace your current javascript files:\n        minify 'c:/sugar' -m                               \n            \n    You wish to have backed up jssource files concatenated, minified, and replace your current javascript files:\n        minify 'c:/sugar' -c                               \n                                        ");
        }
    } else {
        //default is to concatenate the files, then back up and compress them
        if (empty($from)) {
            echo "directory root to process was not specified";
        }
        BackUpAndCompressScriptFiles("{$from}", '', true, true);
        ConcatenateFiles("{$from}", true);
    }
}
示例#2
0
$from = getcwd();
if (isset($_REQUEST['root_directory']) && !empty($_REQUEST['root_directory'])) {
    $from = $_REQUEST['root_directory'];
}
//this script can take a while, change max execution time to 10 mins
$tmp_time = ini_get('max_execution_time');
ini_set('max_execution_time', '600');
//figure out which commands to call.
if ($_REQUEST['js_admin_repair'] == 'concat') {
    //concatenate mode, call the files that will concatenate javascript group files
    $_REQUEST['js_rebuild_concat'] = 'rebuild';
    require_once 'jssource/minify.php';
} else {
    $_REQUEST['root_directory'] = getcwd();
    require_once 'jssource/minify.php';
    if ($_REQUEST['js_admin_repair'] == 'replace') {
        //should replace compressed JS with source js
        reverseScripts("{$from}/jssource/src_files", "{$from}");
    } elseif ($_REQUEST['js_admin_repair'] == 'mini') {
        //should replace compressed JS with minified version of source js
        reverseScripts("{$from}/jssource/src_files", "{$from}");
        BackUpAndCompressScriptFiles("{$from}", "", false);
        ConcatenateFiles("{$from}");
    } elseif ($_REQUEST['js_admin_repair'] == 'repair') {
        //should compress existing javascript (including changes done) without overwriting original source files
        BackUpAndCompressScriptFiles("{$from}", "", false);
        ConcatenateFiles("{$from}");
    }
}
//set execution time back to what it was
ini_set('max_execution_time', $tmp_time);
示例#3
0
function BackUpAndCompressScriptFiles($from_path, $to_path = '', $backup = true)
{
    //check to see if provided paths are legit
    if (!file_exists($from_path)) {
        //log error
        echo "The from directory, {$from_path} Does Not Exist<p>\n";
        return;
    } else {
        $from_path = str_replace('\\', '/', $from_path);
    }
    if (empty($to_path)) {
        $to_path = $from_path;
    } elseif (!file_exists($to_path)) {
        //log error
        echo "The to directory, {$to_path} Does Not Exist<p>\n";
        return;
    }
    //now grab list of files to exclude from minifying
    $exclude_files = get_exclude_files($to_path);
    //process only if file/directory is not in exclude list
    if (!isset($exclude_files[$from_path])) {
        //get correct path for backup
        $bu_path = $to_path . '/jssource/src_files';
        $bu_path .= substr($from_path, strlen($to_path));
        //if this is a directory, then read it and process files
        if (is_dir("{$from_path}")) {
            //grab file / directory and read it.
            $handle = opendir("{$from_path}");
            //loop over the directory and go into each child directory
            while (false !== ($dir = readdir($handle))) {
                //make sure you go into directory tree and not out of tree
                if ($dir != '.' && $dir != '..') {
                    //make recursive call to process this directory
                    BackUpAndCompressScriptFiles($from_path . '/' . $dir, $to_path, $backup);
                }
            }
        }
        //if this is not a directory, then
        //check if this is a javascript file, then process
        // Also, check if there's a min counterpart, in which case, don't use this file.
        $path_parts = pathinfo($from_path);
        if (is_file("{$from_path}") && isset($path_parts['extension']) && $path_parts['extension'] == 'js') {
            /*$min_file_path = $path_parts['dirname'].'/'.$path_parts['filename'].'-min.'.$path_parts['extension'];
              if(is_file($min_file_path)) {
                  $from_path = $min_file_path;
              }*/
            if ($backup) {
                $bu_dir = dirname($bu_path);
                if (!file_exists($bu_dir)) {
                    create_backup_folder($bu_dir);
                }
                //delete backup src file if it exists already
                if (file_exists($bu_path)) {
                    unlink($bu_path);
                }
                //copy original file into a source file
                rename($from_path, $bu_path);
            } else {
                //no need to backup, but remove file that is about to be copied
                //if it exists in both backed up scripts and working directory
                if (file_exists($from_path) && file_exists($bu_path)) {
                    unlink($from_path);
                }
            }
            //now make call to minify and overwrite the original file.
            CompressFiles($bu_path, $from_path);
        }
    }
}
示例#4
0
    if (!empty($argv[2])) {
        if ($argv[2] == '-r') {
            //replace the compressed scripts with the backed up version
            reverseScripts("{$from}/jssource/src_files", $from);
        } elseif ($argv[2] == '-m') {
            //replace the scripts, and then minify the scripts again
            reverseScripts("{$from}/jssource/src_files", $from);
            BackUpAndCompressScriptFiles($from, "", false, true);
        } elseif ($argv[2] == '-c') {
            //replace the scripts, concatenate the files, and then minify the scripts again
            reverseScripts("{$from}/jssource/src_files", $from);
            BackUpAndCompressScriptFiles($from, "", false, true);
            ConcatenateFiles($from, true);
        } elseif ($argv[2] == '-mo') {
            //do not replace the scriptsjust minify the existing scripts again
            BackUpAndCompressScriptFiles($from, "", false, true);
        } elseif ($argv[2] == '-co') {
            //concatenate the files only
            ConcatenateFiles($from, true);
        } elseif ($argv[2] == '-?') {
            die("\n    Usage : minify <root path> [[-r]|[-m]|[-c]]\n\n    <root path> = path of directory to process.  Should be root of sugar instance.\n     -r  = replace javascript of root with scripts from backed up jssource/src_files directory\n     -m  = same as r, only the script is minified and then copied\n     -c  = same as m, only the concatenated files are processed again.\n     -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.\n     -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.\n\n    *** note that options are mutually exclusive.  You would use -r OR -m OR -c\n\n    examples: say your patch is located in 'c:/sugar'\n    You wish to have files from root directory concatenated according to file grouping array, as well as all js files compressed and backed up:\n        minify 'c:/sugar'\n\n    You wish to have backed up jssource files replace your current javascript files:\n        minify 'c:/sugar' -r\n\n    You wish to have backed up jssource files minified, and replace your current javascript files:\n        minify 'c:/sugar' -m\n\n    You wish to have backed up jssource files concatenated, minified, and replace your current javascript files:\n        minify 'c:/sugar' -c\n                                        ");
        }
    } else {
        //default is to concatenate the files, then back up and compress them
        if (empty($from)) {
            echo "directory root to process was not specified";
        }
        BackUpAndCompressScriptFiles($from, '', true, true);
        ConcatenateFiles($from, true);
    }
}