Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add staticDist option #41

Merged
merged 16 commits into from
Jul 11, 2017
5 changes: 3 additions & 2 deletions bit-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ module.exports = function(bitDocs){
siteConfig.html = {
dependencies: {},
static: [],
templates: []
templates: [],
staticDist: []
};
}
var html = siteConfig.html;
_.assign(html.dependencies, htmlConfig.dependencies || {});

mergeOnto("staticDist", html, htmlConfig);
mergeOnto("static", html, htmlConfig);
mergeOnto("templates", html, htmlConfig);
});
Expand Down
59 changes: 39 additions & 20 deletions build/build_test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require("./make_default_helpers_test");

var getRenderer = require('./get_renderer'),
getPartials = require('./get_partials'),
build = require("./build"),
assert = require('assert'),
Q = require('q'),
path = require('path'),
rmdir = require('rimraf'),
fs = require('fs');
var getRenderer = require('./get_renderer');
var getPartials = require('./get_partials');
var build = require("./build");
var assert = require('assert');
var Q = require('q');
var path = require('path');
var rmdir = require('rimraf');
var fs = require('fs');
var read = Q.denodeify(fs.readFile);

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

Expand Down Expand Up @@ -105,21 +106,39 @@ describe("documentjs/lib/generators/html/build",function(){

});

it("builds the static dist", function(done){
it("builds the static dist", function(){
this.timeout(120000);
build.staticDist({
return build.staticDist({
forceBuild: true,
html: {dependencies: {"can-component": "3.0.0-pre.9"}}
}).then(function(result){
fs.readFile(path.join(__dirname, "..", result.distFolder, "bundles","bit-docs-site","static.js"), function(err, res){
if(err) {
done(err);
} else {
assert.ok(/can-component/.test(res), "got static.js with component");
done();
html: {
dependencies: {
"can-component": "3.0.0-pre.9"
}
});
}, done);
}
}).then(function(result){
return read(path.join(__dirname, "..", result.distFolder, "bundles","bit-docs-site","static.js"));
}).then(function(res){
assert.ok(/can-component/.test(res), "got static.js with component");
});
});

it("copy staticDist files to static dist", function(){
this.timeout(120000);
return build.staticDist({
forceBuild: true,
html: {
dependencies: {
"can-component": "3.0.0-pre.9"
},
staticDist: [
'test-static-dist'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an array of files, folders, or either?

]
},
}).then(function(result){
return read(path.join(__dirname, "..", result.distFolder, "test.css"));
}).then(function(res){
assert.ok(/#TestID/.test(res), "got static.js with component");
});
});

it("makes linked content",function(done){
Expand Down
51 changes: 23 additions & 28 deletions site/default/static/build.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@

var stealTools = require("steal-tools"),
fsx = require('../../../../fs_extras'),
Q = require('q'),
path = require("path");

var stealTools = require("steal-tools");
var fsExtra = require('fs-extra');
var fsx = require('../../../../fs_extras');
var Q = require('q');
var path = require("path");
var copy = Q.denodeify(fsExtra.copy);

module.exports = function(options, folders){

var copyDir = function(name){
return fsx.mkdirs( path.join(folders.dist,name) ).then(function(){
return fsx.mkdirs(path.join(folders.dist,name)).then(function(){
return fsx.exists(path.join(folders.build,name)).then(function(exists){
if(exists) {
return fsx.copy( path.join(folders.build,name), path.join(folders.dist,name) );
return fsx.copy(path.join(folders.build,name), path.join(folders.dist,name));
}
});
});
};

var staticDistPromises = [];
if(options.html && options.html.staticDist){
options.html.staticDist.forEach(function(dist){
staticDistPromises.push(copy(path.join(process.cwd(), dist), folders.dist));
});
}

if(options.devBuild) {
// copy all dependencies
var promise = Q.all([
fsx.copy(path.join(folders.build), path.join(folders.dist) )
]);
fsx.copy(path.join(folders.build), path.join(folders.dist))
].concat(staticDistPromises));
// copy everything and steal.js
return promise;
} else {
Expand All @@ -38,24 +45,12 @@ module.exports = function(options, folders){
if(options.debug) {
console.log("BUILD: Copying build to dist.");
}
return fsx.copy(path.join(folders.build, "dist"), path.join(folders.dist) );
// copy everything to DIST
/*return Q.all([
fsx.mkdirs( path.join(folders.dist,"bundles") ).then(function(){
return fsx.copy(path.join(folders.build,"bundles"), path.join(folders.dist,"bundles") );
}),
fsx.copyFrom(path.join( require.resolve("steal"), "..", "steal.production.js"), path.join(folders.dist,"steal.production.js") ),
fsx.copy( path.join(folders.build,"html5shiv.js"), path.join(folders.dist,"html5shiv.js")),

copyDir("fonts"),

copyDir("img"),
copyDir("templates")
]);*/

var promise = Q.all([
fsx.copy(path.join(folders.build, "dist"), path.join(folders.dist))
].concat(staticDistPromises));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicated here and in the options.devBuild statement branch; could this be refactored to not be repeated in both places?


return promise;
});
}



};
3 changes: 3 additions & 0 deletions test-static-dist/test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#TestID {
display: block;
}