-
Notifications
You must be signed in to change notification settings - Fork 61
/
capture.js
77 lines (66 loc) · 1.75 KB
/
capture.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var webshot = require('webshot');
var program = require('commander');
var gameFilePath = './games/games.js';
// HACK
// import file
// http://stackoverflow.com/questions/4662851/how-do-you-import-non-node-js-files
eval(require('fs').readFileSync(gameFilePath, 'utf8'));
program
.version('0.0.1')
.option('-i, --index [index]', 'start index')
.parse(process.argv);
var startIndex = program.index || 0;
var screenshotFolderPath = './screenshots';
var devPath = 'http://localhost:3000/games';
var nGames = games.length;
/* ================================================================ Screenshot
*/
var webshotOption = {
renderDelay: 2000
};
/**
* [fireWebshotByIndex description]
*
* @example fireWebshotByIndex(0);
* @example fireWebshotByIndex(3);
* @example fireWebshotByIndex(nGames - 1);
*
* @param {number} idx
* @param {function} cb
*/
function fireWebshotByIndex(idx, cb) {
console.log(games[idx])
var gameName = games[idx].name;
if (gameName) {
var gameUrl = `${devPath}/${gameName}`
var screenshotFilePath = `${screenshotFolderPath}/${gameName}.jpg`;
webshot(gameUrl, screenshotFilePath, webshotOption, function(err) {
if (err) {
console.log('ERROR: webshot is error', err);
} else {
console.log(`idx: ${idx}, screenshot has been saved to ${screenshotFilePath}`);
}
cb()
});
} else {
console.log(`ERROR: gameName is undefined (i: ${i})`);
}
}
/**
* [fireWebshot description]
* quite duplicate with `fireWebshotByIndex`
*
* @example fireWebshot(0);
*
* @param {number} i
*/
function fireWebshot(i) {
if (i < nGames) {
fireWebshotByIndex(i, function() {
fireWebshot(++i);
});
} else {
console.log('================ DONE');
}
}
fireWebshot(startIndex);