public static function run($pluginsInitCode, Kwf_SourceMaps_SourceMap $sourcemap)
 {
     $js = "\n            require('es6-promise').polyfill(); //required for older nodejs\n            var postcss = require('postcss');\n            var plugins = [];\n            " . $pluginsInitCode . "\n            var instance = postcss( plugins );\n            var css = '';\n            process.stdin.setEncoding('utf-8')\n            process.stdin.on('data', function(buf) { css += buf.toString(); });\n            process.stdin.on('end', function() {\n                instance.process(css).then(function (result) {\n                    process.stdout.write(result.css);\n                }).catch(function(e) {\n                    console.log(e);\n                    process.exit(1);\n                });\n            });\n            process.stdin.resume();\n        ";
     $runfile = tempnam("temp/", 'postcss');
     file_put_contents($runfile, $js);
     putenv("NODE_PATH=" . getcwd() . "/node_modules" . PATH_SEPARATOR . getcwd() . "/" . KWF_PATH . PATH_SEPARATOR . getcwd() . "/");
     $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . $runfile;
     $cmd .= " 2>&1";
     $process = new Symfony\Component\Process\Process($cmd);
     $mapData = $sourcemap->getMapContentsData(false);
     $hasSourcemap = !!$mapData->mappings;
     if ($hasSourcemap) {
         $process->setInput($sourcemap->getFileContentsInlineMap(false));
     } else {
         $process->setInput($sourcemap->getFileContents());
     }
     if ($process->run() !== 0) {
         throw new Kwf_Exception("Process '{$cmd}' failed with " . $process->getExitCode() . "\n" . $process->getOutput());
     }
     putenv("NODE_PATH=");
     unlink($runfile);
     $out = $process->getOutput();
     if (Kwf_SourceMaps_SourceMap::hasInline($out)) {
         $ret = Kwf_SourceMaps_SourceMap::createFromInline($out);
     } else {
         $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($out);
         $ret->setMimeType('text/css');
     }
     $ret->setSources($sourcemap->getSources());
     return $ret;
 }
 /**
  * Runs task
  */
 protected function _run()
 {
     $this->_Process = new TaskProcess($this->_task['command'] . $this->_argsToString($this->_task['arguments']), $this->_task['path']);
     $this->_Process->setTimeout($this->_task['timeout']);
     try {
         $this->_Process->start(function ($type, $buffer) {
             if ('err' === $type) {
                 $this->_Shell->err($buffer);
                 $this->_task['stderr'] .= $buffer;
             } else {
                 $this->_Shell->out($buffer);
                 $this->_task['stdout'] .= $buffer;
             }
             $this->_TaskServer->updated($this->_task);
         });
         while ($this->_Process->isRunning()) {
             $this->_task['process_id'] = (int) $this->_Process->getPid();
             $this->_TaskServer->updateStatistics($this->_task);
             $this->_Process->checkTimeout();
             sleep(Configure::read('Task.checkInterval'));
             if ($this->_TaskServer->mustStop($this->_task['id'])) {
                 $this->_Process->stop(Configure::read('Task.stopTimeout'));
                 $this->_task['code'] = 143;
                 $this->_task['code_string'] = TaskProcess::$exitCodes[143];
                 return $this->_stopped(true);
             }
         }
         $this->_task['code'] = $this->_Process->getExitCode();
         $this->_task['code_string'] = $this->_Process->getExitCodeText();
     } catch (Exception $Exception) {
         $this->_task['code'] = 134;
         $this->_task['code_string'] = $Exception->getMessage();
     }
     $this->_stopped(false);
 }
