Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 6586847

Browse files
committed
Formatted code.
Added max-lines-per-function eslint flag.
1 parent 30864d7 commit 6586847

File tree

2 files changed

+129
-83
lines changed

2 files changed

+129
-83
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
],
55
"rules": {
66
"id-length": 0,
7+
"max-lines-per-function": 0,
78
"new-cap": 0,
89
"no-invalid-this": 0,
910
"no-shadow": 0,

index.js

Lines changed: 128 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -18,129 +18,174 @@ const sqlite3 = require('sqlite3').verbose();
1818
* @public
1919
*/
2020

21-
const plugin = data => new Promise((resolve, reject) => {
21+
const plugin = data =>
22+
new Promise((resolve, reject) => {
2223

23-
const zip = new admzip();
24-
const tempdb = temp.openSync('temp.sqlite');
25-
const db = new sqlite3.Database(tempdb.path);
24+
const zip = new admzip();
25+
const tempdb = temp.openSync('temp.sqlite');
26+
const db = new sqlite3.Database(tempdb.path);
2627

27-
fs.readFile(path.join(__dirname, 'templates/method.hbs'), 'utf8', (err, contents) => {
28+
fs.readFile(
29+
path.join(__dirname, 'templates/method.hbs'),
30+
'utf8',
31+
(err, contents) => {
2832

29-
if (err) {
30-
31-
return reject(err);
32-
33-
}
34-
35-
const methodTemplate = Handlebars.compile(contents);
36-
37-
fs.readFile(path.join(__dirname, 'templates/Info.plist.hbs'), 'utf8', (err, contents) => {
38-
39-
if (err) {
40-
41-
return reject(err);
42-
43-
}
44-
45-
const plistTemplate = Handlebars.compile(contents);
33+
if (err) {
4634

47-
zip.addFile(
48-
`${data.title}.docset/Contents/Info.plist`,
49-
plistTemplate(data)
50-
);
35+
return reject(err);
5136

52-
zip.addLocalFile(
53-
path.join(__dirname, 'templates/resources/bootstrap.min.css'),
54-
`${data.title}.docset/Contents/Resources/Documents/resources/`
55-
);
37+
}
5638

57-
zip.addLocalFile(
58-
path.join(__dirname, 'templates/resources/documentation.css'),
59-
`${data.title}.docset/Contents/Resources/Documents/resources/`
60-
);
39+
const methodTemplate = Handlebars.compile(contents);
6140

62-
zip.addLocalFile(
63-
path.join(__dirname, 'templates/resources/github.min.css'),
64-
`${data.title}.docset/Contents/Resources/Documents/resources/`
65-
);
41+
fs.readFile(
42+
path.join(__dirname, 'templates/Info.plist.hbs'),
43+
'utf8',
44+
(err, contents) => {
6645

67-
db.serialize(() => {
46+
if (err) {
6847

69-
db.run('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);');
70-
db.run('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);');
48+
return reject(err);
7149

72-
data.files.forEach(file => {
50+
}
7351

74-
file.methods.forEach(method => {
52+
const plistTemplate = Handlebars.compile(contents);
7553

7654
zip.addFile(
77-
`${data.title}.docset/Contents/Resources/Documents/${method.uid}.html`,
78-
methodTemplate(method)
55+
`${data.title}.docset/Contents/Info.plist`,
56+
plistTemplate(data)
7957
);
8058

81-
db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', {
82-
'$name': method.name,
83-
'$path': `${method.uid}.html`,
84-
'$type': method.type.replace(/^[a-z]/, match => match.toUpperCase())
85-
});
59+
zip.addLocalFile(
60+
path.join(
61+
__dirname,
62+
'templates/resources/bootstrap.min.css'
63+
),
64+
`${
65+
data.title
66+
}.docset/Contents/Resources/Documents/resources/`
67+
);
8668

87-
if (method.tags.property) {
69+
zip.addLocalFile(
70+
path.join(
71+
__dirname,
72+
'templates/resources/documentation.css'
73+
),
74+
`${
75+
data.title
76+
}.docset/Contents/Resources/Documents/resources/`
77+
);
8878

89-
method.tags.property.forEach(property => {
79+
zip.addLocalFile(
80+
path.join(
81+
__dirname,
82+
'templates/resources/github.min.css'
83+
),
84+
`${
85+
data.title
86+
}.docset/Contents/Resources/Documents/resources/`
87+
);
88+
89+
db.serialize(() => {
90+
91+
db.run('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);');
92+
db.run('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);');
93+
94+
data.files.forEach(file => {
95+
96+
file.methods.forEach(method => {
97+
98+
zip.addFile(
99+
`${
100+
data.title
101+
}.docset/Contents/Resources/Documents/${
102+
method.uid
103+
}.html`,
104+
methodTemplate(method)
105+
);
106+
107+
db.run(
108+
'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);',
109+
{
110+
'$name': method.name,
111+
'$path': `${method.uid}.html`,
112+
'$type': method.type.replace(
113+
/^[a-z]/u,
114+
match => match.toUpperCase()
115+
)
116+
}
117+
);
118+
119+
if (method.tags.property) {
120+
121+
method.tags.property.forEach(property => {
122+
123+
db.run(
124+
'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);',
125+
{
126+
'$name': `${
127+
method.name
128+
}.${property.name}`,
129+
'$path': `${
130+
method.uid
131+
}.html#//apple_ref/cpp/Property/${
132+
property.name
133+
}`,
134+
'$type': 'Property'
135+
}
136+
);
137+
138+
});
139+
140+
}
90141

91-
db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', {
92-
'$name': `${method.name}.${property.name}`,
93-
'$path': `${method.uid}.html#//apple_ref/cpp/Property/${property.name}`,
94-
'$type': 'Property'
95142
});
96143

97144
});
98145

99-
}
100-
101-
});
102-
103-
});
146+
});
104147

105-
});
148+
db.close(err => {
106149

107-
db.close(err => {
150+
if (err) {
108151

109-
if (err) {
152+
return reject(err);
110153

111-
return reject(err);
154+
}
112155

113-
}
156+
fs.readFile(tempdb.path, (err, contents) => {
114157

115-
fs.readFile(tempdb.path, (err, contents) => {
158+
if (err) {
116159

117-
if (err) {
160+
return reject(err);
118161

119-
return reject(err);
162+
}
120163

121-
}
164+
zip.addFile(
165+
`${
166+
data.title
167+
}.docset/Contents/Resources/docSet.dsidx`,
168+
contents
169+
);
122170

123-
zip.addFile(
124-
`${data.title}.docset/Contents/Resources/docSet.dsidx`,
125-
contents
126-
);
171+
return resolve(zip.toBuffer());
127172

128-
return resolve(zip.toBuffer());
173+
});
129174

130-
});
175+
return false;
131176

132-
return false;
177+
});
133178

134-
});
179+
return false;
135180

136-
return false;
181+
}
182+
);
137183

138-
});
184+
return false;
139185

140-
return false;
186+
}
187+
);
141188

142189
});
143190

144-
});
145-
146191
module.exports = plugin;

0 commit comments

Comments
 (0)