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