Minify JavaScript files stylesheets

@return void
421795
public function minifyJS() {
      $js_dir = './js';
      if (is_dir($js_dir)) {
         foreach (glob("$js_dir/*.js") as $js_file) {
            if (!$this->endsWith($js_file, 'min.js')) {
               $this->taskMinify($js_file)
                  ->to(str_replace('.js', '.min.js', $js_file))
                  ->type('js')
                  ->run();
            }
         }
      }
      return $this;
   }
356691
private function normalizeStylesheetsProperty()
    {
        if (empty($this->pluginOptions['stylesheets']))
            $this->pluginOptions['stylesheets'] = array();
        else if (is_array($this->pluginOptions['stylesheets']))
            $this->pluginOptions['stylesheets'] = array_filter($this->pluginOptions['stylesheets'], 'is_string');
        else if (is_string($this->pluginOptions['stylesheets']))
            $this->pluginOptions['stylesheets'] = array($this->pluginOptions['stylesheets']);
        else
            $this->pluginOptions['stylesheets'] = array();
    }
414070
protected function minify($code)
    {
        $code = (string) parent::minify($code);

        $code = preg_replace('/( )?=( )?/', '=', $code);

        $code = preg_replace('/( )?\(( )?/', '(', $code);

        return preg_replace('/( )?var ( )?/', '', $code);
    }
446302
public function minify()
    {
        $css_files = $this->cleanStack($this->get(), 'file');

        $organized_css = array('rest'=>array());
        foreach ($css_files as $_file) {
            if (!empty($_file['media'])) {
                if (!isset($organized_css[ $_file['media'] ])) {
                    $organized_css[ $_file['media'] ] = array();
                }
                $organized_css[ $_file['media'] ][] = $_file;
            } else {
                $organized_css['rest'][] = $_file;
            }
        }

        foreach ($organized_css as $media=>$stack) {
            $cleaned_stack = $this->extractFromStack($stack, 'file');
            if (!empty($cleaned_stack)) {
                $this->addMinified(
                    $this->minifyStack($cleaned_stack), $media=='rest' ? 'screen' : $media
                );
            }
        }

        return $this;
    }
447404
private function cmdJs()
    {
        echo "\n - JS -\n";
        if ($js = $this->config->get('js')) {
            if (!$this->subCmd) {
                foreach ($js as $k => $v) {
                    echo "\n - $k:\n";
                    $this->minify($v->filename, $v->add, $this->yuicompressor, $this->config->baseDir);
                }
                return;
            }

            if (isset($js->{$this->subCmd})) {
                echo "\n - ".$this->subCmd."\n";
                $this->minify($js->{$this->subCmd}->filename,
                  $js->{$this->subCmd}->add,
                  $this->yuicompressor,
                  $this->config->baseDir);
            } else {
                echo "\n Err: Not found!\n";
                return;
            }
        }
    }
1373512
public static function compress($js)
    {
        $js = (string) $js;
        try {
            $js_minifier = new static($js);
            $minified_js = $js_minifier->min();
            return $minified_js;
        } catch (\Exception $exception) {
            return $js;
        }
    }
102173
protected function minifyCss()
    {
        $output = '';

        // Core variables and mixins
        $output .= '@import "variables.less";';
        $output .= '@import "mixins.less";';

        // Reset and dependencies
        $output .= $this->prepareCssForLess('normalize');
        $output .= $this->prepareCssForLess('print');
        $output .= $this->prepareCssForLess('glyphicons');

        // Core CSS
        $output .= $this->prepareCssForLess('scaffolding');
        $output .= $this->prepareCssForLess('type');
        $output .= $this->prepareCssForLess('code');
        $output .= $this->prepareCssForLess('grid');
        $output .= $this->prepareCssForLess('tables');
        $output .= $this->prepareCssForLess('forms');
        $output .= $this->prepareCssForLess('buttons');

        // Components
        $output .= $this->prepareCssForLess('component-animations');
        $output .= $this->prepareCssForLess('dropdowns');
        $output .= $this->prepareCssForLess('button-groups');
        $output .= $this->prepareCssForLess('input-groups');
        $output .= $this->prepareCssForLess('navs');
        $output .= $this->prepareCssForLess('navbar');
        $output .= $this->prepareCssForLess('breadcrumbs');
        $output .= $this->prepareCssForLess('pagination');
        $output .= $this->prepareCssForLess('pager');
        $output .= $this->prepareCssForLess('labels');
        $output .= $this->prepareCssForLess('badges');
        $output .= $this->prepareCssForLess('jumbotron');
        $output .= $this->prepareCssForLess('thumbnails');
        $output .= $this->prepareCssForLess('alerts');
        $output .= $this->prepareCssForLess('progress-bars');
        $output .= $this->prepareCssForLess('media');
        $output .= $this->prepareCssForLess('list-group');
        $output .= $this->prepareCssForLess('panels');
        $output .= $this->prepareCssForLess('responsive-embed');
        $output .= $this->prepareCssForLess('wells');
        $output .= $this->prepareCssForLess('close');

        // Components w/ JavaScript
        $output .= $this->prepareCssForLess('modals');
        $output .= $this->prepareCssForLess('tooltip');
        $output .= $this->prepareCssForLess('popovers');
        $output .= $this->prepareCssForLess('carousel');

        // Utility classes
        $output .= $this->prepareCssForLess('utilities');
        $output .= $this->prepareCssForLess('responsive-utilities');

        $less = new \Less_Parser();
        $less->SetImportDirs([base_path('vendor/twbs/bootstrap/less') => 'bootstrap']);

        $css = $less->parse($output, 'bootstrap.components.less')->getCss();

        $minifier = new Minify\CSS();
        $minifier->add($css);

        return $minifier->minify();
    }
