Create a gist now

Instantly share code, notes, and snippets.

@balupton /README.md
Last active Dec 11, 2015

What would you like to do?
Cakefile Attempts

Cakefile Attempts

Some attempts at making a cakefile that will work on OSX and Windows. Not having that much luck at this stage.

UPDATE: Superceded by bevry/base

# This file was originally created by Benjamin Lupton <b@lupton.cc> (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
# -----------------
# Requires
balUtil = require('bal-util')
pathUtil = require('path')
# -----------------
# Variables
EXT = (if process.platform.indexOf('win') is 0 then '.cmd' else '')
BIN = pathUtil.normalize "./node_modules/.bin"
CAKE = pathUtil.normalize "#{BIN}/cake#{EXT}"
COFFEE = pathUtil.normalize "#{BIN}/coffee#{EXT}"
COFFEE_FLAGS = "c"
CAKE = pathUtil.normalize "#{BIN}/cake#{EXT}"
DOCPAD = pathUtil.normalize "#{BIN}/docpad#{EXT}"
OUT = pathUtil.normalize "./out"
SRC = pathUtil.normalize "./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
# -----------------
# Actions
bench = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
balUtil.spawn "#{OUT}/test/benchmark.js", {output:true}, (err) ->
return next(err)
clean = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.cwd ?= process.cwd()
balUtil.spawn "rm -Rf node_modules *out *.log", {output:true,cwd:opts.cwd}, (err) ->
return next(err)
compile = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.cwd ?= process.cwd()
balUtil.spawn "#{COFFEE} -#{COFFEE_FLAGS} -o #{OUT} #{SRC}", {output:opts.cwd}, (err) ->
return next(err)
watch = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.cwd ?= process.cwd()
balUtil.spawn "#{COFFEE} -#{COFFEE_FLAGS}w -o #{OUT} #{SRC}", {output:opts.cwd}, (err) ->
return next(err)
install = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.cwd ?= process.cwd()
balUtil.npmCommand 'install', {output:true,cwd:opts.cwd}, (err) ->
return next(err)
reset = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
clean opts, (err) ->
return next(err) if err
install opts, (err) ->
return next(err) if err
compile opts, (err) ->
return next(err)
test = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.debug ?= false
balUtil.nodeCommand "#{if opts.debug then '--debug-brk' else ''} #{OUT}/test/everything.test.js --joe-reporter=list".trim(), {output:true}, (err) ->
return next(err)
testPrepare = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
reset opts, (err) ->
return next(err)
finish = (err) ->
throw err if err
console.log('OK')
# -----------------
# Commands
# bench
task 'bench', 'benchmark our project', ->
bench finish
# 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
# 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', ->
testPrepare finish
# This file was originally created by Benjamin Lupton <b@lupton.cc> (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
# -----------------
# Requires
balUtil = require('bal-util')
pathUtil = require('path')
# -----------------
# Variables
EXT = (if process.platform.indexOf('win') is 0 then '.cmd' else '')
BIN = pathUtil.resolve "./node_modules/.bin"
CAKE = pathUtil.resolve "#{BIN}/cake#{EXT}"
COFFEE = pathUtil.resolve "#{BIN}/coffee#{EXT}"
COFFEE_FLAGS = "cb"
CAKE = pathUtil.resolve "#{BIN}/cake#{EXT}"
DOCPAD = pathUtil.resolve "#{BIN}/docpad#{EXT}"
APP = pathUtil.resolve "."
OUT = pathUtil.resolve "#{APP}/out"
SRC = pathUtil.resolve "#{APP}/src"
TEST = pathUtil.resolve "#{APP}/test"
# -----------------
# Actions
clean = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
# Clean Application (./out) + Tests (./test)
balUtil.exec "rm -Rf #{OUT} #{APP}/node_modules #{APP}/*out #{APP}/*.log #{TEST}/node_modules #{TEST}/*out #{TEST}/*.log}", {output:true}, (err) ->
return next(err)
compile = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
# Compile Application (./out) + Tests (./out/test)
balUtil.spawn "#{COFFEE} -#{COFFEE_FLAGS} -o #{OUT} #{SRC}", {output:true}, (err) ->
return next(err)
watch = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
# Watch Compile Application (./out) + Tests (./out/test)
balUtil.spawn "#{COFFEE} -#{COFFEE_FLAGS}w -o #{OUT} #{SRC}", {output:true}, (err) ->
return next(err)
install = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
# Install Application (./out)
balUtil.npmCommand 'install', {output:true}, (err) ->
return next(err) if err
# Install Tests (./test)
balUtil.npmCommand 'install', {output:true,cwd:TEST}, (err) ->
return next(err)
reset = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
# Clean Application + Tests
clean opts, (err) ->
return next(err) if err
# Install Application + Tests
install opts, (err) ->
return next(err) if err
# Compile Application + Tests
compile opts, (err) ->
return next(err)
test = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.debug ?= false
# Run Tests
balUtil.nodeCommand "#{if opts.debug then '--debug-brk' else ''} #{OUT}/test/everything.test.js --joe-reporter=list".trim(), {output:true}, (err) ->
return next(err)
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
# 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', ->
reset finish
# This file was originally created by Benjamin Lupton <b@lupton.cc> (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"
# -----------------
# Requires
{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?
exec("rm -Rf #{OUT} node_modules *out *.log", {stdio:'inherit',cwd:APP}, next)
compile = (opts,next) ->
(next = opts; opts = {}) unless next?
spawn(COFFEE, ['-co', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next)
watch = (opts,next) ->
(next = opts; opts = {}) unless next?
spawn(COFFEE, ['-wco', 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',next)
reset = (opts,next) ->
(next = opts; opts = {}) unless next?
clean opts, safe 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
# 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', ->
reset finish
# This file was originally created by Benjamin Lupton <b@lupton.cc> (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} -b"
CAKE = "#{BIN}/cake#{EXT}"
DOCPAD = "#{BIN}/docpad#{EXT}"
OUT = "#{APP}/out"
SRC = "#{APP}/src"
TEST = "#{APP}/test"
TESTER = "#{OUT}/test/everything.test.js --joe-reporter=list"
# -----------------
# Requires
# Only require if we have to
taskName = process.argv[2]
if taskName
try
balUtil = require('bal-util')
pathUtil = require('path')
catch requireErr
console.log "Missing dependencies. Attempting automatic install."
task taskName, ->
return require('child_process').spawn(NPM, ['install'], {cwd:APP, stdio:'inherit'}).on 'exit', (err) ->
if err
console.log "Automatic install failed. Please run `npm install`"
throw requireErr
console.log "Automatic install was successful. Continuing with desired action."
require('child_process').spawn(CAKE, process.argv[2...], {cwd:APP, stdio:'inherit'}).on 'exit', (err,code) ->
process.exit(code)
return
# -----------------
# Actions
clean = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
(new balUtil.Group(next))
.tasks([
(complete) -> balUtil.exec("rm -Rf #{OUT}", {output:true,cwd:APP}, complete)
(complete) -> balUtil.exec("rm -Rf node_modules *out *.log", {output:true,cwd:APP}, complete)
(complete) -> balUtil.exec("rm -Rf node_modules *out *.log", {output:true,cwd:TEST}, complete)
])
.parallel()
compile = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
balUtil.spawn("#{COFFEE} -co #{OUT} #{SRC}", {output:true,cwd:APP}, next)
watch = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
balUtil.spawn("#{COFFEE} -wco #{OUT} #{SRC}", {output:true,cwd:APP}, next)
install = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
(new balUtil.Group(next))
.tasks([
(complete) -> balUtil.npmCommand('install', {output:true,cwd:APP}, complete)
(complete) -> balUtil.npmCommand('install', {output:true,cwd:TEST}, complete)
])
.parallel()
reset = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.cwd ?= APP
balUtil.flow([clean,install,compile], [opts], next)
test = (opts,next) ->
[opts,next] = balUtil.extractOptsAndCallback(opts,next)
opts.debug ?= false
balUtil.nodeCommand("#{if opts.debug then '--debug-brk' else ''} #{TESTER}".trim(), {output:true}, 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
# 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', ->
reset finish
# This file was originally created by Benjamin Lupton <b@lupton.cc> (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}"
DOCPAD = "#{BIN}/docpad#{EXT}"
OUT = "#{APP}/out"
SRC = "#{APP}/src"
TEST = "#{APP}/test"
TESTER = "#{OUT}/test/everything.test.js --joe-reporter=list"
# -----------------
# 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, ['-co', OUT, SRC], {stdio:'inherit',cwd:APP}).on('exit',next)
watch = (opts,next) ->
(next = opts; opts = {}) unless next?
spawn(COFFEE, ['-wco', 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
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
# 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', ->
reset finish
# Node CoffeeScript Makefile
# By Benjamin "balupton" Lupton (MIT Licenced)
# 2012-10-09T23:50:42-07:00
# 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
# -----------------
# 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 npm-debug.log
# Install
install:
npm install
# Reset
reset:
make clean
make install
# Ensure everything is ready for our tests (used by things like travis)
test-prepare:
rm -Rf test/node_modules test/out test/npm-debug.log
make install
make compile
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
# Javascript/CSS Compressor Makefile
# By Benjamin "balupton" Lupton (MIT Licenced)
# 2012-10-09T23:50:42-07:00
MAKEFLAGS = --no-print-directory --always-make
MAKE = make $(MAKEFLAGS)
BUILDDIR = ./.build
CLOSUREURL = http://closure-compiler.googlecode.com/files/compiler-latest.zip
CLOSUREDIR = $(BUILDDIR)/closure
CLOSUREFILE = $(CLOSUREDIR)/compiler.jar
YUIURL = http://yui.zenfs.com/releases/yuicompressor/yuicompressor-2.4.7.zip
YUIDIR = $(BUILDDIR)/yui
YUIFILE = $(YUIDIR)/yuicompressor-2.4.2/build/yuicompressor-2.4.7.jar
all:
$(MAKE) build;
$(MAKE) add;
demo:
open ./demo/index.html
add:
git add .gitignore CHECKLIST.* COPYING.* demo Makefile README.* scripts
push:
git push --all ; git push --tags
pack:
cat \
./scripts/resources/jquery.scrollto.js \
> ./scripts/jquery.scrollto.js
compress:
java -jar $(CLOSUREFILE) --create_source_map ./scripts/closure.map --js_output_file=./scripts/jquery.scrollto.min.js --js=./scripts/jquery.scrollto.js
build:
$(MAKE) pack
$(MAKE) compress
build-update:
$(MAKE) clean
mkdir $(BUILDDIR) $(CLOSUREDIR) $(YUIDIR)
cd $(CLOSUREDIR); wget -q $(CLOSUREURL) -O file.zip; tar -xf file.zip
cd $(YUIDIR); wget -q $(YUIURL) -O file.zip; tar -xf file.zip
clean:
rm -Rf $(BUILDDIR)
Owner

balupton commented Dec 9, 2013

This has now been superceded by http://github.com/bevry/base

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment