forked from jsdom/jsdom
/
collector.php
36 lines (21 loc) · 917 Bytes
/
collector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$files = glob($_SERVER['argv'][1] . "/*.html");
$segments = array_filter(explode('/', $_SERVER['argv'][1]));
$last = array_pop($segments);
$outputFile = implode('/', $segments) . "/{$last}.js";
$functions = array();
$functionBodies = array();
foreach ($files as $file)
{
$content = file_get_contents($file);
$first = "// expose test function names";
$start = strpos($content, $first);
$end = strpos($content, "</script>", $start + strlen($first));
$substring = substr($content, $start+$first, $end-$start);
$function = substr($substring, strpos($substring, "/**"));
$function = str_replace("function ", "", $function);
$function = str_replace("() {", " : function () {", $function);
// parse out the actual function
array_push($functionBodies, trim($function));
}
file_put_contents($outputFile, "exports.tests = {\r\n".implode(",\r\n", array_filter($functionBodies)) . '\r\n}');