コード例 #1
0
 public function filterLoad(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->emberBin) : array($this->emberBin));
     if ($sourcePath = $asset->getSourcePath()) {
         $templateName = basename($sourcePath);
     } else {
         throw new \LogicException('The embed-precompile filter requires that assets have a source path set');
     }
     $inputDirPath = FilesystemUtils::createThrowAwayDirectory('ember_in');
     $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName;
     $outputPath = FilesystemUtils::createTemporaryFile('ember_out');
     file_put_contents($inputPath, $asset->getContent());
     $pb->add($inputPath)->add('-f')->add($outputPath);
     $process = $pb->getProcess();
     $returnCode = $process->run();
     unlink($inputPath);
     rmdir($inputDirPath);
     if (127 === $returnCode) {
         throw new \RuntimeException('Path to node executable could not be resolved.');
     }
     if (0 !== $returnCode) {
         if (file_exists($outputPath)) {
             unlink($outputPath);
         }
         throw FilterException::fromProcess($process)->setInput($asset->getContent());
     }
     if (!file_exists($outputPath)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $compiledJs = file_get_contents($outputPath);
     unlink($outputPath);
     $asset->setContent($compiledJs);
 }
コード例 #2
0
ファイル: JpegtranFilter.php プロジェクト: Dren-x/mobit
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->jpegtranBin));
     if ($this->optimize) {
         $pb->add('-optimize');
     }
     if ($this->copy) {
         $pb->add('-copy')->add($this->copy);
     }
     if ($this->progressive) {
         $pb->add('-progressive');
     }
     if (null !== $this->restart) {
         $pb->add('-restart')->add($this->restart);
     }
     $pb->add($input = FilesystemUtils::createTemporaryFile('jpegtran'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #3
0
 public function filterLoad(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->tscBin) : array($this->tscBin));
     if ($sourcePath = $asset->getSourcePath()) {
         $templateName = basename($sourcePath);
     } else {
         $templateName = 'asset';
     }
     $inputDirPath = FilesystemUtils::createThrowAwayDirectory('typescript_in');
     $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName . '.ts';
     $outputPath = FilesystemUtils::createTemporaryFile('typescript_out');
     file_put_contents($inputPath, $asset->getContent());
     $pb->add($inputPath)->add('--out')->add($outputPath);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($inputPath);
     rmdir($inputDirPath);
     if (0 !== $code) {
         if (file_exists($outputPath)) {
             unlink($outputPath);
         }
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     if (!file_exists($outputPath)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $compiledJs = file_get_contents($outputPath);
     unlink($outputPath);
     $asset->setContent($compiledJs);
 }
コード例 #4
0
ファイル: UglifyCssFilter.php プロジェクト: Dren-x/mobit
 /**
  * Run the asset through UglifyJs
  *
  * @see Assetic\Filter\FilterInterface::filterDump()
  */
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->uglifycssBin) : array($this->uglifycssBin));
     if ($this->expandVars) {
         $pb->add('--expand-vars');
     }
     if ($this->uglyComments) {
         $pb->add('--ugly-comments');
     }
     if ($this->cuteComments) {
         $pb->add('--cute-comments');
     }
     // input and output files
     $input = FilesystemUtils::createTemporaryFile('uglifycss');
     file_put_contents($input, $asset->getContent());
     $pb->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (127 === $code) {
         throw new \RuntimeException('Path to node executable could not be resolved.');
     }
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #5
0
 public function filterDump(AssetInterface $asset)
 {
     $is64bit = PHP_INT_SIZE === 8;
     $cleanup = array();
     $pb = new ProcessBuilder(array_merge(array($this->javaPath), $is64bit ? array('-server', '-XX:+TieredCompilation') : array('-client', '-d32'), array('-jar', $this->jarPath)));
     if (null !== $this->timeout) {
         $pb->setTimeout($this->timeout);
     }
     if (null !== $this->compilationLevel) {
         $pb->add('--compilation_level')->add($this->compilationLevel);
     }
     if (null !== $this->jsExterns) {
         $cleanup[] = $externs = FilesystemUtils::createTemporaryFile('google_closure');
         file_put_contents($externs, $this->jsExterns);
         $pb->add('--externs')->add($externs);
     }
     if (null !== $this->externsUrl) {
         $cleanup[] = $externs = FilesystemUtils::createTemporaryFile('google_closure');
         file_put_contents($externs, file_get_contents($this->externsUrl));
         $pb->add('--externs')->add($externs);
     }
     if (null !== $this->excludeDefaultExterns) {
         $pb->add('--use_only_custom_externs');
     }
     if (null !== $this->formatting) {
         $pb->add('--formatting')->add($this->formatting);
     }
     if (null !== $this->useClosureLibrary) {
         $pb->add('--manage_closure_dependencies');
     }
     if (null !== $this->warningLevel) {
         $pb->add('--warning_level')->add($this->warningLevel);
     }
     if (null !== $this->language) {
         $pb->add('--language_in')->add($this->language);
     }
     if (null !== $this->flagFile) {
         $pb->add('--flagfile')->add($this->flagFile);
     }
     $pb->add('--js')->add($cleanup[] = $input = FilesystemUtils::createTemporaryFile('google_closure'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     array_map('unlink', $cleanup);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #6
0
 public function filterLoad(AssetInterface $asset)
 {
     $input = $asset->getContent();
     $pb = $this->createProcessBuilder(array($this->autoprefixerBin));
     $pb->setInput($input);
     if ($this->browsers) {
         $pb->add('-b')->add(implode(',', $this->browsers));
     }
     $output = FilesystemUtils::createTemporaryFile('autoprefixer');
     $pb->add('-o')->add($output);
     $proc = $pb->getProcess();
     if (0 !== $proc->run()) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }
コード例 #7
0
 public function filterLoad(AssetInterface $asset)
 {
     $input = FilesystemUtils::createTemporaryFile('dart');
     $output = FilesystemUtils::createTemporaryFile('dart');
     file_put_contents($input, $asset->getContent());
     $pb = $this->createProcessBuilder()->add($this->dartBin)->add('-o' . $output)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         $this->cleanup($output);
         throw FilterException::fromProcess($proc);
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $asset->setContent(file_get_contents($output));
     $this->cleanup($output);
 }
コード例 #8
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->jpegoptimBin));
     if ($this->stripAll) {
         $pb->add('--strip-all');
     }
     if ($this->max) {
         $pb->add('--max=' . $this->max);
     }
     $pb->add($input = FilesystemUtils::createTemporaryFile('jpegoptim'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $proc->run();
     if (false !== strpos($proc->getOutput(), 'ERROR')) {
         unlink($input);
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($input));
     unlink($input);
 }
コード例 #9
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->optipngBin));
     if (null !== $this->level) {
         $pb->add('-o')->add($this->level);
     }
     $pb->add('-out')->add($output = FilesystemUtils::createTemporaryFile('optipng_out'));
     unlink($output);
     $pb->add($input = FilesystemUtils::createTemporaryFile('optinpg_in'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     if (0 !== $code) {
         unlink($input);
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($input);
     unlink($output);
 }
コード例 #10
0
ファイル: CoffeeScriptFilter.php プロジェクト: Dren-x/mobit
 public function filterLoad(AssetInterface $asset)
 {
     $input = FilesystemUtils::createTemporaryFile('coffee');
     file_put_contents($input, $asset->getContent());
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->coffeeBin) : array($this->coffeeBin));
     $pb->add('-cp');
     if ($this->bare) {
         $pb->add('--bare');
     }
     if ($this->noHeader) {
         $pb->add('--no-header');
     }
     $pb->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #11
0
    /**
     * Hack around a bit, get the job done.
     */
    public function filterLoad(AssetInterface $asset)
    {
        static $format = <<<'EOF'
#!/usr/bin/env ruby

require %s
%s
options = { :load_path    => [],
            :source_files => [%s],
            :expand_paths => false }

%ssecretary = Sprockets::Secretary.new(options)
secretary.install_assets if options[:asset_root]
print secretary.concatenation

EOF;
        $more = '';
        foreach ($this->includeDirs as $directory) {
            $more .= 'options[:load_path] << ' . var_export($directory, true) . "\n";
        }
        if (null !== $this->assetRoot) {
            $more .= 'options[:asset_root] = ' . var_export($this->assetRoot, true) . "\n";
        }
        if ($more) {
            $more .= "\n";
        }
        $tmpAsset = FilesystemUtils::createTemporaryFile('sprockets_asset');
        file_put_contents($tmpAsset, $asset->getContent());
        $input = FilesystemUtils::createTemporaryFile('sprockets_in');
        file_put_contents($input, sprintf($format, $this->sprocketsLib ? sprintf('File.join(%s, \'sprockets\')', var_export($this->sprocketsLib, true)) : '\'sprockets\'', $this->getHack($asset), var_export($tmpAsset, true), $more));
        $pb = $this->createProcessBuilder(array($this->rubyBin, $input));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($tmpAsset);
        unlink($input);
        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
        $asset->setContent($proc->getOutput());
    }
コード例 #12
0
ファイル: RooleFilter.php プロジェクト: Dren-x/mobit
 public function filterLoad(AssetInterface $asset)
 {
     $input = FilesystemUtils::createTemporaryFile('roole');
     $output = $input . '.css';
     file_put_contents($input, $asset->getContent());
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->rooleBin) : array($this->rooleBin));
     $pb->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         throw FilterException::fromProcess($proc);
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }
コード例 #13
0
    /**
     * {@inheritdoc}
     */
    public function filterLoad(AssetInterface $asset)
    {
        static $format = <<<'EOF'
var stylus = require('stylus');
var sys    = require(process.binding('natives').util ? 'util' : 'sys');

stylus(%s, %s)%s.render(function(e, css){
    if (e) {
        throw e;
    }

    sys.print(css);
    process.exit(0);
});

EOF;
        // parser options
        $parserOptions = array();
        if ($dir = $asset->getSourceDirectory()) {
            $parserOptions['paths'] = array($dir);
            $parserOptions['filename'] = basename($asset->getSourcePath());
        }
        if (null !== $this->compress) {
            $parserOptions['compress'] = $this->compress;
        }
        $pb = $this->createProcessBuilder();
        $pb->add($this->nodeBin)->add($input = FilesystemUtils::createTemporaryFile('stylus'));
        file_put_contents($input, sprintf($format, json_encode($asset->getContent()), json_encode($parserOptions), $this->useNib ? '.use(require(\'nib\')())' : ''));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);
        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
        $asset->setContent($proc->getOutput());
    }
