-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
82 lines (71 loc) · 2.1 KB
/
index.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
78
79
80
81
const fs = require('fs');
const readline = require('readline');
const Sequelize = require('sequelize');
const docPattern = /^\s*<li data-ice="doc">\S*(?:<div data-ice="dirPath" class="nav-dir-path">\S*<\/div>)?<span data-ice="kind" class="kind-(class|interface|typedef)">[CIT]<\/span>\S*<span data-ice="name"><span><a href="(\S+)">(\S+)<\/a><\/span><\/span><\/li>\s*$/i;
const obsPath = 'rxjs/class/es6/Observable.js~Observable.html';
const obsPattern = /^\s*<h3 data-ice="anchor" id="((?:static|instance)-method-(\S*))"[\s\S]*$/i;
const typeMap = {
class: 'Class',
interface: 'Interface',
typedef: 'Type',
method: 'Method'
};
let objects = [];
let rl = readline.createInterface({
input: fs.createReadStream('rxjs/index.html', 'utf8'),
terminal: false
});
rl.on('line', line => {
let matches = docPattern.exec(line);
if (matches && matches.length === 4) {
objects.push({
type: typeMap[matches[1]],
path: `rxjs/${matches[2]}`,
name: matches[3]
});
}
});
// TODO: clean up
let rlObs = readline.createInterface({
input: fs.createReadStream(obsPath),
terminal: false
})
rlObs.on('line', line => {
let matches = obsPattern.exec(line);
if (matches && matches.length === 3) {
objects.push({
type: typeMap.method,
path: `${obsPath}#${matches[1]}`,
name: matches[2]
});
}
});
let seq = new Sequelize('database', 'username', 'password', {
dialect: 'sqlite',
storage: 'Contents/Resources/docSet.dsidx'
});
let SearchIndex = seq.define('searchIndex', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
},
name: {
type: Sequelize.STRING
},
type: {
type: Sequelize.STRING
},
path: {
type: Sequelize.STRING
}
}, {
freezeTableName: true,
timestamps: false
});
function finish(emitter) {
return new Promise((res) => emitter.on('close', res))
}
Promise.all([rl, rlObs].map(finish))
.then(() => SearchIndex.sync())
.then(() => objects.map(item => SearchIndex.build(item).save()));