Example #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('command')) {
         $output->writeln("<error>Missing required option: --command</error>");
         return 1;
     }
     $statusCode = 0;
     if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
         $output->writeln("<info>[[ Finding repositories ]]</info>");
     }
     $scanner = new \GitScan\GitRepoScanner();
     $gitRepos = $scanner->scan($input->getArgument('path'));
     foreach ($gitRepos as $gitRepo) {
         /** @var \GitScan\GitRepo $gitRepo */
         if (!$gitRepo->matchesStatus($input->getOption('status'))) {
             continue;
         }
         $topLevel = $this->fs->findFirstParent($gitRepo->getPath(), $input->getArgument('path'));
         if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->writeln("<info>[[ {$gitRepo->getPath()} ]]</info>");
         }
         $process = new \Symfony\Component\Process\Process($input->getOption('command'));
         $process->setWorkingDirectory($gitRepo->getPath());
         // $process->setEnv(...); sucks in Debian/Ubuntu
         putenv("path=" . $this->fs->makePathRelative($gitRepo->getPath(), $topLevel));
         putenv("toplevel=" . $topLevel);
         $errorOutput = $output;
         if (is_callable($output, 'getErrorOutput') && $output->getErrorOutput()) {
             $errorOutput = $output->getErrorOutput();
         }
         $process->run(function ($type, $buffer) use($output, $errorOutput) {
             if (\Symfony\Component\Process\Process::ERR === $type) {
                 if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                     $errorOutput->write("<error>STDERR</error> ");
                 }
                 $errorOutput->write($buffer, FALSE, OutputInterface::OUTPUT_RAW);
             } else {
                 if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                     $output->write("<comment>STDOUT</comment> ");
                 }
                 $output->write($buffer, FALSE, OutputInterface::OUTPUT_RAW);
             }
         });
         if (!$process->isSuccessful()) {
             $errorOutput->writeln("<error>[[ {$gitRepo->getPath()}: exit code = {$process->getExitCode()} ]]</error>");
             $statusCode = 2;
         }
     }
     putenv("path");
     putenv("toplevel");
     return $statusCode;
 }
 protected function compileWithCommand($bin, $source, $target)
 {
     $sourceFilePath = trim(Director::getAbsFile($source));
     $targetFilePath = trim(Director::getAbsFile($target));
     $command = $bin . " " . escapeshellarg($sourceFilePath);
     $process = new \Symfony\Component\Process\Process($command);
     $process->run();
     if ($process->isSuccessful()) {
         $css = $process->getOutput();
         if (!file_exists(dirname($targetFilePath))) {
             mkdir(dirname($targetFilePath), null, true);
         }
         file_put_contents($targetFilePath, $css);
         $this->filesCacheAdd($source);
         $this->log[] = ["compiled {$source} to {$target}", 'info'];
     } else {
         $message = $process->getErrorOutput();
         if ($process->getExitCode() != 1 || !$message) {
             $message = "\"{$command}\": non-zero exit code {$process->getExitCode()} '{$process->getExitCodeText()}'. (Output: '{$message}')";
         }
         $this->log[] = ["failed to compile {$source} with {$bin}: {$message}", 'error'];
         SS_Log::log(new Exception($message), SS_Log::ERR);
     }
 }
Example #5
0
 */
$yml = new Symfony\Component\Yaml\Yaml();
$tests = $yml->parse(__DIR__ . '/../behat.yml');
$run = [];
$env = getenv('APP_ENV');
foreach ($tests as $key => $test) {
    if (strpos($key, $env) !== false) {
        $run[] = $key;
    }
}
$failing_test = [];
foreach ($run as $test) {
    $command = "bin/behat --stop-on-failure --no-paths --tags='@api,~@wip' --profile={$test}";
    $run = new \Symfony\Component\Process\Process($command);
    $run->setTimeout(600);
    $run->run(function ($type, $buffer) use($failing_test, $test) {
        if (Symfony\Component\Process\Process::ERR === $type) {
            $failing_test[] = $test;
            //throw new \Exception(sprintf("Test Failed %s", $buffer));
        } else {
            echo $buffer;
        }
    });
    if ($run->getExitCode() != 0) {
        $failing_test[] = $test;
    }
}
if (count($failing_test)) {
    $message = print_r($failing_test, 1);
    throw new \Exception(sprintf("Tests Failed the behat profiles are %s", $message));
}