Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docSet.dsidx
reference.html
node_modules/
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# joi.docset
Just a simple dash docset for joi (https://github.com/spumko/joi). Available through dashs "user contributed" channel ;-)
Just a simple dash docset for joi (https://github.com/hapijs/joi). Available through dashs "user contributed" channel ;-)

## Generate Docset

This requires [Node.js](https://nodejs.org/en/download/) and [sqlite](https://www.sqlite.org/) to be installed.

```bash
npm install
node generate
tar --exclude='.DS_Store' -cvzf ./releases/joi-XXX.tgz joi.docset
```
```
44 changes: 31 additions & 13 deletions generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ var sqlite3 = require('sqlite3');
var _ = require('lodash');
var mkdirp = require('mkdirp');
var docsetName = 'joi.docset';
var referenceUrl = 'https://raw.githubusercontent.com/hapijs/joi/master/README.md';
var referenceUrl = 'https://raw.githubusercontent.com/hapijs/joi/master/API.md';
var Path = require('path');

var documentsPath = Path.join(__dirname, './' + docsetName + '/Contents/Resources/Documents/');
var dbFile = Path.join(__dirname, './' + docsetName + '/Contents/Resources/docSet.dsidx');
var db;
var db;

var joiVersion = "NO-VERSION";

var prepareIndexEntry = function (method, anchor) {
var type = 'Guide';
Expand All @@ -34,7 +36,6 @@ var prepareIndexEntry = function (method, anchor) {
type = 'Constructor';
}


if (method.indexOf('new ') === 0) {
type = 'Constructor';
}
Expand Down Expand Up @@ -66,8 +67,29 @@ var fetchRawMarkdown = function (url) {
};

var removeHeader = function (markdown) {
return Q.Promise(function (resolve, reject) {
var replaced = false;
markdown = markdown.replace(/^<!-- version -->\s*?(# [\d\.xX]* API Reference)\s*?<!-- versionstop -->\s*?<img src="https:\/\/raw.github.com\/hapijs\/joi\/master\/images\/validation\.png" align="right" \/>\s*?<!-- toc -->/, function (match, $1) {
replaced = true;
return $1;
});
if (replaced) {
return resolve(markdown);
}
else {
return reject(new Error('Unable to match header for removal'));
}
});
};

var echoVersion = function (markdown) {
return Q.Promise(function (resolve) {
markdown = "# Joi Reference" + markdown.split('<img src="https://raw.github.com/hapijs/joi/master/images/validation.png" align="right" />')[1];
var versionMatcher = /^# ([\d\.xX]*)/g;
var match = versionMatcher.exec(markdown);
if (match) {
console.log('Joi version: '+match[1]);
joiVersion = match[1];
}
resolve(markdown);
});
};
Expand Down Expand Up @@ -97,7 +119,6 @@ var createSearchIndex = function (markdown) {
});
};


var generateHtml = function (markdown) {
var payload = {
text: markdown,
Expand Down Expand Up @@ -146,7 +167,7 @@ var addDashAnchors = function (text) {
return resolve(text);
});
});
}
};

var wrapInDocument = function (text) {
return Q.Promise(function (resolve) {
Expand All @@ -170,31 +191,28 @@ var writeFile = function (text) {
});
};




mkdirp(documentsPath, function (err) {
fs.unlink(dbFile, function(error) {
if (!error) {
console.log('Previous database deleted!');
};
}

db = new sqlite3.Database(dbFile);
db = new sqlite3.Database(dbFile);
db.serialize(function () {
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);");


fetchRawMarkdown(referenceUrl)
.then(removeHeader)
.then(echoVersion)
.then(createSearchIndex)
.then(generateHtml)
.then(replaceUserContent)
.then(addDashAnchors)
.then(wrapInDocument)
.then(writeFile)
.then(function (markdown) {
console.log('Generation completed!');
console.log('Generation of joi.docset version '+joiVersion+' completed!');
}).catch(function (e) {
console.log(e);
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "joi-docset",
"version": "1.0.0",
"version": "1.1.0",
"description": "Dash docset for joi",
"main": "generate.js",
"scripts": {
Expand All @@ -13,6 +13,6 @@
"mkdirp": "^0.5.0",
"q": "^1.0.1",
"request": "^2.36.0",
"sqlite3": "^2.2.3"
"sqlite3": "^3.0.10"
}
}
Binary file added releases/joi-9.0.1.tgz
Binary file not shown.