Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

96 lines (74 sloc) 2.726 kb
#
# Cakefile
# --------
#
# Targets:
#
# test:
# Try out some Casper-Chai magic
#
# toast:
# Turn lib/coffeescript into build/javascript
#
try
{spawn} = require 'child_process'
{log} = require 'util'
fs = require 'fs'
glob = require 'glob'
coffee = require 'coffee-script'
catch err
console.log "\n Package loading issue; Perhaps `npm install` needs to be run."
throw new Error("A package could not be loaded: #{err}")
SRC_DIR = 'lib'
COFFEE_SRC = ['casper-chai.coffee']
UGLIFY_CMD = './node_modules/uglify-js2/bin/uglifyjs2'
DOC_TARGET = 'docs/casper-chai.md'
task 'docs', 'create some Markdown docs in build/', ->
#
# This strips out all the coffeescript comments from the source files and
# putting them into the target.
#
# The comments are at the moment expected to be in Github Flavoured Markdown:
# http://github.github.com/github-flavored-markdown/
#
source_dir = require('path').join(__dirname, SRC_DIR)
sources = []
# Get all source files. Preserve the order in COFFEE_SRC
COFFEE_SRC.forEach (src) ->
glob.sync(src, cwd: source_dir).forEach (filename) ->
if filename not in sources
sources.push(filename)
comment_rex = /###([\s\S]+?)###/gm
comments = sources.map((src_file) ->
src_file = require('path').join(SRC_DIR, src_file)
console.log "Reading #{src_file}."
cs = fs.readFileSync(src_file, 'utf8')
match_text = cs.match(comment_rex)
.join("\n") # join all the comment blocks together into one fluid text
# remove "###"
.replace(/###/g, "")
# remove all leading space (so use ``` for code)
.replace(/\n[ \t]+/gm, "\n")
# change \n\s*@@@+ to ### (for headers, since we can't use ###)
.replace(/\n\s*@@@@@/gm, "\n#####")
.replace(/\n\s*@@@@/gm, "\n####")
.replace(/\n\s*@@@/gm, "\n###")
return match_text
).join("\n\n") # join separate files together by newlines
comments = "<!--- AUTO-GENERATED BY CAKEFILE. Do not edit! -->\n#{comments}"
console.log "Writing comment documents to #{DOC_TARGET}"
fs.writeFileSync("#{DOC_TARGET}", comments, 'utf8')
task 'deploy', 'Publish a patch release on npm (increments patch number)', ->
semver = require('semver')
# read package.json
pkg = JSON.parse(fs.readFileSync('package.json', "utf8"))
# get and increment version
version = pkg.version
pkg.version = semver.inc(version, 'patch')
# notify of version change and write new package.json
console.log "version incrementing from #{version} => #{pkg.version}"
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2), "utf8")
# rebuild the docs
invoke 'docs'
# publish
spawn "npm", ['publish'], customFds: [0,1,2]
Jump to Line
Something went wrong with that request. Please try again.