jscov.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. require_once dirname( __FILE__ ) .'/../config.php';
  3. /**
  4. * Created by JetBrains PhpStorm.
  5. * User: lisisi01
  6. * Date: 12-9-13
  7. * Time: 下午12:36
  8. * To change this template use File | Settings | File Templates.
  9. */
  10. function source(){
  11. $sourcePath=dirname( __FILE__ ) .'/source.js';
  12. $as = array();
  13. $is = list_file(Config::$COVERAGE_PATH,$as);
  14. $string = 'function loadSource(){'."\n";
  15. $file = fopen($sourcePath,"a");
  16. if($file)
  17. fwrite($file,$string);
  18. else {
  19. print "fail read file";
  20. return '';
  21. }
  22. foreach($is as $i) {
  23. $path = explode(Config::$COVERAGE_PATH.'/', $i);
  24. $path = $path[1];
  25. if(file_exists($i)){
  26. $f = fopen($i,'r');
  27. while(!feof($f))
  28. {
  29. $s = fgets($f);
  30. if(!!strpos($s,'].source')){
  31. $string='_$jscoverage[\''.$path.'\'] &&'.' (';
  32. $string.=substr($s,0,-2).');'."\n";
  33. if(!$file)
  34. $file = fopen($sourcePath,"a");
  35. fwrite($file,$string);
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. $string='}';
  42. if(!$file)
  43. $file = fopen($sourcePath,"a");
  44. fwrite($file,$string);
  45. fclose($file);
  46. }
  47. function list_file($dir,$as){
  48. $list = scandir($dir); // 得到该文件下的所有文件和文件夹
  49. foreach($list as $file){//遍历
  50. $file_location=$dir."/".$file;//生成路径
  51. if(is_dir($file_location) && $file!="." &&$file!=".."){ //判断是不是文件夹
  52. $as = list_file($file_location,$as); //继续遍历
  53. }
  54. else if(substr(basename($file), -3) == '.js' && basename($file)!="jscoverage.js")
  55. array_push($as, $file_location);
  56. }
  57. return $as;
  58. }
  59. ?>