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.

132 lines
5.5 KiB

8 years ago
  1. const fs = require('fs')
  2. var log = '{\n'
  3. var issuelog = ' "message": "#### Syntax Issues\\n\\n Name | Entry\\n----|----------------------\\n'
  4. var file = fs.readFileSync(process.argv[2], 'utf8')
  5. entryErrorCheck(file)
  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. if (entryFilter(entries[i]) === true) {
  17. total += 1
  18. entryArray[i].name = namepatt.exec(entries[i])[1]
  19. entryArray[i].pass = findPattern(entries[i])
  20. if (entryArray[i].pass === true) {
  21. totalPass += 1
  22. } else {
  23. console.log(entryArray[i].name + 'Failed.')
  24. // entryArray[i].error = findError(entries[i]) //WIP
  25. totalFail += 1
  26. issuelog += entryArray[i].name + ' | ' + entries[i] + '\\n'
  27. }
  28. }
  29. }
  30. if (totalFail > 0) {
  31. console.log(totalFail + ' Failed, ' + totalPass + ' Passed, of ' + total)
  32. log += ' "error": true,\n "title": "Found ' + totalFail + ' entries with syntax error(s).",\n'
  33. fs.writeFileSync('syntaxcheck.json', log + issuelog + '"\n}')
  34. process.exit(1)
  35. } else {
  36. console.log(totalFail + ' Failed, ' + totalPass + ' Passed, of ' + total + '\n')
  37. log += ' "error": false\n}'
  38. fs.writeFileSync('syntaxcheck.json', log)
  39. process.exit(0)
  40. }
  41. };
  42. function entryFilter (md) {
  43. var linepatt = /^\s{0,4}\*\s\[.*`/
  44. return linepatt.test(md)
  45. }
  46. function split (text) {
  47. return text.split(/\r?\n/)
  48. }
  49. // function parseMD(md) {
  50. // return split(md).filter(entryFilter);
  51. // }
  52. function findPattern (text) {
  53. var nodnospatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)`(.*?)`\s`(.*?)`/ // Regex for entries with no demo and no source code
  54. var slpatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Demo\b\]\((.*?)\),\s\[Source Code\b\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with demo and source code
  55. var nodpatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with no demo
  56. var nospatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with no source code
  57. var pnodnospatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s`(⚠)`\s\-\s(.{0,249}?\.\s)`(.*?)`\s`(.*?)`/ // Regex for entries with proprietary with no demo and no source code
  58. var pslpatt = /\s{0,4}\*\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
  59. var pnodpatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s`(⚠)`\s\-\s(.{0,249}?\.\s)\(\[Source Code\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with proprietary with no demo
  60. var pnospatt = /\s{0,4}\*\s\[(.*?)\]\((.*?)\)\s`(⚠)`\s\-\s(.{0,249}?\.\s)\(\[Demo\]\((.*?)\)\)\s`(.*?)`\s`(.*?)`/ // Regex for entries with proprietary with no source code
  61. if (nodnospatt.test(text) === true) {
  62. return true
  63. } else if (slpatt.test(text) === true) {
  64. return true
  65. } else if (nodpatt.test(text) === true) {
  66. return true
  67. } else if (nospatt.test(text) === true) {
  68. return true
  69. } else if (pnodnospatt.test(text) === true) {
  70. return true
  71. } else if (pslpatt.test(text) === true) {
  72. return true
  73. } else if (pnodpatt.test(text) === true) {
  74. return true
  75. } else if (pnospatt.test(text) === true) {
  76. return true
  77. } else {
  78. return false
  79. }
  80. };
  81. // WIP
  82. function findError (entry) {
  83. var fixedEntry = entry
  84. if (/\s{0,4}\*\s\[.*?\]\(http.*?\)/.test(entry) === false) { // Fix * site name/URL
  85. console.log('marker2')
  86. entry.replace(/^(\s*)\**\s*\[*([^()\[\]]*?)\]*\s*\(*(https*:\/\/[^ )]{1,})(\)*\s*`*⚠`*\s*-*\s*|\)*\s*-*\s*)(.*)/gi, function (match, p1, p2, p3, p4, p5) {
  87. console.log('Error in [Name](URL)')
  88. if (/⚠/.test(entry) === true) {
  89. fixedEntry = p1 + '* [' + p2 + '](' + p3 + ') `⚠` - ' + p5
  90. } else {
  91. fixedEntry = p1 + '* [' + p2 + '](' + p3 + ') - ' + p5
  92. }
  93. console.log('Fixed: ' + fixedEntry)
  94. })
  95. }
  96. if (/\s-\s/.test(entry) === false) {
  97. console.log('marker3')
  98. entry.replace(/(\s{0,3}\*\s\[.*?\]\(.*?\))(\s*`*⚠`*\s*-*\s*|\s*`*⚠`*\s*-*|`*⚠`*\s*-*\s*|`*⚠`*-*|\s*|\s*-*\s*|\s*-*|-*\s*|-*|\s*)(.{0,249}?\.)(.*)/gi, function (match, p1, p2, p3, p4) { // Fix space - space between link and descrition
  99. console.log('Missing ` - ` between Site link and description.')
  100. if (/⚠/.test(entry) === true) {
  101. fixedEntry = p1 + ' `⚠` - ' + p3 + p4
  102. } else {
  103. fixedEntry = p1 + ' - ' + p3 + p4
  104. }
  105. console.log('Fixed: ' + fixedEntry)
  106. })
  107. }
  108. if (/^\s{0,4}\*\s\[.*?\]\(.*?\).*?(\s\.|\)\)\s)`.*?`\s`.*?`/.test(entry) === false) {
  109. console.log('marker4')
  110. entry.replace(/^(\s*\*\s.*?\)\)|.*?\s\-\s.*?\.)(\s*`*\s*)(.*?)(\s*`\s*`\s*|\s*`\s*`*\s*|\s*`*\s*`\s*|\s)(.*?)`/gi, function (match, p1, p2, p3, p4, p5) { // Fix License and Language
  111. console.log('Issue in Language or License')
  112. fixedEntry = p1 + ' `' + p3 + '` `' + p5 + '`'
  113. console.log('Fixed: ' + fixedEntry)
  114. })
  115. } else if (/demo/i.test(entry) === true) {
  116. } else if (/source/i.test(entry) === true) {
  117. }
  118. console.log(findPattern(fixedEntry))
  119. // if (findPattern(fixedEntry) === false) {
  120. // findError(fixedEntry) // If it's not fixed let's try again.
  121. // }
  122. }
  123. // else if (/source/i.test(entry) === true && /demo/i.test(entry) === true) {