collector.php 911 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. $files = glob($_SERVER['argv'][1] . "/*.html");
  3. $segments = array_filter(explode('/', $_SERVER['argv'][1]));
  4. $last = array_pop($segments);
  5. $outputFile = implode('/', $segments) . "/{$last}.js";
  6. $functions = array();
  7. $functionBodies = array();
  8. foreach ($files as $file)
  9. {
  10. $content = file_get_contents($file);
  11. $first = "// expose test function names";
  12. $start = strpos($content, $first);
  13. $end = strpos($content, "</script>", $start + strlen($first));
  14. $substring = substr($content, $start+$first, $end-$start);
  15. $function = substr($substring, strpos($substring, "/**"));
  16. $function = str_replace("function ", "", $function);
  17. $function = str_replace("() {", " : function () {", $function);
  18. // parse out the actual function
  19. array_push($functionBodies, trim($function));
  20. }
  21. file_put_contents($outputFile, "exports.tests = {\n".implode(",\n", array_filter($functionBodies)) . '\n}');