Generate a compiled asset, with all the configured filters applied.

@param AssetTarget $target The target to build
@return The processed result of $target and it dependencies.
@throws RuntimeException
426501
public function generate(AssetTarget $build)
    {
        $filters = $this->filterRegistry->collection($build);
        $output = '';
        foreach ($build->files() as $file) {
            $content = $file->contents();
            $content = $filters->input($file->path(), $content);
            $output .= $content . "\n";
        }
        if (!$this->debug || php_sapi_name() === 'cli') {
            $output = $filters->output($build->path(), $output);
        }
        return trim($output);
    }
627870
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 = tempnam(sys_get_temp_dir(), 'input');

        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());
    }
1317785
public function getMainFromTarget(int $target): int
    {
        if (!array_key_exists($target, $this->targetMap)) {
            throw new \RuntimeException('Not mapped');
        }
        return $this->targetMap[$target];
    }
1350373
private function findTargetCompiler($target, $mode): CompilationTarget
    {
        /** @var CompilationTarget $targetCompiler */
        foreach ($this->compilationTargets as $targetCompiler) {
            if ($targetCompiler->supports($target, $mode)) {
                return $targetCompiler;
            }
        }

        throw new TargetUnsupportedException('The given target is not supported.');
    }
813309
public function setTarget($target) {
        if (strpos($target, '%s') === false) {
            throw new \InvalidArgumentException('Searchable target url should contain \'%s\'.');
        }
        $this->target = $target;
        return $this;
    }
944300
public function setTarget($target)
    {
        if ((!$target instanceof PaletteInterface) && (!$target instanceof PropertyInterface)) {
            throw new DcGeneralInvalidArgumentException();
        }

        $this->target = $target;
        return $this;
    }
608560
private function preload($target, $alias)
    {
        if (!is_file($target) || !is_readable($target)) {
            throw new RuntimeException('Either invalid file supplied or its not readable');
        }

        // Prepare base name
        if ($alias === null) {
            $baseName = FileManager::getBaseName($target);
        } else {
            $baseName = $alias;
        }

        // Grab the Mime-Type
        $mime = FileManager::getMimeType($target);

        $this->prepare($mime, $baseName);
    }
376803
public function build(array $filters = [])
    {
        $assets = [];
        foreach (array_keys($this->_queued) as $alias) {
            $this->_resolveDependencies($this->_collection->get($alias), $assets);
        }

        /** @var Asset $asset */
        $result = [
            Asset::TYPE_JS_FILE  => [],
            Asset::TYPE_JS_CODE  => [],
            Asset::TYPE_JSX_FILE => [],
            Asset::TYPE_JSX_CODE => [],
            Asset::TYPE_CSS_FILE => [],
            Asset::TYPE_CSS_CODE => [],
            Asset::TYPE_CALLBACK => [],
        ];
        foreach ($assets as $asset) {

            $source = $asset->load($filters);

            if (Asset::TYPE_COLLECTION === $source[0]) {
                $source = $source[1];
            } else {
                $source = [$source];
            }

            foreach ($source as $sourceItem) {

                $type = $sourceItem[0];
                $src = $sourceItem[1];

                if ($src && !Arr::in($src, $result[$type])) {
                    $result[$type][] = $src;
                }
            }
        }

        return $result;
    }
153894
public function setup($target)
    {
        $installer = tempnam(sys_get_temp_dir(), 'install');
        $handle = fopen($installer, 'w+');

        $request = $this->guzzle->get('https://getcomposer.org/installer', null, $handle);

        try {
            $response = $request->send();
            fclose($handle);
        } catch (GuzzleException $e) {
            fclose($handle);
            throw new RuntimeException('Unable to download composer install script.');
        }

        if (200 !== $response->getStatusCode()) {
            @unlink($installer);
            throw new RuntimeException('Unable to download composer install script.');
        }

        $dir = getcwd();
        if (!@chdir(dirname($target))) {
            throw new RuntimeException('Unable to move to target directory for composer install.');
        }

        $process = ProcessBuilder::create([$this->phpExecutable, $installer])
            ->setTimeout(300)
            ->getProcess()
        ;

        try {
            $process->run();
            @unlink($installer);
        } catch (ProcessException $e) {
            @unlink($installer);
            throw new RuntimeException('Unable run composer install script.');
        }

        if (!@rename(getcwd() . '/composer.phar', $target)) {
            throw new RuntimeException('Composer install failed.');
        }

        if (!@chdir($dir)) {
            throw new RuntimeException('Unable to move back to origin directory.');
        }

        if (!$process->isSuccessful()) {
            throw new RuntimeException('Composer install failed.');
        }

        if (!file_exists($target)) {
            throw new RuntimeException('Composer install failed.');
        }
    }
