diff --git a/.gitignore b/.gitignore index 7283991..4385c06 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ site/static/build/ site/static/dist/ site/templates/ test/tmp -.idea/ \ No newline at end of file +.idea/ +.vscode +.DS_Store diff --git a/build/build_test.js b/build/build_test.js index efc40e1..1343a6d 100644 --- a/build/build_test.js +++ b/build/build_test.js @@ -1,42 +1,40 @@ -require("./make_default_helpers_test"); - +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); +var Q = require('q'); +var rimraf = require('rimraf'); 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 rmdir = Q.denodeify(rimraf); var read = Q.denodeify(fs.readFile); -describe("documentjs/lib/generators/html/build",function(){ +require("./make_default_helpers_test"); + +describe("documentjs/lib/generators/html/build", function(){ - beforeEach(function(done){ - rmdir(path.join(__dirname,"..","site","static"), function(e){ - rmdir(path.join(__dirname,"..","site","templates"), done); + beforeEach(function(){ + return rmdir(path.join(__dirname, "..", "site", "static")).then(function(){ + return rmdir(path.join(__dirname, "..", "site", "templates")); }); }); - it("get_renderer and get_partial work",function(done){ - Q.all([ + it("get_renderer and get_partial work", function(){ + return Q.all([ getRenderer('build/test/templates'), getPartials('build/test/templates') ]).then(function(results){ - var renderer = results[0]; - var result = renderer({subject: "World"}); assert.equal(result, "

Hello World

"); - done(); - },done).catch(done); + }); }); - it("build.renderer build.templates build.helpers",function(done){ - + it("build.renderer build.templates build.helpers", function(){ var options = { - html: { templates: path.join(__dirname,"test","templates_with_helpers") }, + html: { templates: path.join(__dirname, "test", "templates_with_helpers") }, dest: "XXXXYYYZZZ", forceBuild: true, pageConfig: { @@ -53,13 +51,11 @@ describe("documentjs/lib/generators/html/build",function(){ }; - Q.all([ + return Q.all([ build.renderer(buildTemplatesPromise, options), build.helpers(buildTemplatesPromise, {}, options, getCurrent) ]).then(function(results){ - var renderer = results[0]; - var result = renderer({ subject: "World", src: "./index.js", @@ -68,14 +64,13 @@ describe("documentjs/lib/generators/html/build",function(){ }); assert.equal(result, "

HELLO World

\n"); - done(); - },done).catch(done); + }); }); - it("Does ignoreTemplateRender",function(done){ + it("Does ignoreTemplateRender", function(){ var options = { - html: {templates: path.join(__dirname,"test","render_body_option")}, + html: {templates: path.join(__dirname, "test", "render_body_option")}, dest: "XXXXYYYZZZ", forceBuild: true, pageConfig: { @@ -91,18 +86,15 @@ describe("documentjs/lib/generators/html/build",function(){ return data; }; - Q.all([ + return Q.all([ build.renderer(buildTemplatesPromise, options), build.helpers(buildTemplatesPromise, {}, options, getCurrent) ]).then(function(results){ - var renderer = results[0]; - var result = renderer({body: "{{message}} stuff"}); assert.equal(result, "

{{message}} stuff

\n

static

"); - done(); - },done).catch(done); + }); }); @@ -116,7 +108,7 @@ describe("documentjs/lib/generators/html/build",function(){ } } }).then(function(result){ - return read(path.join(__dirname, "..", result.distFolder, "bundles","bit-docs-site","static.js")); + 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"); }); @@ -154,9 +146,11 @@ describe("documentjs/lib/generators/html/build",function(){ }); }); - it("makes linked content",function(done){ + it("makes linked content", function(){ var options = { - html: { templates: path.join(__dirname,"test","escaped") }, + html: { + templates: path.join(__dirname, "test", "escaped") + }, dest: "XXXXYYYZZZ", forceBuild: true, pageConfig: { @@ -181,18 +175,14 @@ describe("documentjs/lib/generators/html/build",function(){ something: {name: "something", title: ""} }; - - Q.all([ + return Q.all([ build.renderer(buildTemplatesPromise, options), build.helpers(buildTemplatesPromise, docMap, options, getCurrent) ]).then(function(results){ - var renderer = results[0]; - var result = renderer(docObject); + assert.equal(result, "

This is

\n\n"); - done(); - },done).catch(done); + }); }); - }); diff --git a/build/static_dist.js b/build/static_dist.js index ae7c765..35382b6 100644 --- a/build/static_dist.js +++ b/build/static_dist.js @@ -113,6 +113,8 @@ function addPackages(siteConfig, buildFolder) { return readFile(path.join(fullBuildFolderPath, "package.json")).then(function(packageContents){ var json = JSON.parse(packageContents); + json = _.merge(json || {}, siteConfig.html.package); + // Legacy support for dependency injection json.dependencies = _.assign(json.dependencies || {},siteConfig.html.dependencies); return writeFile( path.join(fullBuildFolderPath, "package.json"), JSON.stringify(json) ).then(function(){ @@ -158,7 +160,7 @@ function installPackages(options, buildFolder, distFolder, hash){ if(options.debug) { console.log("BUILD: Getting build module"); } - + var build = require("../site/static/build/"+hash+"/build.js"); return build(options,{ dist: distFolder, diff --git a/html_test.js b/html_test.js index 3aef10f..1e0ef39 100644 --- a/html_test.js +++ b/html_test.js @@ -1,70 +1,63 @@ -require("./build/build_test"); +var fs = require('fs'); +var path = require('path'); +var assert = require('assert'); +var _ = require('lodash'); +var Q = require('q'); +var rimraf = require('rimraf'); +var html = require("./html"); +var rmdir = Q.denodeify(rimraf); +var readFile = Q.denodeify(fs.readFile); -var html = require("./html"), - assert = require('assert'), - Q = require('q'), - path = require('path'), - fs = require('fs'), - rmdir = require('rimraf'), - _ = require('lodash'), - readFile = Q.denodeify(fs.readFile); +require("./build/build_test"); -describe("documentjs/lib/generators/html",function(){ - beforeEach(function(done){ - rmdir(path.join(__dirname,"site","static"), function(e){ - rmdir(path.join(__dirname,"site","templates"), done) +describe("documentjs/lib/generators/html", function(){ + beforeEach(function(){ + return rmdir(path.join(__dirname, "site", "static")).then(function(e){ + return rmdir(path.join(__dirname, "site", "templates")); }); }); - it("can push out dev mode static", function(done){ - - this.timeout(60000); - rmdir(path.join(__dirname,"test","tmp"), function(e){ - if(e) { - return done(e); - } + it("can push out dev mode static", function(){ + this.timeout(240000); + return rmdir(path.join(__dirname, "test", "tmp")).then(function(){ var options = { - dest: path.join(__dirname, "test","tmp"), + dest: path.join(__dirname, "test", "tmp"), devBuild: true, minify: false, parent: "index", forceBuild: true }; - var docMap = Q.Promise(function(resolve){ - resolve(_.assign({ - index: {name: "index", type: "page", body: "Hello World"} + index: { + name: "index", + type: "page", + body: "Hello World" + } })); - }); - html.generate(docMap,options).then(function(){ - if(!fs.existsSync(path.join(__dirname,"test","tmp","static","styles","styles.less"))) { - done(new Error("canjs does not exist")); - } else if(fs.existsSync(path.join(__dirname,"test","tmp","static","bundles","static.js"))) { - done(new Error("static build exists")); - } else { - done(); + return html.generate(docMap,options).then(function(){ + if(!fs.existsSync(path.join(__dirname, "test", "tmp", "static", "styles", "styles.less"))) { + throw new Error("canjs does not exist"); } - },done); - }, done); + if(fs.existsSync(path.join(__dirname, "test", "tmp", "static", "bundles", "static.js"))) { + throw new Error("static build exists"); + } + }); + }); }); - it("body is rendered as a mustache template prior to markdown with templateRender", function(done){ - this.timeout(40000); - rmdir(path.join(__dirname,"test","tmp"), function(e){ - if(e) { - return done(e); - } + it("body is rendered as a mustache template prior to markdown with templateRender", function(){ + this.timeout(240000); + return rmdir(path.join(__dirname, "test", "tmp")).then(function(){ var options = { - dest: path.join(__dirname, "test","tmp"), + dest: path.join(__dirname, "test", "tmp"), parent: "index", templateRender: true }; - var docMap = Q.Promise(function(resolve){ resolve(_.assign({ index: { @@ -75,102 +68,90 @@ describe("documentjs/lib/generators/html",function(){ thing: { name: "thing", params: [ - {name: "first"} + { + name: "first" + } ] } })); }); - html.generate(docMap,options).then(function(){ - fs.readFile( - path.join(__dirname,"test","tmp","index.html"), - function(err, data){ - if(err) { - done(err); - } - assert.ok( /first<\/code>/.test(""+data), "got first" ); - done(); - }); - - },done); + return html.generate(docMap,options); + }).then(function(){ + return readFile(path.join(__dirname, "test", "tmp", "index.html")); + }).then(function(data){ + assert.ok(/first<\/code>/.test(""+data), "got first"); }); }); it("closing script tags are properly escaped", function() { this.timeout(40000); - return Q.denodeify(rmdir)(path.join(__dirname,"test","tmp")) - .then(function() { - var options = { - dest: path.join(__dirname, "test","tmp"), - parent: "index", - templateRender: true - }; - - var docMap = Q.Promise(function(resolve){ - resolve(_.assign({ - index: { - name: "index", - type: "page", - body: [ - "Hello `{{thing.params.0.script}}`", - "Load steal using \n\n `{{thing.params.1.script}}`" - ].join("\n") - }, - thing: { - name: "thing", - params: [ - {script: ""}, - {script: ""} - ] - } - })); - }); - - return html.generate(docMap, options); - }) - .then(function() { - return readFile(path.join(__dirname, "test", "tmp", "index.html")); - }) - .then(function(data) { - var index = data.toString(); - - assert.ok( - index.includes("&lt;script&gt;function() {return true; }&lt;\/script&gt;<\/code>"), - "script closing tag escaped" - ); - }) - .then(function() { - return readFile(path.join(__dirname, "test", "tmp", "thing.html")); - }) - .then(function(data) { - var content = data.toString(); - var rx = /<\/script>/g; - - var docObject = content.substring( - content.indexOf("var docObject = "), - content.indexOf("};", content.indexOf("var docObject = ")) - ); + return rmdir(path.join(__dirname, "test", "tmp")).then(function() { + var options = { + dest: path.join(__dirname, "test", "tmp"), + parent: "index", + templateRender: true + }; - assert.ok( - !rx.test(docObject), - "docObject should not have unscaped closing script tags" - ); + var docMap = Q.Promise(function(resolve){ + resolve(_.assign({ + index: { + name: "index", + type: "page", + body: [ + "Hello `{{thing.params.0.script}}`", + "Load steal using \n\n `{{thing.params.1.script}}`" + ].join("\n") + }, + thing: { + name: "thing", + params: [ + {script: ""}, + {script: ""} + ] + } + })); }); + + return html.generate(docMap, options); + }) + .then(function() { + return readFile(path.join(__dirname, "test", "tmp", "index.html")); + }) + .then(function(data) { + var index = data.toString(); + assert.ok( + index.includes("&lt;script&gt;function() {return true; }&lt;\/script&gt;<\/code>"), + "script closing tag escaped" + ); + }) + .then(function() { + return readFile(path.join(__dirname, "test", "tmp", "thing.html")); + }) + .then(function(data) { + var content = data.toString(); + var rx = /<\/script>/g; + var docObject = content.substring( + content.indexOf("var docObject = "), + content.indexOf("};", content.indexOf("var docObject = ")) + ); + + assert.ok( + !rx.test(docObject), + "docObject should not have unscaped closing script tags" + ); + }); }); - it("slashes get put in a folder and can link correctly", function(done){ - this.timeout(40000); - rmdir(path.join(__dirname,"test","tmp"), function(e){ - if(e) { - return done(e); - } + it("slashes get put in a folder and can link correctly", function(){ + this.timeout(240000); + return rmdir(path.join(__dirname, "test", "tmp")).then(function(){ var options = { - dest: path.join(__dirname, "test","tmp"), + dest: path.join(__dirname, "test", "tmp"), parent: "index" }; - var docMap = Q.Promise(function(resolve){ resolve(_.assign({ index: { @@ -185,38 +166,24 @@ describe("documentjs/lib/generators/html",function(){ })); }); - html.generate(docMap,options).then(function(){ - fs.readFile( - path.join(__dirname,"test","tmp","module","name.html"), - function(err, data){ - if(err) { - done(err); - } - - - assert.ok( (""+data).indexOf('src="../static/node_modules/steal/steal.production.js"') !== -1, "got the right path to scripts" ); - assert.ok( (""+data).indexOf('href="../static/bundles/bit-docs-site/static.css"') !== -1, "got the right path to styles" ); - assert.ok( (""+data).indexOf('index') !== -1, "got the right thing to index" ); - - done(); - }); - - },done); + return html.generate(docMap,options); + }).then(function(){ + return readFile(path.join(__dirname, "test", "tmp", "module", "name.html")); + }).then(function(data){ + assert.ok((""+data).indexOf('src="../static/steal.production.js"') !== -1, "got the right path to scripts"); + assert.ok((""+data).indexOf('href="../static/bundles/bit-docs-site/static.css"') !== -1, "got the right path to styles"); + assert.ok((""+data).indexOf('index') !== -1, "got the right thing to index"); }); }); - it("dest on docObject works", function(done){ - this.timeout(40000); - rmdir(path.join(__dirname,"test","tmp"), function(e){ - if(e) { - return done(e); - } + it("dest on docObject works", function(){ + this.timeout(240000); + return rmdir(path.join(__dirname, "test", "tmp")).then(function(){ var options = { - dest: path.join(__dirname, "test","tmp","deep"), + dest: path.join(__dirname, "test", "tmp", "deep"), parent: "index" }; - var docMap = Q.Promise(function(resolve){ resolve(_.assign({ index: { @@ -232,37 +199,23 @@ describe("documentjs/lib/generators/html",function(){ })); }); - html.generate(docMap,options).then(function(){ - fs.readFile( - path.join(__dirname,"test","tmp","deep","module","name.html"), - function(err, data){ - if(err) { - done(err); - } - - - assert.ok( (""+data).indexOf('index') !== -1, "got the right thing to index" ); - - done(); - }); - - },done); + return html.generate(docMap,options); + }).then(function(){ + return readFile(path.join(__dirname, "test", "tmp", "deep", "module", "name.html")); + }).then(function(data){ + assert.ok( (""+data).indexOf('index') !== -1, "got the right thing to index" ); }); }); - it("basic sidebar works", function(done){ - this.timeout(40000); - rmdir(path.join(__dirname,"test","tmp"), function(e){ - if(e) { - return done(e); - } + it("basic sidebar works", function(){ + this.timeout(240000); + return rmdir(path.join(__dirname, "test", "tmp")).then(function(){ var options = { - dest: path.join(__dirname, "test","tmp","sidebar"), + dest: path.join(__dirname, "test", "tmp", "sidebar"), parent: "earth", forceBuild: true }; - var docMap = Q.Promise(function(resolve){ resolve(_.assign({ earth: { @@ -270,32 +223,32 @@ describe("documentjs/lib/generators/html",function(){ type: "page", body: "Welcome to earth" }, - "Americas": { + Americas: { parent: "earth", name: "Americas", body: "Americas" }, - "USA": { + USA: { parent: "Americas", name: "USA", body: "USA" }, - "Mexico": { + Mexico: { parent: "Americas", name: "Mexico", body: "Mexico" }, - "Asia": { + Asia: { parent: "earth", name: "Asia", body: "Asia" }, - "China": { + China: { parent: "Asia", name: "China", body: "China" }, - "India": { + India: { parent: "Asia", name: "India", body: "India" @@ -303,23 +256,12 @@ describe("documentjs/lib/generators/html",function(){ })); }); - html.generate(docMap,options).then(function(){ - fs.readFile( - path.join(__dirname,"test","tmp","sidebar","India.html"), - function(err, data){ - if(err) { - done(err); - } - - assert.ok( (""+data).indexOf('href="Asia.html"') !== -1, "link to asia" ); - assert.ok( (""+data).indexOf('href="China.html"') !== -1, "link to china" ); - - done(); - }); - - },done); + return html.generate(docMap,options); + }).then(function(){ + return readFile(path.join(__dirname, "test", "tmp", "sidebar", "India.html")); + }).then(function(data){ + assert.ok( (""+data).indexOf('href="Asia.html"') !== -1, "link to asia" ); + assert.ok( (""+data).indexOf('href="China.html"') !== -1, "link to china" ); }); }); - - }); diff --git a/package.json b/package.json index ff066bd..f0e7c54 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "handlebars": "1.X", "lodash": "~4.13.1", "md5": "2.1.0", - "steal-tools": "0.16.X", + "q": "^1.5.0", + "steal-tools": "^1.8.0", "striptags": "^2.1.1", "unescape-html": "^1.0.0" }, diff --git a/site/default/static/build.js b/site/default/static/build.js index e57e7ac..ac36628 100644 --- a/site/default/static/build.js +++ b/site/default/static/build.js @@ -44,7 +44,7 @@ module.exports = function(options, folders){ if(options.debug) { console.log("BUILD: Copying build to dist."); } - + staticDistPromises.push(fsx.copy(path.join(folders.build, "dist"), path.join(folders.dist))); return Q.all(staticDistPromises); diff --git a/site/default/static/package.json b/site/default/static/package.json index 11f3fbc..27d5328 100644 --- a/site/default/static/package.json +++ b/site/default/static/package.json @@ -6,10 +6,15 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "steal": { + "plugins": [ + "steal-less" + ] + }, "author": "Bitovi", "license": "MIT", "dependencies": { - "steal": "0.16.X" - }, - "system": {"npmAlgorithm": "flat"} + "steal-less": "^1.2.0", + "steal-tools": "^1.8.0" + } } diff --git a/site/default/templates/layout.mustache b/site/default/templates/layout.mustache index 2dc4c0d..3dcb3f3 100644 --- a/site/default/templates/layout.mustache +++ b/site/default/templates/layout.mustache @@ -32,7 +32,7 @@ + src="{{pathToDest}}/static/steal.production.js"> {{/if}}