Mirror of Awesome Self Hosted
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.3 KiB

  1. const fs = require('fs');
  2. var testStatus;
  3. var file = fs.readFileSync('README.md', 'utf8')
  4. entryErrorCheck(file);
  5. return testStatus;
  6. function entryErrorCheck(md) {
  7. var namepatt = /\*\s\[(.*?)\]/;
  8. var entries = split(md);
  9. var totalFail = 0;
  10. var totalPass = 0;
  11. var total = 0;
  12. var entryArray = [];
  13. for (var i = 0, len = entries.length; i < len; i++) {
  14. entryArray[i] = new Object;
  15. entryArray[i].raw = entries[i];
  16. //console.log(entries[i]);
  17. //console.log(entryArray[i].raw);
  18. //console.log(entryFilter(entries[i]));
  19. if (entryFilter(entries[i]) === true){
  20. total += 1;
  21. entryArray[i].name = namepatt.exec(entries[i])[1];
  22. //console.log('name' + entryArray[i].name);
  23. //entryArray[i].error = "";
  24. entryArray[i].pass = findPattern(entries[i], i);
  25. if (entryArray[i].pass == true) {
  26. totalPass += 1;
  27. //console.log(i + 1 + ". Pass: " + entryArray[i].name);
  28. } else {
  29. console.log("Line #" + (i + 1) + ". Fail: " + entryArray[i].name);
  30. //console.log(entries[i]);
  31. totalFail += 1;
  32. }
  33. }
  34. }
  35. if (totalFail > 0) {
  36. console.log(totalFail + " Failed, " + totalPass + " Passed, of " + total);
  37. process.exit(1);
  38. } else {
  39. console.log(totalFail + " Failed, " + totalPass + " Passed, of " + total);
  40. process.exit(0);
  41. }
  42. //console.log(entries[i])
  43. //console.log(totalPass + "|" + totalFail);
  44. };
  45. function entryFilter(md) {
  46. var linepatt = /^\s{0,4}\*\s\[.*\`/;
  47. return linepatt.test(md);
  48. }
  49. function split(text){
  50. //cutOne = text.split("<!-- BEGIN SOFTWARE LIST -->");
  51. //cutTwo = cutOne[1].split("<!-- END SOFTWARE LIST -->");
  52. //cutThree = cutTwo[0].replace(/^\#.*$|^\_.*$|^See.*$|^Some.*$|^\*.*\*$|^\s\*.*\*$|^CMS.*$|^\*\*\[.*$/mg, "");
  53. return text.split(/\r?\n/);
  54. }
  55. function parseMD(md) {
  56. return split(md).filter(entryFilter);
  57. //console.log(entries);
  58. //console.log (entries.length);
  59. //console.log(entries[0]);
  60. //console.log(entries[entries.length - 1]);
  61. }
  62. function findPattern(text, i) {
  63. var nodnospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no demo and no source code
  64. var slpatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Demo\b\]\((.*?)\)\,\s\[Source Code\b\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with demo and source code
  65. var nodpatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no demo
  66. var nospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no source code
  67. var pnodnospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\`(\⚠)\`\s\-\s(.{0,249}?\.\s)\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with proprietary with no demo and no source code
  68. var pslpatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\`(\⚠)\`\s\-\s(.{0,249}?\.\s)\(\[Demo\b\]\((.*?)\)\,\s\[Source Code\b\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with proprietary with demo and source code
  69. var pnodpatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\`(\⚠)\`\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with proprietary with no demo
  70. var pnospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\`(\⚠)\`\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with proprietary with no source code
  71. if (nodnospatt.test(text) == true) {
  72. return true;
  73. } else if (slpatt.test(text) == true) {
  74. return true;
  75. } else if (nodpatt.test(text) == true) {
  76. return true;
  77. } else if (nospatt.test(text) == true) {
  78. return true;
  79. } else if (pnodnospatt.test(text) == true) {
  80. return true;
  81. } else if (pslpatt.test(text) == true) {
  82. return true;
  83. } else if (pnodpatt.test(text) == true) {
  84. return true;
  85. } else if (pnospatt.test(text) == true) {
  86. return true;
  87. } else {
  88. //document.getElementById("alert").innerHTML = "Error(s) Found, check your syntax!";
  89. return false;
  90. }
  91. };