|
1 | 1 | var fs = require('fs'),
|
2 |
| - path = require('path'); |
| 2 | + path = require('path'), |
| 3 | + hbs = require('handlebars'), |
| 4 | + helpers = require('../lib/helpers')(hbs), |
| 5 | + admzip = require('adm-zip'), |
| 6 | + temp = require('temp').track(), |
| 7 | + sqlite3 = require('sqlite3').verbose(); |
| 8 | + |
| 9 | +module.exports.buildDashDocSet = function (input) { |
| 10 | + |
| 11 | + var zip = new admzip(), |
| 12 | + tempdb = temp.openSync('temp.sqlite'), |
| 13 | + db = new sqlite3.Database(tempdb.path); |
| 14 | + |
| 15 | + input.uid = module.exports.formatStringForUID(input.title); |
| 16 | + |
| 17 | + zip.addFile( |
| 18 | + input.title + '.docset/Contents/Resources/Documents/index.html', |
| 19 | + require('../templates/dash/index.hbs')(input) |
| 20 | + ); |
| 21 | + |
| 22 | + zip.addFile( |
| 23 | + input.title + '.docset/Contents/Info.plist', |
| 24 | + require('../templates/dash/plist.hbs')(input) |
| 25 | + ); |
| 26 | + |
| 27 | + db.serialize(function() { |
| 28 | + |
| 29 | + db.run('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);'); |
| 30 | + db.run('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);'); |
| 31 | + |
| 32 | + input.files.forEach(function (file) { |
| 33 | + |
| 34 | + file.methods.forEach(function (method) { |
| 35 | + |
| 36 | + if (!method.ignore && method.ctx) { |
| 37 | + |
| 38 | + db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', { |
| 39 | + $name: hbs.helpers.formatName(method.ctx.string), |
| 40 | + $type: method.ctx.type.replace(/^[a-z]/, function (match) { return match.toUpperCase(); }), |
| 41 | + $path: 'index.html#' + method.ctx.uid |
| 42 | + }); |
| 43 | + |
| 44 | + } |
| 45 | + |
| 46 | + }); |
| 47 | + |
| 48 | + }); |
| 49 | + |
| 50 | + }); |
| 51 | + |
| 52 | + db.close(function () { |
| 53 | + |
| 54 | + zip.addFile( |
| 55 | + input.title + '.docset/Contents/Resources/docSet.dsidx', |
| 56 | + fs.readFileSync(tempdb.path) |
| 57 | + ); |
| 58 | + |
| 59 | + if (input.output) { |
| 60 | + |
| 61 | + fs.writeFileSync(input.output, zip.toBuffer(), 'utf8'); |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + }); |
| 66 | + |
| 67 | + if (!input.output) { |
| 68 | + |
| 69 | + console.error('Not avalible through stdout. Please use the --output flag instead.'); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + return false; |
| 74 | + |
| 75 | +}; |
3 | 76 |
|
4 | 77 | module.exports.findPackage = function (input) {
|
5 | 78 |
|
|
0 commit comments