dangerfile.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. const {danger, markdown, message, warn} = require('danger')
  2. const http = require('http')
  3. const url = require('url')
  4. const yaml = require('js-yaml')
  5. const fs = require('fs')
  6. markdown("Hey there! Thanks for contributing a PR to osgameclones! 🎉")
  7. let namesAdded = []
  8. let namesChanged = []
  9. let namesRemoved = []
  10. const isGame = game => /^games\/\w+\.yaml$/.test(game)
  11. let unknownLanguageDetected = false
  12. const knownLanguages = Object.keys(require('linguist-languages')).concat(['Delphi', 'TorqueScript'])
  13. let unknownFrameworkDetected = false
  14. const knownFrameworks = [
  15. '.NET',
  16. 'Adobe AIR',
  17. 'Adventure Game Studio',
  18. 'Allegro',
  19. 'Avalonia',
  20. 'BackBone.js',
  21. 'bgfx',
  22. 'Box2D',
  23. 'Bullet3',
  24. 'Carbon',
  25. 'Castle Game Engine',
  26. 'CreateJS',
  27. 'Cocos2d',
  28. 'Construct',
  29. 'Construct2',
  30. 'Crystal Space',
  31. 'Cube 2 Engine',
  32. 'Daemon Engine',
  33. 'DirectX',
  34. 'DIV Games Studio',
  35. 'Duality',
  36. 'Ebitengine',
  37. 'EntityX',
  38. 'EnTT',
  39. 'Flash',
  40. 'Fyne',
  41. 'FMOD',
  42. 'FNA',
  43. 'GameMaker Studio',
  44. 'GameSprockets',
  45. 'gLib2D',
  46. 'Godot',
  47. 'Graphics32',
  48. 'GTK',
  49. 'HaxeFlixel',
  50. 'Impact',
  51. 'Inform',
  52. 'Irrlicht',
  53. 'JavaFX',
  54. 'JMonkeyEngine',
  55. 'jQuery',
  56. 'Kylix',
  57. 'Laravel',
  58. 'Lazarus',
  59. 'libGDX',
  60. 'libretro',
  61. 'LÖVE',
  62. 'LowRes NX',
  63. 'LWJGL',
  64. 'macroquad',
  65. 'melonJS',
  66. 'Minetest Engine',
  67. 'Mono',
  68. 'MonoGame',
  69. 'ncurses',
  70. 'NeoAxis Engine',
  71. 'Netty.io',
  72. 'nya-engine',
  73. 'OGRE',
  74. 'Open Dynamics Engine',
  75. 'OpenAL',
  76. 'OpenFL',
  77. 'OpenGL',
  78. 'OpenRA',
  79. 'OpenSceneGraph',
  80. 'OpenTK',
  81. 'OpenXR',
  82. 'osu!framework',
  83. 'Oxygine',
  84. 'Panda3D',
  85. 'PandaJS',
  86. 'Phaser',
  87. 'PICO-8',
  88. 'Piston',
  89. 'PixiJS',
  90. 'pygame',
  91. 'QB64',
  92. 'Qt',
  93. 'raylib',
  94. 'React',
  95. 'Redux',
  96. 'rot.js',
  97. 'Rx.js',
  98. 'SDL',
  99. 'SDL2',
  100. 'SDL.NET',
  101. 'Sea3D',
  102. 'SFML',
  103. 'Slick2D',
  104. 'Solarus',
  105. 'Source SDK',
  106. 'Spring RTS Engine',
  107. 'Starling',
  108. 'Swing',
  109. 'SWT',
  110. 'three.js',
  111. 'TGUI',
  112. 'TIC-80',
  113. 'Torque 3D',
  114. 'Tween.js',
  115. 'Unity',
  116. 'VDrift Engine',
  117. 'Vue.js',
  118. 'Vulkan',
  119. 'WebGL',
  120. 'wxWidgets',
  121. 'XNA'
  122. ]
  123. const frameworkLangs = {
  124. 'SDL2': ['C++', 'C'],
  125. 'SDL': ['C++', 'C'],
  126. 'SDL.NET': ['C#'],
  127. 'OpenGL': ['C++', 'C'],
  128. 'Unity': ['C#'],
  129. 'SFML': ['C++'],
  130. 'libGDX': ['Java', 'Kotlin'],
  131. 'Qt': ['C++'],
  132. 'Allegro': ['C++', 'C'],
  133. 'pygame': ['Python'],
  134. 'OGRE': ['C++'],
  135. 'Fyne': ['Go'],
  136. }
  137. // -----------
  138. // Game checks
  139. // -----------
  140. const checkRepoGoogleCode = game => {
  141. if (game.repo && (game.repo.indexOf('googlecode') >= 0 || game.repo.indexOf('code.google') >= 0)) {
  142. warn(`⚰️ ${game.name}'s repo is Google Code, a dead service. Please check if there is an updated repo elsewhere.`)
  143. }
  144. }
  145. const checkRepoGit = game => {
  146. if (game.repo && game.repo.startsWith("git://")) {
  147. warn(`🔗 ${game.name}'s repo is a git repo, which cannot be opened in browsers by default. Please change it to the project's developer web page.`)
  148. }
  149. }
  150. const checkRepoSVN = game => {
  151. if (game.repo && game.repo.startsWith("svn://")) {
  152. warn(`🔗 ${game.name}'s repo is an SVN repo, which cannot be opened in browsers by default. Please change it to the project's developer web page.`)
  153. }
  154. }
  155. const checkRepoFTP = game => {
  156. if (game.repo && game.repo.startsWith("ftp://")) {
  157. warn(`🔗 ${game.name}'s repo is on a FTP server, which cannot be opened in some browsers by default. Please change it to the project's developer web page.`)
  158. }
  159. }
  160. const checkRepoAdded = game => {
  161. if (!game.repo) return
  162. const match = game.repo.match(/github.com\/([^/]+)\//)
  163. if (!match) return
  164. const author = match[1]
  165. message(`💌 Hey @${author}, we're adding your game to osgameclones!`)
  166. }
  167. const checkLanguageKnown = game => {
  168. if (!game.langs) return
  169. const unknownLanguages = game.langs.filter(l => !knownLanguages.includes(l))
  170. if (unknownLanguages.length) {
  171. warn(
  172. `🔢 ${game.name} contains "${unknownLanguages}" as language, which is not known by us. ` +
  173. `Please check for spelling errors.`
  174. )
  175. unknownLanguageDetected = true
  176. }
  177. }
  178. const checkFrameworkKnown = game => {
  179. if (!game.frameworks) return
  180. const unknownFrameworks = game.frameworks.filter(l => !knownFrameworks.includes(l))
  181. if (unknownFrameworks.length) {
  182. warn(
  183. `🌇 ${game.name} contains "${unknownFrameworks}" as frameworks, which is not known by us. ` +
  184. `Please check for spelling errors.`
  185. )
  186. unknownFrameworkDetected = true
  187. }
  188. }
  189. const checkFrameworkUsesLang = game => {
  190. if (!game.frameworks) return
  191. const commonFrameworks = game.frameworks.filter(frameworks => Object.keys(frameworkLangs).includes(frameworks))
  192. commonFrameworks.forEach(framework => {
  193. const langs = frameworkLangs[framework]
  194. if (!game.langs || game.langs.filter(lang => langs.includes(lang)).length === 0) {
  195. message(
  196. `🏗 ${game.name} uses "${framework}" as a framework, but doesn't have ${langs} in its languages.`
  197. )
  198. }
  199. })
  200. }
  201. const checkHasImagesOrVideos = game => {
  202. if (!game.images && !game.video) {
  203. warn(`🖼 ${game.name} has no images or videos. Please help improve the entry by finding one!`)
  204. }
  205. }
  206. const checkHasAdded = game => {
  207. if (!game.added) {
  208. warn(`📅 ${game.name} has no added date`)
  209. }
  210. }
  211. const commonChecks = game => {
  212. checkRepoGoogleCode(game)
  213. checkRepoGit(game)
  214. checkRepoSVN(game)
  215. checkRepoFTP(game)
  216. checkLanguageKnown(game)
  217. checkFrameworkKnown(game)
  218. checkFrameworkUsesLang(game)
  219. checkHasImagesOrVideos(game)
  220. checkHasAdded(game)
  221. }
  222. // -----------
  223. const onGameAdded = game => {
  224. namesAdded.push(game.name)
  225. checkRepoAdded(game)
  226. commonChecks(game)
  227. }
  228. const onGameChanged = game => {
  229. namesChanged.push(game.name)
  230. commonChecks(game)
  231. }
  232. const onGameRemoved = game => {
  233. namesRemoved.push(game.name)
  234. }
  235. const getGameChanges = files => {
  236. Promise.all(files.filter(isGame).map(file => danger.git.diffForFile(file)))
  237. .then(diffs => {
  238. diffs.forEach(diff => {
  239. const gamesBefore = yaml.load(diff.before)
  240. // Compare any changes in games metadata
  241. const stringsBefore = gamesBefore.map(game => JSON.stringify(game))
  242. const gamesAfter = yaml.load(diff.after)
  243. const namesBefore = gamesBefore.map(game => game.name)
  244. const namesAfter = gamesAfter.map(game => game.name)
  245. gamesBefore.forEach(game => {
  246. if (!namesAfter.includes(game.name)) {
  247. onGameRemoved(game)
  248. }
  249. })
  250. gamesAfter.forEach(game => {
  251. if (!namesBefore.includes(game.name)) {
  252. onGameAdded(game)
  253. } else if (namesBefore.includes(game.name) && !stringsBefore.includes(JSON.stringify(game))) {
  254. onGameChanged(game)
  255. }
  256. })
  257. })
  258. if (unknownLanguageDetected) message(`Known languages are ${knownLanguages.join(", ")}.`)
  259. if (unknownFrameworkDetected) message(`Known frameworks are ${knownFrameworks.join(", ")}.`)
  260. if (namesAdded.length > 0) {
  261. message(`Game(s) added: ${danger.utils.sentence(namesAdded)} 🎊`)
  262. }
  263. if (namesChanged.length > 0) {
  264. message(`Game(s) updated: ${danger.utils.sentence(namesChanged)} 👏`)
  265. }
  266. if (namesRemoved.length > 0) {
  267. message(`Game(s) removed: ${danger.utils.sentence(namesRemoved)} 😿`)
  268. }
  269. })
  270. }
  271. getGameChanges([].concat(danger.git.modified_files || [], danger.git.created_files || [], danger.git.deleted_files || []))