Skip to content

Commit 23fc68d

Browse files
Merge pull request #30 from bit-docs/29-create-docmap-hash
#29 create docmap hash file
2 parents 556aae0 + 79ca026 commit 23fc68d

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

generate.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ module.exports = function(docMapPromise, siteConfig){
5151
var searchMapPromise = docMapPromise.then(function(docMap){
5252
return write.searchMap(docMap, siteConfig);
5353
});
54+
var searchMapHashPromise = searchMapPromise.then(function(searchMap){
55+
return write.docMapHash(searchMap, siteConfig);
56+
});
5457

5558
var docsPromise = Q.all([
5659
docMapPromise,
5760
build.renderer(buildTemplatesPromise, siteConfig),
5861
helpersReadyPromise,
5962
mkdirs(siteConfig.dest),
60-
searchMapPromise
63+
searchMapPromise,
64+
searchMapHashPromise
6165
]).then(function(results){
6266
var docMap = results[0],
6367
renderer = results[1];

write/doc_map_hash.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var fs = require('fs'),
2+
path = require('path'),
3+
Q = require('q'),
4+
writeFile = Q.denodeify(fs.writeFile),
5+
mkdirs = Q.denodeify(require("fs-extra").mkdirs),
6+
md5 = require('md5');
7+
8+
/**
9+
* @function bitDocs.generators.html.write.docMapHash
10+
* @parent bitDocs.generators.html.write.methods
11+
*
12+
* Writes out file containing an md5 hash of a docMap-like object
13+
* (docMap or subset of a docMap)
14+
*
15+
* @signature `.write.docMapHash(docMap, siteConfig)`
16+
*
17+
* @param {documentjs.process.docMap} docMap
18+
* @param {Object} siteConfig
19+
* @return {Promise} Resolves when docMapHash has been written.
20+
*/
21+
module.exports = function(docMap, siteConfig) {
22+
var docMapHashConfig = {
23+
hash: md5(JSON.stringify(docMap))
24+
},
25+
dest = path.join(siteConfig.dest, 'docMapHash.json');
26+
27+
return mkdirs(siteConfig.dest).then(function(){
28+
return writeFile(dest, JSON.stringify(docMapHashConfig)).then(function(){
29+
return docMapHashConfig;
30+
});
31+
});
32+
33+
};

write/search_map.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ module.exports = function(docMap, siteConfig) {
3838
var dest = path.join(siteConfig.dest, 'searchMap.json');
3939

4040
return mkdirs(siteConfig.dest).then(function(){
41-
return writeFile(dest, JSON.stringify(searchMap));
41+
return writeFile(dest, JSON.stringify(searchMap)).then(function(){
42+
return searchMap;
43+
});
4244
});
4345

4446
};

write/write.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ exports.docMap = require("./doc_map");
1515
exports.docObject = require("./doc_object");
1616
exports.staticDist = require("./static_dist");
1717
exports.searchMap = require("./search_map");
18+
exports.docMapHash = require("./doc_map_hash");

0 commit comments

Comments
 (0)