diff --git a/.npmignore b/.npmignore index 9b40c735..57823065 100755 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,7 @@ .travis* +Cakefile Makefile +History.md docs/ src/ diff --git a/.travis.yml b/.travis.yml index 5d7e416a..9526f7e5 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,11 @@ language: node_js -before_script: "make test-prepare" +install: "npm install" +before_script: "./node_modules/.bin/cake test-prepare" +script: "./node_modules/.bin/cake test" node_js: - 0.6 - 0.8 + - 0.9 notifications: irc: - "irc.freenode.org#bevry-dev" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e7a3c0da..ec1e9391 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,9 +19,10 @@ 1. Fork the DocPad Repository 1. Clone your fork and cd into it -1. Run `npm install` to install dependencies +1. Insure CoffeeScript is installed globally; `npm install -g coffee-script` +1. Run `cake setup` to setup project for development 1. Run `npm link` to link our local copy as the global instance (so it is available via `docpad`) -1. Run `make dev` to compile our coffeescript and recompile on changes +1. Run `cake watch` to compile our source files and recompile on changes ## Pull Requests @@ -35,5 +36,5 @@ ## Testing -1. Run `npm test` to run the tests +1. Run `cake test` to run the tests 1. There are several types of tests run, the most common is the rendering test, which compares files inside `test/out` to `test/out-expected` diff --git a/Cakefile b/Cakefile new file mode 100644 index 00000000..dd0017e5 --- /dev/null +++ b/Cakefile @@ -0,0 +1,129 @@ +# This file was originally created by Benjamin Lupton (http://balupton.com) +# and is currently licensed under the Creative Commons Zero (http://creativecommons.org/publicdomain/zero/1.0/) +# making it public domain so you can do whatever you wish with it without worry (you can even remove this notice!) +# +# If you change something here, be sure to reflect the changes in: +# - the scripts section of the package.json file +# - the .travis.yml file + + +# ----------------- +# Variables + +WINDOWS = process.platform.indexOf('win') is 0 +NODE = process.execPath +NPM = if WINDOWS then process.execPath.replace('node.exe','npm.cmd') else 'npm' +EXT = (if WINDOWS then '.cmd' else '') +APP = process.cwd() +BIN = "#{APP}/node_modules/.bin" +CAKE = "#{BIN}/cake#{EXT}" +COFFEE = "#{BIN}/coffee#{EXT}" +OUT = "#{APP}/out" +SRC = "#{APP}/src" +TEST = "#{APP}/test" + + +# ----------------- +# Requires + +pathUtil = require('path') +{exec,spawn} = require('child_process') +safe = (next,fn) -> + return (err) -> + return next(err) if err + return fn() + + +# ----------------- +# Actions + +clean = (opts,next) -> + (next = opts; opts = {}) unless next? + args = [ + '-Rf' + OUT + pathUtil.join(APP,'node_modules') + pathUtil.join(APP,'*out') + pathUtil.join(APP,'*log') + pathUtil.join(TEST,'node_modules') + pathUtil.join(TEST,'*out') + pathUtil.join(TEST,'*log') + ] + spawn('rm', args, {stdio:'inherit',cwd:APP}).on('exit',next) + +compile = (opts,next) -> + (next = opts; opts = {}) unless next? + spawn(COFFEE, ['-bco', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next) + +watch = (opts,next) -> + (next = opts; opts = {}) unless next? + spawn(COFFEE, ['-bwco', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next) + +install = (opts,next) -> + (next = opts; opts = {}) unless next? + spawn(NPM, ['install'], {stdio:'inherit',cwd:APP}).on 'exit', safe next, -> + spawn(NPM, ['install'], {stdio:'inherit',cwd:TEST}).on('exit',next) + +reset = (opts,next) -> + (next = opts; opts = {}) unless next? + clean opts, safe next, -> install opts, safe next, -> compile opts, next + +setup = (opts,next) -> + (next = opts; opts = {}) unless next? + install opts, safe next, -> + compile opts, next + +test = (opts,next) -> + (next = opts; opts = {}) unless next? + args = [] + args.push("--debug-brk") if opts.debug + args.push("#{OUT}/test/everything.test.js") + args.push("--joe-reporter=list") + spawn(NODE, args, {stdio:'inherit',cwd:APP}, next) + +finish = (err) -> + throw err if err + console.log('OK') + + +# ----------------- +# Commands + +# clean +task 'clean', 'clean up instance', -> + clean finish + +# compile +task 'compile', 'compile our files', -> + compile finish + +# dev/watch +task 'dev', 'watch and recompile our files', -> + watch finish +task 'watch', 'watch and recompile our files', -> + watch finish + +# install +task 'install', 'install dependencies', -> + install finish + +# reset +task 'reset', 'reset instance', -> + reset finish + +# setup +task 'setup', 'setup for development', -> + setup finish + +# test +task 'test', 'run our tests', -> + test finish + +# test-debug +task 'test-debug', 'run our tests in debug mode', -> + test {debug:true}, finish + +# test-prepare +task 'test-prepare', 'prepare out tests', -> + setup finish + diff --git a/History.md b/History.md index 3e7c47be..6a7b3f47 100755 --- a/History.md +++ b/History.md @@ -1,5 +1,13 @@ ## History +- v6.21.5 January 24, 2013 + - Supports Node v0.9 + - Added `renderSingleExtensions` option + - Note: currently this will render `src/documents/script.coffee` from CoffeeScript to JavaScript as intended, HOWEVER the outfile will be `out/script.coffee` instead of the expected `out/script.js`. We will likely have to do an extension mapping for single extensions. + - Added expiremental `docpad-compile` executable + - Updated dependencies + - [bal-util](https://github.com/balupton/bal-util) from ~1.15.4 to ~1.16.0 + - v6.21.4 January 16, 2013 - Fixed incorrect meta data parsing for certain files - Closes [issue #394](https://github.com/bevry/docpad/issues/394) thanks to [Jose Quesada](https://github.com/quesada) and [Stefan](https://github.com/stegrams) diff --git a/LICENSE.txt b/LICENSE.md similarity index 100% rename from LICENSE.txt rename to LICENSE.md diff --git a/Makefile b/Makefile deleted file mode 100755 index b2239c1c..00000000 --- a/Makefile +++ /dev/null @@ -1,61 +0,0 @@ -# If you change something here, be sure to reflect the changes in: -# - the scripts section of the package.json file -# - the .travis.yml file - -# ----------------- -# Variables - -BIN=node_modules/.bin -COFFEE=$(BIN)/coffee -OUT=out -SRC=src - - -# ----------------- -# Documentation - -# Usage: coffee [options] path/to/script.coffee -- [args] -# -b, --bare compile without a top-level function wrapper -# -c, --compile compile to JavaScript and save as .js files -# -o, --output set the output directory for compiled JavaScript -# -w, --watch watch scripts for changes and rerun commands - - -# ----------------- -# Commands - -# Watch and recompile our files -dev: - $(COFFEE) -cbwo $(OUT) $(SRC) - -# Compile our files -compile: - $(COFFEE) -cbo $(OUT) $(SRC) - -# Clean up -clean: - rm -Rf $(OUT) node_modules *.log - -# Install dependencies -install: - npm install - -# Reset -reset: - make clean - make install - make compile - -# Ensure everything is ready for our tests (used by things like travis) -test-prepare: - make reset - rm -Rf test/node_modules test/*out test/*.log - cd test; npm install - -# Run our tests -test: - npm test - - -# Ensure the listed commands always re-run and are never cached -.PHONY: dev compile clean install reset test-prepare test diff --git a/bin/docpad-compile b/bin/docpad-compile new file mode 100755 index 00000000..dd91e5e5 --- /dev/null +++ b/bin/docpad-compile @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require(__dirname+'/../out/bin/docpad-compile'); \ No newline at end of file diff --git a/package.json b/package.json index 35b1e660..86961e46 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docpad", - "version": "6.21.4", + "version": "6.21.5", "description": "DocPad is a language agnostic document management system. This means you write your website as documents, in whatever language you wish, and DocPad will handle the compiling, templates and layouts for you. For static documents it will generate static files, for dynamic documents it'll re-render them on each request. You can utilise DocPad by itself, or use it as a module your own custom system. It's pretty cool, and well worth checking out. We love it.", "homepage": "https://github.com/bevry/docpad", "installUrl": "http://docpad.org/install", @@ -61,7 +61,7 @@ "npm": ">=1.1" }, "dependencies": { - "bal-util": "~1.15.4", + "bal-util": "~1.16.0", "caterpillar": "~1.1.3", "commander": "~1.1.1", "cson": "~1.4.0", @@ -90,11 +90,12 @@ }, "bin": { "docpad": "./bin/docpad", + "docpad-compile": "./bin/docpad-compile", "docpad-debug": "./bin/docpad-debug", "docpad-server": "./bin/docpad-server" }, "scripts": { - "test": "node ./out/test/everything.test.js" + "test": "./node_modules/.bin/cake test" }, "main": "./out/main.js" } \ No newline at end of file diff --git a/src/bin/docpad-compile.coffee b/src/bin/docpad-compile.coffee new file mode 100644 index 00000000..f3eb891f --- /dev/null +++ b/src/bin/docpad-compile.coffee @@ -0,0 +1,53 @@ +# Require +DocPad = require(__dirname+'/../lib/docpad') + +# Prepare +getArgument = (name,value=null,defaultValue=null) -> + result = defaultValue + argumentIndex = process.argv.indexOf("--#{name}") + if argumentIndex isnt -1 + result = value ? process.argv[argumentIndex+1] + return result + +# DocPad Action +action = (getArgument('action',null,'generate')+' '+getArgument('watch','watch','')).trim() + +# DocPad Configuration +docpadConfig = {} +docpadConfig.rootPath = getArgument('rootPath',null,process.cwd()) +docpadConfig.outPath = getArgument('outPath',null,docpadConfig.rootPath+'/out') +docpadConfig.srcPath = getArgument('srcPath',null,docpadConfig.rootPath+'/src') +docpadConfig.documentsPaths = (-> + documentsPath = getArgument('documentsPath') + if documentsPath? + documentsPath = docpadConfig.srcPath if documentsPath is 'auto' + else + documentsPath = docpadConfig.srcPath+'/documents' + return [documentsPath] +)() +docpadConfig.port = (-> + port = getArgument('port') + port = parseInt(port,10) if port and isNaN(port) is false + return port +)() +docpadConfig.renderSingleExtensions = (-> + renderSingleExtensions = getArgument('renderSingleExtensions',null,'auto') + if renderSingleExtensions in ['true','yes'] + renderSingleExtensions = true + else if renderSingleExtensions in ['false','no'] + renderSingleExtensions = false + return renderSingleExtensions +)() + +# Create DocPad Instance +DocPad.createInstance docpadConfig, (err,docpad) -> + # Check + return console.log(err.stack) if err + + # Generate and Serve + docpad.action action, (err) -> + # Check + return console.log(err.stack) if err + + # Done + console.log('OK') diff --git a/src/bin/docpad-server.coffee b/src/bin/docpad-server.coffee index f00884a2..520e2c8b 100644 --- a/src/bin/docpad-server.coffee +++ b/src/bin/docpad-server.coffee @@ -1,29 +1,23 @@ # Require DocPad = require(__dirname+'/../lib/docpad') -# DocPad Configuration -docpadConfig = {} -serverAction = process.env.DOCPAD_SERVER_ACTION or 'server generate' +# Prepare +getArgument = (name,value=null,defaultValue=null) -> + result = defaultValue + argumentIndex = process.argv.indexOf("--#{name}") + if argumentIndex isnt -1 + result = value ? process.argv[argumentIndex+1] + return result -# --action -(-> - actionArgumentIndex = process.argv.indexOf('--action') - if actionArgumentIndex isnt -1 - serverAction = process.argv[actionArgumentIndex+1] -)() +# DocPad Action +action = getArgument('action',null,'server generate') -# --port -(-> - portArgument = null - portArgumentIndex = process.argv.indexOf('--port') - if portArgumentIndex isnt -1 - portArgument = process.argv[portArgumentIndex+1] - if isNaN(portArgument) - portArgument = null - else - portArgument = parseInt(portArgument,10) - if portArgument - docpadConfig.port = portArgument +# DocPad Configuration +docpadConfig = {} +docpadConfig.port = (-> + port = getArgument('port') + port = parseInt(port,10) if port and isNaN(port) is false + return port )() # Create DocPad Instance @@ -32,7 +26,7 @@ DocPad.createInstance docpadConfig, (err,docpad) -> return console.log(err.stack) if err # Generate and Serve - docpad.action serverAction, (err) -> + docpad.action action, (err) -> # Check return console.log(err.stack) if err diff --git a/src/lib/docpad.coffee b/src/lib/docpad.coffee index 555e43b6..7d4ed91b 100755 --- a/src/lib/docpad.coffee +++ b/src/lib/docpad.coffee @@ -774,6 +774,10 @@ class DocPad extends EventEmitterEnhanced # ----------------------------- # Other + # Render Single Extensions + # Whether or not we should render single extensions by default + renderSingleExtensions: false + # Render Passes # How many times should we render documents that reference other documents? renderPasses: 1 @@ -980,6 +984,9 @@ class DocPad extends EventEmitterEnhanced docpad = @ locale = @getLocale() + # Render Single Extensions + @DocumentModel::defaults.renderSingleExtensions = docpad.config.renderSingleExtensions + # Version Check @compareVersion() @@ -1890,7 +1897,7 @@ class DocPad extends EventEmitterEnhanced # Snore @slowPlugins = {} - snore = @createSnore -> + snore = balUtil.createSnore -> docpad.log 'notice', util.format(locale.pluginsSlow, _.keys(docpad.slowPlugins).join(', ')) # Async @@ -2064,33 +2071,6 @@ class DocPad extends EventEmitterEnhanced # --------------------------------- # Utilities: Misc - # Create snore - createSnore: (message) -> - # Prepare - docpad = @ - - # Create snore object - snore = - snoring: false - timer: setTimeout( - -> - snore.clear() - snore.snoring = true - if _.isFunction(message) - message() - else - docpad.log 'notice', message - 5000 - ) - clear: -> - if snore.timer - clearTimeout(snore.timer) - snore.timer = false - - # Return - snore - - # Compare current DocPad version to the latest compareVersion: -> return @ unless @config.checkVersion