コード例 #14
0
 /**
  * Run the asset through UglifyJs
  *
  * @see Assetic\Filter\FilterInterface::filterDump()
  */
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->uglifyjsBin) : array($this->uglifyjsBin));
     if ($this->noCopyright) {
         $pb->add('--no-copyright');
     }
     if ($this->beautify) {
         $pb->add('--beautify');
     }
     if ($this->unsafe) {
         $pb->add('--unsafe');
     }
     if (false === $this->mangle) {
         $pb->add('--no-mangle');
     }
     if ($this->defines) {
         foreach ($this->defines as $define) {
             $pb->add('-d')->add($define);
         }
     }
     // input and output files
     $input = FilesystemUtils::createTemporaryFile('uglifyjs_in');
     $output = FilesystemUtils::createTemporaryFile('uglifyjs_out');
     file_put_contents($input, $asset->getContent());
     $pb->add('-o')->add($output)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         if (127 === $code) {
             throw new \RuntimeException('Path to node executable could not be resolved.');
         }
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $uglifiedJs = file_get_contents($output);
     unlink($output);
     $asset->setContent($uglifiedJs);
 }
コード例 #15
0
 private function processCall($call, array $protoOptions = array())
 {
     $tmp = FilesystemUtils::createTemporaryFile('php_formula_loader');
     file_put_contents($tmp, implode("\n", array('<?php', $this->registerSetupCode(), $call, 'echo serialize($_call);')));
     $args = unserialize(shell_exec('php ' . escapeshellarg($tmp)));
     unlink($tmp);
     $inputs = isset($args[0]) ? self::argumentToArray($args[0]) : array();
     $filters = isset($args[1]) ? self::argumentToArray($args[1]) : array();
     $options = isset($args[2]) ? $args[2] : array();
     if (!isset($options['debug'])) {
         $options['debug'] = $this->factory->isDebug();
     }
     if (!is_array($options)) {
         throw new \RuntimeException('The third argument must be omitted, null or an array.');
     }
     // apply the prototype options
     $options += $protoOptions;
     if (!isset($options['name'])) {
         $options['name'] = $this->factory->generateAssetName($inputs, $filters, $options);
     }
     return array($options['name'] => array($inputs, $filters, $options));
 }
