|
1 | | -var path = require('path'); |
2 | | -var getFile = require('./get-file'); |
3 | | -var compare = require('./compare-solution'); |
| 1 | +var path = require('path') |
| 2 | +var getFile = require('./get-file') |
| 3 | +var compare = require('./compare-solution') |
4 | 4 |
|
5 | | -module.exports = function createProblem(dirname) { |
6 | | - var exports = {}; |
| 5 | +module.exports = function createProblem (dirname) { |
| 6 | + var exports = {} |
7 | 7 |
|
8 | | - var problemName = dirname.split(path.sep); |
9 | | - var i18n; |
| 8 | + var problemName = dirname.split(path.sep) |
| 9 | + var i18n |
10 | 10 |
|
11 | | - problemName = problemName[problemName.length-1]; |
| 11 | + problemName = problemName[problemName.length - 1] |
12 | 12 |
|
13 | 13 | exports.init = function (workshopper) { |
14 | | - i18n = workshopper.i18n; |
15 | | - var postfix = workshopper.i18n.lang() === 'en' ? '' : '_' + workshopper.i18n.lang(); |
16 | | - this.problem = {file: path.join(dirname, 'problem' + postfix + '.md')}; |
17 | | - this.solution = {file: path.join(dirname, 'solution' + postfix + '.md')}; |
18 | | - this.solutionPath = path.resolve(__dirname, '..', 'solutions', problemName, "index.js"); |
19 | | - this.troubleshootingPath = path.join(__dirname, '..', 'i18n', 'troubleshooting' + postfix + '.md'); |
| 14 | + i18n = workshopper.i18n |
| 15 | + var postfix = workshopper.i18n.lang() === 'en' ? '' : '_' + workshopper.i18n.lang() |
| 16 | + this.problem = { file: path.join(dirname, 'problem' + postfix + '.md') } |
| 17 | + this.solution = { file: path.join(dirname, 'solution' + postfix + '.md') } |
| 18 | + this.solutionPath = path.resolve(__dirname, '..', 'solutions', problemName, 'index.js') |
| 19 | + this.troubleshootingPath = path.join(__dirname, '..', 'i18n', 'troubleshooting' + postfix + '.md') |
20 | 20 | } |
21 | 21 |
|
22 | 22 | exports.verify = function (args, cb) { |
23 | | - |
24 | | - var attemptPath = path.resolve(process.cwd(), args[0]); |
25 | | - compare(this.solutionPath, attemptPath, i18n, function(match, obj) { |
26 | | - |
27 | | - if(match) { |
28 | | - return cb(true); |
| 23 | + var attemptPath = path.resolve(process.cwd(), args[0]) |
| 24 | + compare(this.solutionPath, attemptPath, i18n, function (match, obj) { |
| 25 | + if (match) { |
| 26 | + return cb(true) |
29 | 27 | } |
30 | 28 |
|
31 | | - if(!obj) { |
| 29 | + if (!obj) { |
32 | 30 | // An error occured, we've already printed an error |
33 | | - return; |
| 31 | + return |
34 | 32 | } |
35 | 33 |
|
36 | | - var message = getFile(this.troubleshootingPath); |
| 34 | + var message = getFile(this.troubleshootingPath) |
37 | 35 |
|
38 | | - message = message.replace(/%solution%/g, obj.solution); |
39 | | - message = message.replace(/%attempt%/g, obj.attempt); |
40 | | - message = message.replace(/%diff%/g, obj.diff); |
41 | | - message = message.replace(/%filename%/g, args[0]); |
| 36 | + message = message.replace(/%solution%/g, obj.solution) |
| 37 | + message = message.replace(/%attempt%/g, obj.attempt) |
| 38 | + message = message.replace(/%diff%/g, obj.diff) |
| 39 | + message = message.replace(/%filename%/g, args[0]) |
42 | 40 |
|
43 | 41 | exports.fail = [ |
44 | | - {text: message, type: 'md' }, |
| 42 | + { text: message, type: 'md' }, |
45 | 43 | require('./footer.js') |
46 | 44 | ] |
47 | 45 |
|
48 | | - cb(false); |
49 | | - |
50 | | - }.bind(this)); |
51 | | - }; |
| 46 | + cb(false) |
| 47 | + }.bind(this)) |
| 48 | + } |
52 | 49 |
|
53 | | - return exports; |
| 50 | + return exports |
54 | 51 | } |
0 commit comments