Browse files

Smarted Cakefile.

  • Loading branch information...
1 parent 2f9b7ee commit cf1f7347516e5215bd5657e8642e575d23819130 @assaf assaf committed Dec 21, 2010
Showing with 57 additions and 34 deletions.
  1. +57 −34 Cakefile
View
91 Cakefile
@@ -14,7 +14,7 @@ log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
task "clean", "Remove temporary files and such", ->
- exec "rm -rf html"
+ exec "rm -rf html clean"
# Setup
@@ -43,60 +43,83 @@ toHTML = (source, callback)->
title = path.basename(source, ".md").replace("_", " ")
fs.mkdir "html", 0777, ->
fs.readFile "doc/_layout.html", "utf8", (err, layout)->
+ return callback(err) if err
fs.readFile source, "utf8", (err, text)->
- throw err if err
+ return callback(err) if err
log "Creating #{target} ...", green
exec "ronn --html #{source}", (err, stdout, stderr)->
- throw err if err
+ return callback(err) if err
title = stdout.match(/<h1>(.*)<\/h1>/)[1]
html = layout.replace("{{body}}", stdout).replace(/{{title}}/g, title).replace(/<h1>.*<\/h1>/, "")
- fs.writeFile target, html, "utf8"
- callback target if callback
-
-task "doc:source", ->
+ fs.writeFile target, html, "utf8", (err)->
+ callback err, target
+
+documentPages = (callback)->
+ toHTML "README.md", (err)->
+ return callback(err) if err
+ exec "mv html/readme.html html/index.html", (err)->
+ return callback(err) if err
+ toHTML "TODO.md", (err)->
+ return callback(err) if err
+ exec "cp -f doc/*.css html/", (err)->
+ callback err
+
+documentSource = (callback)->
log "Documenting source files ...", green
- exec "docco lib/**/*.coffee", (err) ->
- throw err if err
+ exec "docco lib/**/*.coffee", (err)->
+ return callback(err) if err
log "Copying to html/source ...", green
- exec "mkdir -p html && cp -rf docs/ html/source && rm -rf docs"
-
-task "doc:pages", ->
- toHTML "README.md", ->
- exec "mv html/readme.html html/index.html"
- "index.html"
- toHTML "TODO.md"
- exec "cp -f doc/*.css html/"
+ exec "mkdir -p html && cp -rf docs/ html/source && rm -rf docs", (err)->
+ callback err
-task "doc", "Generate documentation", ->
- invoke "doc:pages"
- invoke "doc:source"
+generateDocs = (callback)->
+ log "Generating documentation ...", green
+ documentPages (err)->
+ return callback(err) if err
+ documentSource (err)->
+ callback err
+task "doc:pages", -> documentPages (err)-> throw err if err
+task "doc:source", -> documentSource (err)-> throw err if err
+task "doc", "Generate documentation", -> generateDocs (err)-> throw err if err
# Testing
# -------
-task "test", "Run all tests", ->
+runTests = (callback)->
+ log "Running test suite ...", green
exec "vows --spec", (err, stdout, stderr)->
log stdout, green
log stderr, red
+ callback err
+task "test", "Run all tests", -> runTests (err)-> throw err if err
# Publishing
# ----------
-task "doc:publish", ->
- log "Uploading documentation ...", green
- exec "rsync -cr --del --progress html/ labnotes.org:/var/www/zombie/"
+publishDocs = (callback)->
+ log "Publishing documentation ...", green
+ generateDocs (err)->
+ return callback(err) if err
+ log "Uploading documentation ...", green
+ exec "rsync -cr --del --progress html/ labnotes.org:/var/www/zombie/", callback
+task "doc:publish", -> publishDocs (err)-> throw err if err
task "publish", "Publish new version (Git, NPM, site)", ->
- fs.readFile "package.json", "utf8", (err, package)->
- version = JSON.parse(package).version
- log "Tagging v#{version} ...", green
- exec "git tag v#{version}", ->
- exec "git push"
-
- log "Publishing in NPM ...", green
- invoke "clean" # Need to rid of all the crap, or it gets included
- invoke "npm publish"
+ runTests (err)->
+ throw err if err
+ fs.readFile "package.json", "utf8", (err, package)->
+ version = JSON.parse(package).version
+ log "Tagging v#{version} ...", green
+ exec "git tag v#{version}", ->
+ exec "git push"
+
+ log "Publishing to NPM ...", green
+ exec "rm -rf clean && git checkout-index -a -f --prefix clean/", (err)->
+ throw err if err
+ exec "npm publish clean", (err)->
+ throw err if err
- invoke "doc:publish"
+ # Publish documentation
+ publishDocs (err)-> throw err if err

0 comments on commit cf1f734

Please sign in to comment.