This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
191 lines (138 loc) Β· 6.45 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const fs = require('fs');
const path = require('path');
const Handlebars = require('handlebars');
require('./helpers');
const admzip = require('adm-zip');
const temp = require('temp').track();
const sqlite3 = require('sqlite3').verbose();
/**
* Dash export plugin for doxdox.
*
* @example parseInputs(inputs, {'parser': 'dox', 'layout': 'dash'}).then(content => console.log(content));
* @param {Array} data Methods parsed using a doxdox parser.
* @return {Promise} Promise with generated content.
* @public
*/
const plugin = data =>
new Promise((resolve, reject) => {
const zip = new admzip();
const tempdb = temp.openSync('temp.sqlite');
const db = new sqlite3.Database(tempdb.path);
fs.readFile(
path.join(__dirname, 'templates/method.hbs'),
'utf8',
(err, contents) => {
if (err) {
return reject(err);
}
const methodTemplate = Handlebars.compile(contents);
fs.readFile(
path.join(__dirname, 'templates/Info.plist.hbs'),
'utf8',
(err, contents) => {
if (err) {
return reject(err);
}
const plistTemplate = Handlebars.compile(contents);
zip.addFile(
`${data.title}.docset/Contents/Info.plist`,
plistTemplate(data)
);
zip.addLocalFile(
path.join(
__dirname,
'templates/resources/bootstrap.min.css'
),
`${
data.title
}.docset/Contents/Resources/Documents/resources/`
);
zip.addLocalFile(
path.join(
__dirname,
'templates/resources/documentation.css'
),
`${
data.title
}.docset/Contents/Resources/Documents/resources/`
);
zip.addLocalFile(
path.join(
__dirname,
'templates/resources/github.min.css'
),
`${
data.title
}.docset/Contents/Resources/Documents/resources/`
);
db.serialize(() => {
db.run('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);');
db.run('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);');
data.files.forEach(file => {
file.methods.forEach(method => {
zip.addFile(
`${
data.title
}.docset/Contents/Resources/Documents/${
method.uid
}.html`,
methodTemplate(method)
);
db.run(
'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);',
{
'$name': method.name,
'$path': `${method.uid}.html`,
'$type': method.type.replace(
/^[a-z]/u,
match => match.toUpperCase()
)
}
);
if (method.tags.property) {
method.tags.property.forEach(property => {
db.run(
'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);',
{
'$name': `${
method.name
}.${property.name}`,
'$path': `${
method.uid
}.html#//apple_ref/cpp/Property/${
property.name
}`,
'$type': 'Property'
}
);
});
}
});
});
});
db.close(err => {
if (err) {
return reject(err);
}
fs.readFile(tempdb.path, (err, contents) => {
if (err) {
return reject(err);
}
zip.addFile(
`${
data.title
}.docset/Contents/Resources/docSet.dsidx`,
contents
);
return resolve(zip.toBuffer());
});
return false;
});
return false;
}
);
return false;
}
);
});
module.exports = plugin;