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