diff --git a/bit-docs.js b/bit-docs.js index 639bba1..7c543aa 100644 --- a/bit-docs.js +++ b/bit-docs.js @@ -3,8 +3,11 @@ var _ = require("lodash"); var tags = require("./tags/tags"); var mergeOnto = function(prop, dest, source){ + if(!dest[prop]) { + dest[prop] = []; + } if(source[prop]) { - dest[prop] = dest[prop].concat(source[prop]) + dest[prop] = dest[prop].concat(source[prop]); } }; @@ -30,12 +33,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); }); diff --git a/build/build_test.js b/build/build_test.js index 5e81315..efc40e1 100644 --- a/build/build_test.js +++ b/build/build_test.js @@ -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(){ @@ -105,21 +106,52 @@ 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 absolute staticDist folders to static dist", function(){ + this.timeout(120000); + return build.staticDist({ + forceBuild: true, + html: { + staticDist: [ + path.join(__dirname, '..', 'test-static-dist') + ] + }, + }).then(function(result){ + return read(path.join(__dirname, "..", result.distFolder, "test.css")); + }).then(function(res){ + assert.ok(/#TestID/.test(res), "got test.css file"); + }); + }); + + it("copy relative staticDist folders to static dist", function(){ + this.timeout(120000); + return build.staticDist({ + forceBuild: true, + html: { + staticDist: [ + './test-static-dist' + ] + }, + }).then(function(result){ + return read(path.join(__dirname, "..", result.distFolder, "test.css")); + }).then(function(res){ + assert.ok(/#TestID/.test(res), "got test.css file"); + }); }); it("makes linked content",function(done){ diff --git a/package.json b/package.json index ff7e9c6..6b811ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bit-docs-generate-html", - "version": "0.6.0", + "version": "0.6.0-pre.1", "description": "Generates an HTML site with mustache templates", "main": "index.js", "scripts": { diff --git a/site/default/static/build.js b/site/default/static/build.js index 0cf85be..e57e7ac 100644 --- a/site/default/static/build.js +++ b/site/default/static/build.js @@ -1,28 +1,34 @@ - -var stealTools = require("steal-tools"), - fsx = require('../../../../fs_extras'), - Q = require('q'), - path = require("path"); - +var stealTools = require("steal-tools"); +var fsx = require('../../../../fs_extras'); +var Q = require('q'); +var path = require("path"); 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){ + if(!path.isAbsolute(dist)){ + dist = path.join(process.cwd(), dist); + } + staticDistPromises.push(fsx.copyFrom(dist, folders.dist)); + }); + } + if(options.devBuild) { // copy all dependencies - var promise = Q.all([ - fsx.copy(path.join(folders.build), path.join(folders.dist) ) - ]); + staticDistPromises.push(fsx.copy(path.join(folders.build), path.join(folders.dist))); // copy everything and steal.js - return promise; + return Q.all(staticDistPromises); } else { // run steal-tools and then copy things @@ -38,24 +44,10 @@ 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") - ]);*/ + staticDistPromises.push(fsx.copy(path.join(folders.build, "dist"), path.join(folders.dist))); + + return Q.all(staticDistPromises); }); } - - - }; diff --git a/test-static-dist/test.css b/test-static-dist/test.css new file mode 100644 index 0000000..99f3865 --- /dev/null +++ b/test-static-dist/test.css @@ -0,0 +1,3 @@ +#TestID { + display: block; +} \ No newline at end of file