Skip to content

Commit bdb98a8

Browse files
authored
Merge pull request #323 from workshopper/update-libraries
Update libraries
2 parents 13d8d14 + 63e7e11 commit bdb98a8

9 files changed

Lines changed: 5836 additions & 5789 deletions

File tree

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const languages = ['en'].concat(fs.readdirSync(i18nDir)
77
.filter((f) => f.match(/\w+\.json/))
88
.map((f) => f.replace('.json', ''))
99
)
10-
var jsing = require('workshopper-adventure')({
10+
const jsing = require('workshopper-adventure')({
1111
appDir: __dirname,
1212
languages,
1313
header: require('workshopper-adventure/default/header'),
@@ -18,8 +18,8 @@ jsing.addAll(require('./menu.json').map(function (name) {
1818
return {
1919
name,
2020
fn: function () {
21-
var p = name.toLowerCase().replace(/\s/g, '-')
22-
var dir = require('path').join(__dirname, 'problems', p)
21+
const p = name.toLowerCase().replace(/\s/g, '-')
22+
const dir = require('path').join(__dirname, 'problems', p)
2323
return problem(dir)
2424
}
2525
}

lib/compare-solution.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
/* eslint-disable standard/no-callback-literal */
2-
31
require('colors')
42

5-
var path = require('path')
6-
var diff = require('diff')
7-
var run = require(path.join(__dirname, 'run-solution'))
3+
const path = require('path')
4+
const diff = require('diff')
5+
const run = require(path.join(__dirname, 'run-solution'))
86

97
module.exports = function (solution, attempt, i18n, cb) {
108
run(solution, i18n, function (err, solutionResult) {
119
if (err) {
1210
console.error(err)
13-
return cb(false)
11+
return cb(err, false)
1412
}
1513

1614
run(attempt, i18n, function (err, attemptResult) {
1715
if (err && err.code !== 8) {
1816
console.error(err)
19-
return cb(false)
17+
return cb(err, false)
2018
}
2119

2220
if (solutionResult === attemptResult) {
23-
return cb(true)
21+
return cb(err, true)
2422
}
2523

26-
cb(false, {
24+
cb(null, false, {
2725
solution: solutionResult,
2826
attempt: err || attemptResult,
2927
diff: generateDiff(solutionResult, attemptResult)
@@ -33,9 +31,9 @@ module.exports = function (solution, attempt, i18n, cb) {
3331
}
3432

3533
function generateDiff (solution, attempt) {
36-
var parts = diff.diffChars(solution, attempt)
34+
const parts = diff.diffChars(solution, attempt)
3735

38-
var result = ''
36+
let result = ''
3937

4038
parts.forEach(function (part) {
4139
if (part.added) {

lib/footer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var path = require('path')
1+
const path = require('path')
22
module.exports = [
33
{ text: '---', type: 'md' },
44
{ file: path.join(__dirname, '..', 'i18n', 'footer', '{lang}.md') },

lib/get-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var fs = require('fs')
1+
const fs = require('fs')
22

33
module.exports = function (filepath) {
44
return fs.readFileSync(filepath, 'utf8')

lib/problem.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
1-
/* eslint-disable standard/no-callback-literal */
2-
3-
var path = require('path')
4-
var getFile = require('./get-file')
5-
var compare = require('./compare-solution')
1+
const path = require('path')
2+
const getFile = require('./get-file')
3+
const compare = require('./compare-solution')
64

75
module.exports = function createProblem (dirname) {
8-
var exports = {}
6+
const exports = {}
97

10-
var problemName = dirname.split(path.sep)
11-
var i18n
8+
let problemName = dirname.split(path.sep)
9+
let i18n
1210

1311
problemName = problemName[problemName.length - 1]
1412

1513
exports.init = function (workshopper) {
1614
i18n = workshopper.i18n
17-
var postfix = workshopper.i18n.lang() === 'en' ? '' : '_' + workshopper.i18n.lang()
15+
const postfix = workshopper.i18n.lang() === 'en' ? '' : '_' + workshopper.i18n.lang()
1816
this.problem = { file: path.join(dirname, 'problem' + postfix + '.md') }
1917
this.solution = { file: path.join(dirname, 'solution' + postfix + '.md') }
2018
this.solutionPath = path.resolve(__dirname, '..', 'solutions', problemName, 'index.js')
2119
this.troubleshootingPath = path.join(__dirname, '..', 'i18n', 'troubleshooting' + postfix + '.md')
2220
}
2321

2422
exports.verify = function (args, cb) {
25-
var attemptPath = path.resolve(process.cwd(), args[0])
26-
compare(this.solutionPath, attemptPath, i18n, function (match, obj) {
23+
const attemptPath = path.resolve(process.cwd(), args[0])
24+
compare(this.solutionPath, attemptPath, i18n, function (_, match, obj) {
2725
if (match) {
28-
return cb(true)
26+
return cb(null, true)
2927
}
3028

3129
if (!obj) {
3230
// An error occured, we've already printed an error
3331
return
3432
}
3533

36-
var message = getFile(this.troubleshootingPath)
34+
let message = getFile(this.troubleshootingPath)
3735

3836
message = message.replace(/%solution%/g, obj.solution)
3937
message = message.replace(/%attempt%/g, obj.attempt)
@@ -45,7 +43,7 @@ module.exports = function createProblem (dirname) {
4543
require('./footer.js')
4644
]
4745

48-
cb(false)
46+
cb(null, false)
4947
}.bind(this))
5048
}
5149

lib/run-solution.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var fs = require('fs')
2-
var exec = require('child_process').exec
1+
const fs = require('fs')
2+
const exec = require('child_process').exec
33

44
/**
55
* @param {!string} filePath

0 commit comments

Comments
 (0)