-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.js
64 lines (59 loc) · 2.01 KB
/
generate.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
var build = require("./build/build");
var write = require("./write/write");
var Q = require("q");
var fs = require("fs-extra");
var mkdirs = Q.denodeify(fs.mkdirs);
var Handlebars = require("handlebars");
/**
* @parent bit-docs-generate-html/modules
* @module {function} bit-docs-generate-html/generate
*
* Generates an HTML site for a [bit-docs/types/docMap]
* given configuration siteConfig.
*
* @signature `generate(docMapPromise, siteConfig)`
*
* @param {Promise<bit-docs/types/docMap>} docMapPromise A promise that
* contains a `docMap` created by [bit-docs-glob-finder/index].
*
* @param {Object} siteConfig Configuration siteConfig.
*
* @return {Promise} A promise that resolves when the site has been built.
*/
module.exports = function(docMapPromise, siteConfig){
// 1. Copies everything from site/default/static to site/static/build
// 2. Overwrites site/static/build with content in `siteConfig.static`
// 3. Runs site/static/build/build.js
// A. Builds itself and copies everything to site/static/dist
var staticPromise = build.staticDist(siteConfig).then(function(){
// copies statics to documentation location.
return write.staticDist(siteConfig);
});
var buildTemplatesPromise = build.templates(siteConfig).then(function(){
return Handlebars.create();
});
buildTemplatesPromise["catch"](function(){
console.log("problem building templates");
});
var currentDocObject;
var getCurrent = function(){
return currentDocObject;
};
var setCurrent = function(current){
currentDocObject = current;
};
var helpersReadyPromise = docMapPromise.then(function(docMap){
return build.helpers(buildTemplatesPromise, docMap, siteConfig, getCurrent);
});
var docsPromise = Q.all([
docMapPromise,
build.renderer(buildTemplatesPromise, siteConfig),
helpersReadyPromise,
mkdirs(siteConfig.dest)
]).then(function(results){
var docMap = results[0],
renderer = results[1];
return write.docMap(docMap, renderer, siteConfig, setCurrent);
});
return Q.all([staticPromise, docsPromise]);
};