コード例 #16
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->pngoutBin));
     if (null !== $this->color) {
         $pb->add('-c' . $this->color);
     }
     if (null !== $this->filter) {
         $pb->add('-f' . $this->filter);
     }
     if (null !== $this->strategy) {
         $pb->add('-s' . $this->strategy);
     }
     if (null !== $this->blockSplitThreshold) {
         $pb->add('-b' . $this->blockSplitThreshold);
     }
     $pb->add($input = FilesystemUtils::createTemporaryFile('pngout_in'));
     file_put_contents($input, $asset->getContent());
     $output = FilesystemUtils::createTemporaryFile('pngout_out');
     unlink($output);
     $pb->add($output .= '.png');
     $proc = $pb->getProcess();
     $code = $proc->run();
     if (0 !== $code) {
         unlink($input);
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent(file_get_contents($output));
     unlink($input);
     unlink($output);
 }
コード例 #17
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->javaPath, '-jar', $this->jarPath));
     if (null !== $this->charset) {
         $pb->add('--charset')->add($this->charset);
     }
     if ($this->mhtml) {
         $pb->add('--mhtml');
     }
     if (null !== $this->mhtmlRoot) {
         $pb->add('--mhtmlroot')->add($this->mhtmlRoot);
     }
     // automatically define root if not already defined
     if (null === $this->root) {
         if ($dir = $asset->getSourceDirectory()) {
             $pb->add('--root')->add($dir);
         }
     } else {
         $pb->add('--root')->add($this->root);
     }
     if ($this->skipMissing) {
         $pb->add('--skip-missing');
     }
     if (null !== $this->maxUriLength) {
         $pb->add('--max-uri-length')->add($this->maxUriLength);
     }
     if (null !== $this->maxImageSize) {
         $pb->add('--max-image-size')->add($this->maxImageSize);
     }
     // input
     $pb->add($input = FilesystemUtils::createTemporaryFile('cssembed'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #18
0
 public function filterLoad(AssetInterface $asset)
 {
     $cleanup = array();
     $pb = $this->createProcessBuilder(array($this->javaPath, '-jar', $this->jarPath));
     if (null !== $this->allowUnrecognizedFunctions) {
         $pb->add('--allow-unrecognized-functions');
     }
     if (null !== $this->allowedNonStandardFunctions) {
         $pb->add('--allowed_non_standard_functions')->add($this->allowedNonStandardFunctions);
     }
     if (null !== $this->copyrightNotice) {
         $pb->add('--copyright-notice')->add($this->copyrightNotice);
     }
     if (null !== $this->define) {
         $pb->add('--define')->add($this->define);
     }
     if (null !== $this->gssFunctionMapProvider) {
         $pb->add('--gss-function-map-provider')->add($this->gssFunctionMapProvider);
     }
     if (null !== $this->inputOrientation) {
         $pb->add('--input-orientation')->add($this->inputOrientation);
     }
     if (null !== $this->outputOrientation) {
         $pb->add('--output-orientation')->add($this->outputOrientation);
     }
     if (null !== $this->prettyPrint) {
         $pb->add('--pretty-print');
     }
     $pb->add($cleanup[] = $input = FilesystemUtils::createTemporaryFile('gss'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     array_map('unlink', $cleanup);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #19
0
ファイル: SassFilter.php プロジェクト: Dren-x/mobit
 public function filterLoad(AssetInterface $asset)
 {
     $sassProcessArgs = array($this->sassPath);
     if (null !== $this->rubyPath) {
         $sassProcessArgs = array_merge(explode(' ', $this->rubyPath), $sassProcessArgs);
     }
     $pb = $this->createProcessBuilder($sassProcessArgs);
     if ($dir = $asset->getSourceDirectory()) {
         $pb->add('--load-path')->add($dir);
     }
     if ($this->unixNewlines) {
         $pb->add('--unix-newlines');
     }
     if (true === $this->scss || null === $this->scss && 'scss' == pathinfo($asset->getSourcePath(), PATHINFO_EXTENSION)) {
         $pb->add('--scss');
     }
     if ($this->style) {
         $pb->add('--style')->add($this->style);
     }
     if ($this->precision) {
         $pb->add('--precision')->add($this->precision);
     }
     if ($this->quiet) {
         $pb->add('--quiet');
     }
     if ($this->debugInfo) {
         $pb->add('--debug-info');
     }
     if ($this->lineNumbers) {
         $pb->add('--line-numbers');
     }
     if ($this->sourceMap) {
         $pb->add('--sourcemap');
     }
     foreach ($this->loadPaths as $loadPath) {
         $pb->add('--load-path')->add($loadPath);
     }
     if ($this->cacheLocation) {
         $pb->add('--cache-location')->add($this->cacheLocation);
     }
     if ($this->noCache) {
         $pb->add('--no-cache');
     }
     if ($this->compass) {
         $pb->add('--compass');
     }
     // input
     $pb->add($input = FilesystemUtils::createTemporaryFile('sass'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #20
0
ファイル: LessFilter.php プロジェクト: raphydev/onep
    public function filterLoad(AssetInterface $asset)
    {
        static $format = <<<'EOF'
var less = require('less');
var sys  = require(process.binding('natives').util ? 'util' : 'sys');

less.render(%s, %s, function(error, css) {
    if (error) {
        less.writeError(error);
        process.exit(2);
    }
    try {
        if (typeof css == 'string') {
            sys.print(css);
        } else {
            sys.print(css.css);
        }
    } catch (e) {
        less.writeError(error);
        process.exit(3);
    }
});

EOF;
        // parser options
        $parserOptions = $this->parserOptions;
        if ($dir = $asset->getSourceDirectory()) {
            $parserOptions['paths'] = array($dir);
            $parserOptions['filename'] = basename($asset->getSourcePath());
        }
        foreach ($this->loadPaths as $loadPath) {
            $parserOptions['paths'][] = $loadPath;
        }
        $pb = $this->createProcessBuilder();
        $pb->add($this->nodeBin)->add($input = FilesystemUtils::createTemporaryFile('less'));
        file_put_contents($input, sprintf($format, json_encode($asset->getContent()), json_encode(array_merge($parserOptions, $this->treeOptions))));
        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);
        if (0 !== $code) {
            throw FilterException::fromProcess($proc)->setInput($asset->getContent());
        }
        $asset->setContent($proc->getOutput());
    }
コード例 #21
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder($this->nodeBin ? array($this->nodeBin, $this->uglifyjsBin) : array($this->uglifyjsBin));
     if ($this->compress) {
         $pb->add('--compress');
         if (is_string($this->compress) && !empty($this->compress)) {
             $pb->add($this->compress);
         }
     }
     if ($this->beautify) {
         $pb->add('--beautify');
     }
     if ($this->mangle) {
         $pb->add('--mangle');
     }
     if ($this->screwIe8) {
         $pb->add('--screw-ie8');
     }
     if ($this->comments) {
         $pb->add('--comments')->add(true === $this->comments ? 'all' : $this->comments);
     }
     if ($this->wrap) {
         $pb->add('--wrap')->add($this->wrap);
     }
     if ($this->defines) {
         $pb->add('--define')->add(implode(',', $this->defines));
     }
     // input and output files
     $input = FilesystemUtils::createTemporaryFile('uglifyjs2_in');
     $output = FilesystemUtils::createTemporaryFile('uglifyjs2_out');
     file_put_contents($input, $asset->getContent());
     $pb->add('-o')->add($output)->add($input);
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         if (file_exists($output)) {
             unlink($output);
         }
         if (127 === $code) {
             throw new \RuntimeException('Path to node executable could not be resolved.');
         }
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     if (!file_exists($output)) {
         throw new \RuntimeException('Error creating output file.');
     }
     $asset->setContent(file_get_contents($output));
     unlink($output);
 }