class TypeScriptFilter

Compiles TypeScript into JavaScript.

@link http://www.typescriptlang.org/ @author Jarrod Nettles <jarrod.nettles@icloud.com>

Hierarchy

Expanded class hierarchy of TypeScriptFilter

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Filter/TypeScriptFilter.php, line 23

Namespace

Assetic\Filter
View source
class TypeScriptFilter extends BaseNodeFilter {
  private $tscBin;
  private $nodeBin;
  public function __construct($tscBin = '/usr/bin/tsc', $nodeBin = null) {
    $this->tscBin = $tscBin;
    $this->nodeBin = $nodeBin;
  }
  public function filterLoad(AssetInterface $asset) {
    $pb = $this
      ->createProcessBuilder($this->nodeBin ? array(
      $this->nodeBin,
      $this->tscBin,
    ) : array(
      $this->tscBin,
    ));
    $templateName = basename($asset
      ->getSourcePath());
    $inputDirPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('input_dir');
    $inputPath = $inputDirPath . DIRECTORY_SEPARATOR . $templateName . '.ts';
    $outputPath = tempnam(sys_get_temp_dir(), 'output');
    mkdir($inputDirPath);
    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);
  }
  public function filterDump(AssetInterface $asset) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseNodeFilter::$nodePaths private property
BaseNodeFilter::addNodePath public function
BaseNodeFilter::createProcessBuilder protected function Creates a new process builder. Overrides BaseProcessFilter::createProcessBuilder
BaseNodeFilter::getNodePaths public function
BaseNodeFilter::setNodePaths public function
BaseProcessFilter::$timeout private property
BaseProcessFilter::mergeEnv protected function
BaseProcessFilter::setTimeout public function Set the process timeout.
TypeScriptFilter::$nodeBin private property
TypeScriptFilter::$tscBin private property
TypeScriptFilter::filterDump public function Filters an asset just before it's dumped. Overrides FilterInterface::filterDump
TypeScriptFilter::filterLoad public function Filters an asset after it has been loaded. Overrides FilterInterface::filterLoad
TypeScriptFilter::__construct public function