From a2eebc3488ec069cd8c97daaa091e0e1adc7816e Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Wed, 8 Feb 2012 17:07:19 +0000 Subject: [PATCH] Refactor cake tasks --- Cakefile | 61 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/Cakefile b/Cakefile index 52225e1..7b59879 100644 --- a/Cakefile +++ b/Cakefile @@ -1,3 +1,4 @@ +fs = require 'fs' {exec} = require 'child_process' run = (cmd) -> @@ -5,42 +6,44 @@ run = (cmd) -> 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', ->