-
Notifications
You must be signed in to change notification settings - Fork 35
/
filecheck.js
38 lines (27 loc) · 925 Bytes
/
filecheck.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
const fs = require('fs')
const path = require('path')
function setup (_mode, callback) {
const fileError = function (i18nKey) {
return callback(new Error(this.__(i18nKey, { submission: submissionPath })))
}.bind(this)
const noFileError = function () {
return fileError('error.submission_no_file')
}
const notRegularError = function () {
return fileError('error.submission_not_regular')
}
const submission = this.args[0]
const submissionPath = submission ? path.resolve(submission.toString()) : ''
if (!submission) return noFileError()
fs.stat(submission.toString(), function (err, stat) {
if ((err && err.code === 'ENOENT') || !stat) { return noFileError() }
if (err) { return callback(err) }
if (!stat.isFile()) { return notRegularError() }
callback()
})
}
function filecheck (exercise) {
exercise.addSetup(setup)
return exercise
}
module.exports = filecheck