1209439
public function minifyJs(array $args = array()) {
        $ini = Zend_Registry::get('config');
        if (empty($ini->assets->js)) {
            Garp_Cli::errorOut(
                "You do not have a valid asset configuration specified in application.ini.\n" .
                "Configure like this:\n" .
                'assets.js.main_js.filename = "main.min.js"' . "\n" .
                'assets.js.main_js.sourcefiles[] = "libs/myplugin.js"' . "\n" .
                'assets.js.main_js.sourcefiles[] = "main.js"' . "\n" .
                "This will combine libs/myplugin.js and main.js into main.min.js."
            );
            return false;
        }

        $jsRoot = ltrim($ini->assets->js->basePath ?: 'js', '/');
        $assets = $ini->assets->js->toArray();
        unset($assets['basePath']);

        $selectedKey = null;
        if (!empty($args)) {
            $selectedKey = $args[0];
        }

        foreach ($assets as $key => $assetSettings) {
            if (!is_null($selectedKey) && $key != $selectedKey) {
                continue;
            }
            if (empty($assetSettings['sourcefiles'])
                || empty($assetSettings['filename'])
            ) {
                Garp_Cli::errorOut(
                    $key .
                    ' is not configured correctly. "sourcefiles" and "filename" are required keys.'
                );
                return false;
            }
            $minifier = new Garp_Assets_Minifier(APPLICATION_PATH . '/../public/' . $jsRoot);
            $minifier->minifyJs($assetSettings['sourcefiles'], $assetSettings['filename']);
        }
        Garp_Cli::lineOut('Done.');
        return true;
    }
1297272
protected function addStyleSheets()
	{
		// Initialize string for .css path
		$path = '';

		// Get .css path if defined in config file
		if ($this->getConfig('assets.paths.css'))
		{
			$path = $this->getConfig('assets.paths.css') . '/';
		}

		foreach ($this->stylesheets as $file => $options)
		{
			// Set default value for median attribute
			$media = 'all';

			// Set default value for conditional comments
			$cond = '';

			// Check in config file if stylesheet is an external resource
			$cdn = $this->getConfig('assets.cdn.'.$file);

			// Initialize string for file's url
			$href = '';

			// No conditional comment
			if (is_string($options) && $options)
			{
				$media = $options;
			}

			// Conditional comments are defined
			elseif(is_array($options))
			{
				// Check if value is not empty
				if (array_key_exists(1, $options) && $options[1])
				{
					// Get value for conditional comments
					$cond = $options[1];
				}

				// Check if value is not empty
				if (array_key_exists(0, $options) && $options[0])
				{
					// Get value for media attribute
					$media = $options[0];
				}
			}

			// Stylesheet is an external resource
			if ($cdn)
			{
				// Get file's url
				$href = $cdn;
			}

			// Stylesheet is a local resources + check if file exists
			elseif (File::exists(public_path($path.$file.'.css')))
			{
				// Get file's url
				$href = asset($path.$file.'.css');
			}

			// Check if url is not empty
			if ($href)
			{
				// Register link tag for this stylesheet
				$this->addOneLink('stylesheet', $href, '', array('media' => $media), $cond);
			}
		}
	}
194609
public function minify(array $options = array())
    {
        if (!class_exists('Wa72\\HtmlPrettymin\\PrettyMin')) {
            throw new \Exception('Function minify needs composer package wa72/html-pretty-min');
        }
        $pm = new PrettyMin($options);
        $pm->load($this->dom)->minify();
        return $this;
    }
