forked from Antriel/phaser3-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
total-sqlite.js
48 lines (32 loc) · 1.23 KB
/
total-sqlite.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
var fs = require('fs');
var dirTree = require('directory-tree');
var stringOccurrence = require('string-occurrence');
var SQLite3 = require('better-sqlite3');
var rootDir = '../phaser/src/';
var db = new SQLite3('./description.sqlite');
var queries = [];
var filteredTree = dirTree(rootDir, { extensions: /\.js$/ }, (item, PATH) => {
var file = fs.readFileSync(item.path, 'utf8');
var descTotal = stringOccurrence(file, '[description]');
if (descTotal > 0)
{
// item.path = item.path.replace('\\', '/');
// item.path = item.path.replace('../phaser\\', '');
item.path = item.path.replace('..\\phaser\\', '');
console.log(item.path, item.name);
// Parse the file line by line
var lines = file.split('\n');
for (var i = 0; i < lines.length; i++)
{
if (stringOccurrence(lines[i], '[description]'))
{
queries.push('INSERT INTO descriptions (id, file, line) VALUES (NULL, "' + item.path + '", ' + (i + 1) + ')');
// console.log('Line ' + i + 1);
}
}
}
});
console.log('Running transaction (' + queries.length + ' queries)');
db.transaction(queries).run();
console.log('Complete');
db.close();