Navigation Menu

Skip to content

Commit

Permalink
Refactor cake tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
hakanensari committed Feb 8, 2012
1 parent f4d113c commit a2eebc3
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions Cakefile
@@ -1,46 +1,49 @@
fs = require 'fs'
{exec} = require 'child_process'

run = (cmd) ->
exec cmd, (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr

publish = (msg, cmd) ->
exec 'git status', (err, stdout) ->
if stdout.match /nothing to commit/
cmds = [
'rm -rf docs',
'node_modules/docco/bin/docco src/**/*.coffee',
cmd,
'ls -1 | grep -v docs | xargs rm -rf',
'mv docs/* .',
'rm -rf docs',
'git add .',
"git commit -m '#{msg}'",
'git push origin gh-pages',
'git checkout master',
'rm -rf docs',
'npm install'
].join(' && ')
exec cmds
else
console.error 'Index is dirty!'

task 'build', 'Build project', ->
run 'rm -rf lib/* && coffee --compile --output lib/ src/'

task 'document', 'generate docs', ->
run 'docco src/**/*.coffee'

task 'pages:init', 'Initialize GitHub Pages', ->
publish 'Create docs',
'git symbolic-ref HEAD refs/heads/gh-pages; rm .git/index'

task 'pages:update', 'Update GitHub Pages', ->
publish 'Update docs',
'git checkout gh-pages'
task 'publish', 'Publish docs to GitHub', ->
exec 'git rm --ignore-unmatch doc && git status', (err, stdout) ->
if !stdout.match /nothing to commit/
publish = (msg, cmd) ->
cmds = [
'rm -rf docs',
'node_modules/docco/bin/docco src/**/*.coffee',
cmd,
'ls -1 | grep -v docs | xargs rm -rf',
'mv docs/* .',
'rm -rf docs',
'git add .',
"git commit -m '#{msg}'",
'git push origin gh-pages',
'git checkout master',
'rm -rf docs',
'npm install'
].join(' && ')
exec cmds

exec 'git branch', (err, stdout, stderr) ->
throw err if err
if stdout.match /gh-pages/
publish 'Update docs',
'git checkout gh-pages'
else
publish 'Create docs',
'git symbolic-ref HEAD refs/heads/gh-pages; rm .git/index'
else
console.error 'Index is dirty!'

task 'publish', 'Publish project', ->
task 'release', 'Release project to npm', ->
run 'npm publish'

task 'test', 'Run specs', ->
Expand Down

0 comments on commit a2eebc3

Please sign in to comment.