498226
private function cmdJss()
    {
        if ($jss = $this->config->get('jss')) {
            echo "\n - Compiled JS+CSS -\n";

            if (!$this->subCmd) {
                foreach ($jss as $k => $v) {
                    echo "\n - $k:\n";
                    $this->jssCompiler($v);
                }
                return;
            }

            if (isset($jss->{$this->subCmd})) {
                echo "\n - ".$this->subCmd."\n";
                
                $this->jssCompiler($jss->{$this->subCmd});
                return;
            } else {
                echo "\n Err: Not found!\n";
                return;
            }
        }
    }
830693
function remove_inline_stylesheets(){
      for (var i = 0; i < styles.length; i++) {
        if (styles[i].length && styles[i] !== "\n") {
          html = html.replace(styles[i], "");
        }
      }
    }
108739
function uglify(js) {
		return ugli.minify(js, {
			fromString: true,
			mangle: false,
			compress: {
				warnings: false
			}
		}).code;
	}
431463
public function minify($json){
			$tokenizer = "/\"|(\/\*)|(\*\/)|(\/\/)|\n|\r/";
			$in_string = false;
			$in_multiline_comment = false;
			$in_singleline_comment = false;
			$tmp; $tmp2; $new_str = array(); $ns = 0; $from = 0; $lc; $rc; $lastIndex = 0;
			while (preg_match($tokenizer,$json,$tmp,PREG_OFFSET_CAPTURE,$lastIndex)){
				$tmp = $tmp[0];
				$lastIndex = $tmp[1] + strlen($tmp[0]);
				$lc = substr($json,0,$lastIndex - strlen($tmp[0]));
				$rc = substr($json,$lastIndex);
				if (!$in_multiline_comment && !$in_singleline_comment){
					$tmp2 = substr($lc,$from);
					if (!$in_string){
						$tmp2 = preg_replace("/(\n|\r|\s)*/","",$tmp2);
					}
					$new_str[] = $tmp2;
				}
				$from = $lastIndex;
				if ($tmp[0] == "\"" && !$in_multiline_comment && !$in_singleline_comment){
					preg_match("/(\\\\)*$/",$lc,$tmp2);
					if (!$in_string || !$tmp2 || (strlen($tmp2[0]) % 2) == 0){ // start of string with ", or unescaped " character found to end string
						$in_string = !$in_string;
					}
					$from--; // include " character in next catch
					$rc = substr($json,$from);
				} else if ($tmp[0] == "/*" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
					$in_multiline_comment = true;
				} else if ($tmp[0] == "*/" && !$in_string && $in_multiline_comment && !$in_singleline_comment){
					$in_multiline_comment = false;
				} else if ($tmp[0] == "//" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
					$in_singleline_comment = true;
				} else if (($tmp[0] == "\n" || $tmp[0] == "\r") && !$in_string && !$in_multiline_comment && $in_singleline_comment){
					$in_singleline_comment = false;
				} else if (!$in_multiline_comment && !$in_singleline_comment && !(preg_match("/\n|\r|\s/",$tmp[0]))){
					$new_str[] = $tmp[0];
				}
			}
			$new_str[] = $rc;
			return implode("",$new_str);
		}
601725
def minify(tokens, options):
    
    # Remove comments
    remove_comments(tokens)
    # Remove docstrings
    remove_docstrings(tokens)
    result = token_utils.untokenize(tokens)
    # Minify our input script
    result = multiline_indicator.sub('', result)
    result = fix_empty_methods(result)
    result = join_multiline_pairs(result)
    result = join_multiline_pairs(result, '[]')
    result = join_multiline_pairs(result, '{}')
    result = remove_blank_lines(result)
    result = reduce_operators(result)
    result = dedent(result, use_tabs=options.tabs)
    return result
192199
private function assets()
    {
        $s = '';
        foreach($this->styles as $id=>$f){
            $s .= '<link id="stylesheet_'.$id.'" rel="stylesheet" href="'.$this->url.'css/'.$f.'.css">'."\n\t";
        }
        $this->val('style', $s);

        $s = '<script id="javascript_base">var URL=\''.$this->url.'\'';

        foreach ($this->jsvalues as $n=>$v) {
            $s .= ','.$n.'='.(is_string($v) ? '\''.str_replace("'", '"', $v).'\'' : $v);
        }
        $s .= ';</script>';
        
        foreach($this->scripts as $id=>$f){
            $s .= "\n\t".'<script id="javascript_'.$id.'" src="'.$this->url.'js/'.$f.'.js"></script>';
        }
        $this->val('script', $s); //e($this);
    }
246555
public static function minify($source, array $filters = null, array $plugins = null)
		{
		self::$errors = array();
		$minifier = new CssMinifier($source, $filters, $plugins);
		return $minifier->getMinified();
		}