-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
49 lines (44 loc) · 1.18 KB
/
bootstrap.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
/**
* Common rountines
*
* @package reverse-engineering-html-to-database
* @copyright Copyright (C) 2016 Alligo LTDA.
* @author Emerson Rocha Luiz <emerson at alligo.com.br>
*/
var startTime = null;
/**
* Like require, but try different files, in order
*
* @param {Array} filepaths
* @returns \require|false
*/
function requireOneOf(filepaths) {
var fs = require('fs'), i, n = filepaths.length;
function exists(filePath) {
try {
return fs.statSync(filePath).isFile();
} catch (err) {
return false;
}
}
for (i = 0; i < n; i++) {
if (exists(filepaths[i])) {
return require(filepaths[i]);
}
}
console.log((new Date()).toJSON() + '> ERROR requireOneOf: No file to load', filepaths);
return false;
}
function start() {
startTime = new Date();
}
function totalTime(jobsNumber, info) {
var end = new Date();
var time = ((end.getTime() - startTime.getTime()) / 1000 / 60); // min
console.log((new Date()).toJSON() + '> INFO : totalTime ' + info + ' '+ time.toFixed(2) + 'min. ' + (jobsNumber / time).toFixed(2) + ' jobs/min');
}
module.exports = {
requireOneOf: requireOneOf,
start: start,
totalTime: totalTime
};