forked from Antriel/phaser3-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.js
64 lines (47 loc) · 1.41 KB
/
dump.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
var fs = require('fs');
var dirTree = require('directory-tree');
var beautify = require('json-beautify');
var SQLite3 = require('better-sqlite3');
var rootDir = '../phaser/src/';
var outputJSON = './percy/files.json';
// Back-up the DB
fs.renameSync('./percy/files.db', './percy/files-backup.db');
// Create a new one
var db = new SQLite3('./percy/files.db');
db.exec(`
BEGIN TRANSACTION;
CREATE TABLE "files" (
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
'path' TEXT NOT NULL,
'done' INTEGER NOT NULL DEFAULT 0
);
COMMIT;
`);
var queries = [];
var filteredTree = dirTree(rootDir, { extensions: /\.js$/ }, (item, PATH) => {
item.path = item.path.replace('..\\phaser\\src\\', '');
if (
item.path.substr(-8) !== 'index.js' &&
item.path.substr(0, 21) !== 'physics\\matter-js\\lib' &&
item.path.substr(0, 9) !== 'polyfills'
)
{
queries.push('INSERT INTO files (path) VALUES ("' + item.path + '")');
}
});
filteredTree = beautify(filteredTree, null, 2, 100);
// Save the JSON
fs.writeFile(outputJSON, filteredTree, function (error) {
if (error)
{
throw error;
}
else
{
console.log('files.json saved');
console.log('Running transaction (' + queries.length + ' queries)');
db.transaction(queries).run();
console.log('Complete. Now run \'sync\'');
db.close();
}
});