-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildscript.js
More file actions
57 lines (49 loc) · 1.26 KB
/
buildscript.js
File metadata and controls
57 lines (49 loc) · 1.26 KB
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
const fs = require('fs-extra')
Promise.resolve()
.then(clean)
.then(copy)
.then(createGamesList)
.then(() => console.log('\nRunning webpack...'))
.catch((err) => console.error(err) && process.exit(1))
/**
* Replacement for rimraf
*/
function clean () {
return fs.remove('./docs')
.then(() => console.log('- Cleaned up ./docs'))
.catch((err) => { throw new Error(err) })
}
/**
* Copy public files
*/
function copy () {
const copyOpts = {
filter: (file) => !file.match(/\.(md|todo)$/)
}
return fs.copy('./public/data', './docs/data', copyOpts)
.then(() => console.log('- Copied data files'))
.catch((err) => { throw new Error(err) })
}
/**
* Create games list json file
*/
function createGamesList () {
return new Promise((resolve, reject) => {
const dir = './docs/data/games'
const games = []
fs.readdir(dir, function (readErr, files) {
if (readErr) throw new Error(readErr)
files.forEach((file) => {
const gameData = fs.readJsonSync(`${dir}/${file}`)
games.push(gameData.game)
})
try {
fs.writeJsonSync(`${dir}/gameslist.json`, games)
console.log('- Created games json file')
resolve()
} catch (writeErr) {
reject(writeErr)
}
})
})
}