Skip to content

Commit 4d7c8cd

Browse files
authored
Merge pull request #41 from bit-docs/40-add-static-dist-option
Add staticDist option
2 parents bfdeedc + 70cb8ae commit 4d7c8cd

File tree

5 files changed

+85
-54
lines changed

5 files changed

+85
-54
lines changed

bit-docs.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ var _ = require("lodash");
33
var tags = require("./tags/tags");
44

55
var mergeOnto = function(prop, dest, source){
6+
if(!dest[prop]) {
7+
dest[prop] = [];
8+
}
69
if(source[prop]) {
7-
dest[prop] = dest[prop].concat(source[prop])
10+
dest[prop] = dest[prop].concat(source[prop]);
811
}
912
};
1013

@@ -30,12 +33,13 @@ module.exports = function(bitDocs){
3033
siteConfig.html = {
3134
dependencies: {},
3235
static: [],
33-
templates: []
36+
templates: [],
37+
staticDist: []
3438
};
3539
}
3640
var html = siteConfig.html;
3741
_.assign(html.dependencies, htmlConfig.dependencies || {});
38-
42+
mergeOnto("staticDist", html, htmlConfig);
3943
mergeOnto("static", html, htmlConfig);
4044
mergeOnto("templates", html, htmlConfig);
4145
});

build/build_test.js

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
require("./make_default_helpers_test");
22

3-
var getRenderer = require('./get_renderer'),
4-
getPartials = require('./get_partials'),
5-
build = require("./build"),
6-
assert = require('assert'),
7-
Q = require('q'),
8-
path = require('path'),
9-
rmdir = require('rimraf'),
10-
fs = require('fs');
3+
var getRenderer = require('./get_renderer');
4+
var getPartials = require('./get_partials');
5+
var build = require("./build");
6+
var assert = require('assert');
7+
var Q = require('q');
8+
var path = require('path');
9+
var rmdir = require('rimraf');
10+
var fs = require('fs');
11+
var read = Q.denodeify(fs.readFile);
1112

1213
describe("documentjs/lib/generators/html/build",function(){
1314

@@ -105,21 +106,52 @@ describe("documentjs/lib/generators/html/build",function(){
105106

106107
});
107108

108-
it("builds the static dist", function(done){
109+
it("builds the static dist", function(){
109110
this.timeout(120000);
110-
build.staticDist({
111+
return build.staticDist({
111112
forceBuild: true,
112-
html: {dependencies: {"can-component": "3.0.0-pre.9"}}
113-
}).then(function(result){
114-
fs.readFile(path.join(__dirname, "..", result.distFolder, "bundles","bit-docs-site","static.js"), function(err, res){
115-
if(err) {
116-
done(err);
117-
} else {
118-
assert.ok(/can-component/.test(res), "got static.js with component");
119-
done();
113+
html: {
114+
dependencies: {
115+
"can-component": "3.0.0-pre.9"
120116
}
121-
});
122-
}, done);
117+
}
118+
}).then(function(result){
119+
return read(path.join(__dirname, "..", result.distFolder, "bundles","bit-docs-site","static.js"));
120+
}).then(function(res){
121+
assert.ok(/can-component/.test(res), "got static.js with component");
122+
});
123+
});
124+
125+
it("copy absolute staticDist folders to static dist", function(){
126+
this.timeout(120000);
127+
return build.staticDist({
128+
forceBuild: true,
129+
html: {
130+
staticDist: [
131+
path.join(__dirname, '..', 'test-static-dist')
132+
]
133+
},
134+
}).then(function(result){
135+
return read(path.join(__dirname, "..", result.distFolder, "test.css"));
136+
}).then(function(res){
137+
assert.ok(/#TestID/.test(res), "got test.css file");
138+
});
139+
});
140+
141+
it("copy relative staticDist folders to static dist", function(){
142+
this.timeout(120000);
143+
return build.staticDist({
144+
forceBuild: true,
145+
html: {
146+
staticDist: [
147+
'./test-static-dist'
148+
]
149+
},
150+
}).then(function(result){
151+
return read(path.join(__dirname, "..", result.distFolder, "test.css"));
152+
}).then(function(res){
153+
assert.ok(/#TestID/.test(res), "got test.css file");
154+
});
123155
});
124156

125157
it("makes linked content",function(done){

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bit-docs-generate-html",
3-
"version": "0.6.0",
3+
"version": "0.6.0-pre.1",
44
"description": "Generates an HTML site with mustache templates",
55
"main": "index.js",
66
"scripts": {

site/default/static/build.js

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
2-
var stealTools = require("steal-tools"),
3-
fsx = require('../../../../fs_extras'),
4-
Q = require('q'),
5-
path = require("path");
6-
1+
var stealTools = require("steal-tools");
2+
var fsx = require('../../../../fs_extras');
3+
var Q = require('q');
4+
var path = require("path");
75

86
module.exports = function(options, folders){
9-
107
var copyDir = function(name){
11-
return fsx.mkdirs( path.join(folders.dist,name) ).then(function(){
8+
return fsx.mkdirs(path.join(folders.dist,name)).then(function(){
129
return fsx.exists(path.join(folders.build,name)).then(function(exists){
1310
if(exists) {
14-
return fsx.copy( path.join(folders.build,name), path.join(folders.dist,name) );
11+
return fsx.copy(path.join(folders.build,name), path.join(folders.dist,name));
1512
}
1613
});
1714
});
1815
};
16+
17+
var staticDistPromises = [];
18+
if(options.html && options.html.staticDist){
19+
options.html.staticDist.forEach(function(dist){
20+
if(!path.isAbsolute(dist)){
21+
dist = path.join(process.cwd(), dist);
22+
}
23+
staticDistPromises.push(fsx.copyFrom(dist, folders.dist));
24+
});
25+
}
26+
1927
if(options.devBuild) {
2028
// copy all dependencies
21-
var promise = Q.all([
22-
fsx.copy(path.join(folders.build), path.join(folders.dist) )
23-
]);
29+
staticDistPromises.push(fsx.copy(path.join(folders.build), path.join(folders.dist)));
2430
// copy everything and steal.js
25-
return promise;
31+
return Q.all(staticDistPromises);
2632
} else {
2733

2834
// run steal-tools and then copy things
@@ -38,24 +44,10 @@ module.exports = function(options, folders){
3844
if(options.debug) {
3945
console.log("BUILD: Copying build to dist.");
4046
}
41-
return fsx.copy(path.join(folders.build, "dist"), path.join(folders.dist) );
42-
// copy everything to DIST
43-
/*return Q.all([
44-
fsx.mkdirs( path.join(folders.dist,"bundles") ).then(function(){
45-
return fsx.copy(path.join(folders.build,"bundles"), path.join(folders.dist,"bundles") );
46-
}),
47-
fsx.copyFrom(path.join( require.resolve("steal"), "..", "steal.production.js"), path.join(folders.dist,"steal.production.js") ),
48-
fsx.copy( path.join(folders.build,"html5shiv.js"), path.join(folders.dist,"html5shiv.js")),
49-
50-
copyDir("fonts"),
51-
52-
copyDir("img"),
53-
copyDir("templates")
54-
]);*/
5547

48+
staticDistPromises.push(fsx.copy(path.join(folders.build, "dist"), path.join(folders.dist)));
49+
50+
return Q.all(staticDistPromises);
5651
});
5752
}
58-
59-
60-
6153
};

test-static-dist/test.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#TestID {
2+
display: block;
3+
}

0 commit comments

Comments
 (0)