875284
public function html(string $target)
    {
        $html = new Html\Facade();
        $html->process($this->coverage, $target);
    }
286655
protected function setFilter($filter, AssetInterface $asset)
    {
        if (is_null($filter)) {
            return;
        }

        if (!empty($filter['filter'])) {
            $this->ensureByFilter($asset, $filter['filter']);

            return;
        }

        if (!empty($filter['service'])) {
            $this->ensureByService($asset, $filter['service']);

            return;
        }

        throw new Exception\RuntimeException(
            'Invalid filter supplied. Expected Filter or Service.'
        );
    }
198920
private function canAddTarget($target, $mode)
    {
        // Mode is set to ignore existing targets
        if ($mode === self::DUPLICATE_IGNORE) {
            return false;
        }

        // Error if we're not allowed to overwrite or can't remove the existing target
        if ($mode !== self::DUPLICATE_OVERWRITE || !$this->filesystem->remove($target)) {
            throw new \RuntimeException(sprintf('Installation target "%s" already exists', $target));
        }

        return true;
    }
681127
public function extract($source, $target)
    {
        if (!$sourceRes = gzopen($source, 'r')) {
            throw new \RuntimeException(sprintf('Unable to read archive file "%s".', $source));
        }
        if (!$targetRes = fopen($target, 'w')) {
            throw new \RuntimeException(sprintf('Unable to write target file "%s".', $target));
        }
        while (!gzeof($sourceRes)) {
            fwrite($targetRes, gzread($sourceRes, $this->bufferSize));
        }
        if (!gzclose($sourceRes)) {
            throw new \RuntimeException(sprintf('Unable to close archive file "%s".', $source));
        }
        if (!fclose($targetRes)) {
            throw new \RuntimeException(sprintf('Unable to close target file "%s".', $target));
        }
    }
1175401
public function copy($target, $source)
    {
        if (!$this->exists($target)) {
            throw new \RuntimeException("$target does not exist.", E_ERROR);
        }

        if (!$this->exists($source)) {
            $this->makeDirectory(dirname($source), true);
        }

        return file_put_contents($source, $this->get($target));
    }
402631
private function downloadTemporaryFile($url, $target)
    {
        try {
            if (($fh = @fopen($target, 'w')) === false) {
                throw new RuntimeException(
                    sprintf(
                        'Could not create file "%s": %s',
                        $target,
                        @error_get_last()['message']
                    )
                );
            }

            if ((@fwrite($fh, $this->httpClient->get($url, 'application/octet-stream'))) === false) {
                throw new RuntimeException(
                    sprintf(
                        'The "%s" file could not be downloaded: %s',
                        $url,
                        @error_get_last()['message']
                    )
                );
            }
        } finally {
            if (is_resource($fh)) {
                fclose($fh);
            }
        }
    }
1232635
public function dump(
        $target = 'web/js',
        $pattern = self::DEFAULT_TRANSLATION_PATTERN,
        array $formats = array(),
        \stdClass $merge = null
    ) {
        $availableFormats  = array('js', 'json');

        $parts = array_filter(explode('/', $pattern));
        $this->filesystem->remove($target. '/' . current($parts));

        foreach ($formats as $format) {
            if (!in_array($format, $availableFormats)) {
                throw new \RuntimeException('The ' . $format . ' format is not available. Use only: ' . implode(', ', $availableFormats) . '.');
            }
        }

        if (empty($formats)) {
            $formats = $availableFormats;
        }

        $this->dumpConfig($pattern, $formats, $target);

        if ($merge && $merge->domains) {
            $this->dumpTranslationsPerLocale($pattern, $formats, $target);
        } else {
            $this->dumpTranslationsPerDomain($pattern, $formats, $target);
        }
    }
577939
private function getRenderer(int $target): RendererInterface
    {
        if ($target == self::OUTPUT && System::isCLI()) {
            if (System::isColorsSupported(STDOUT)) {
                $target = self::OUTPUT_CLI_COLORS;
            } else {
                $target = self::OUTPUT_CLI;
            }
        }

        if (!isset($this->targets[$target])) {
            throw new DumperException(sprintf("Undefined dump target %d", $target));
        }

        if (is_string($this->targets[$target])) {
            $this->targets[$target] = new $this->targets[$target]();
        }

        return $this->targets[$target];
    }