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.

100 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. process.exit(0);
  29. } else {
  30. console.log("Line #" + i + 1 + ". Fail: " + entryArray[i].name);
  31. //console.log(entries[i]);
  32. totalFail += 1;
  33. process.exit(1);
  34. }
  35. }
  36. }
  37. if (totalFail > 0) {
  38. console.log(totalFail + " Failed, " + totalPass + " Passed, of " + total);
  39. testStatus = 1;
  40. } else {
  41. console.log(totalFail + " Failed, " + totalPass + " Passed, of " + total);
  42. testStatus = 0;
  43. }
  44. //console.log(entries[i])
  45. //console.log(totalPass + "|" + totalFail);
  46. };
  47. function entryFilter(md) {
  48. var linepatt = /^\s{0,4}\*\s\[.*\`/;
  49. return linepatt.test(md);
  50. }
  51. function split(text){
  52. //cutOne = text.split("<!-- BEGIN SOFTWARE LIST -->");
  53. //cutTwo = cutOne[1].split("<!-- END SOFTWARE LIST -->");
  54. //cutThree = cutTwo[0].replace(/^\#.*$|^\_.*$|^See.*$|^Some.*$|^\*.*\*$|^\s\*.*\*$|^CMS.*$|^\*\*\[.*$/mg, "");
  55. return text.split(/\r?\n/);
  56. }
  57. function parseMD(md) {
  58. return split(md).filter(entryFilter);
  59. //console.log(entries);
  60. //console.log (entries.length);
  61. //console.log(entries[0]);
  62. //console.log(entries[entries.length - 1]);
  63. }
  64. function findPattern(text, i) {
  65. var nodnospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no demo and no source code
  66. 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
  67. var nodpatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no demo
  68. var nospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with no source code
  69. 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
  70. 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
  71. var pnodpatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\`(\⚠)\`\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with proprietary with no demo
  72. var pnospatt = /\s{0,3}\*\s\[(.*?)\]\((.*?)\)\s\`(\⚠)\`\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s\`(.*?)\`\s\`(.*?)\`/; //Regex for entries with proprietary with no source code
  73. if (nodnospatt.test(text) == true) {
  74. return true;
  75. } else if (slpatt.test(text) == true) {
  76. return true;
  77. } else if (nodpatt.test(text) == true) {
  78. return true;
  79. } else if (nospatt.test(text) == true) {
  80. return true;
  81. } else if (pnodnospatt.test(text) == true) {
  82. return true;
  83. } else if (pslpatt.test(text) == true) {
  84. return true;
  85. } else if (pnodpatt.test(text) == true) {
  86. return true;
  87. } else if (pnospatt.test(text) == true) {
  88. return true;
  89. } else {
  90. //document.getElementById("alert").innerHTML = "Error(s) Found, check your syntax!";
  91. return false;
  92. }
  93. };