dangerfile.js 7.1 KB

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