Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switched to using Makefile

  • Loading branch information...
commit 2e56750f41cd6b9b0936f6d1c9d359fb1bab8976 1 parent 2a719ae
@assaf authored
View
234 Cakefile
@@ -1,234 +0,0 @@
-File = require("fs")
-Path = require("path")
-HLJS = require("highlight/lib/vendor/highlight.js/highlight").hljs
-{spawn, exec} = require("child_process")
-stdout = process.stdout
-
-# Use executables installed with npm bundle.
-process.env["PATH"] = "node_modules/.bin:#{process.env["PATH"]}"
-
-# ANSI Terminal Colors.
-bold = "\033[0;1m"
-red = "\033[0;31m"
-green = "\033[0;32m"
-reset = "\033[0m"
-
-# Log a message with a color.
-log = (message, color, explanation) ->
- console.log color + message + reset + ' ' + (explanation or '')
-
-# Handle error and kill the process.
-onerror = (err)->
- if err
- process.stdout.write "#{red}#{err.stack}#{reset}\n"
- process.exit -1
-
-
-## Setup ##
-
-# Setup development dependencies, not part of runtime dependencies.
-task "setup", "Install development dependencies", ->
- File.readFile "package.json", "utf8", (err, package)->
- install = (dependencies, callback)->
- if dep = dependencies.shift()
- [name, version] = dep
- log "Installing #{name} #{version}", green
- exec "npm install \"#{name}@#{version}\"", (err)->
- if err
- onerror err
- else
- install dependencies, callback
- else if callback
- callback()
-
- json = JSON.parse(package)
- log "Need runtime dependencies, installing into node_modules ...", green
- dependencies = []
- dependencies.push [name, version] for name, version of json.dependencies
- install dependencies, ->
- log "Need development dependencies, installing ...", green
- dependencies = []
- dependencies.push [name, version] for name, version of json.devDependencies
- install dependencies
-
-task "install", "Install Zombie in your local repository", ->
- generateMan (err)->
- onerror err
- log "Installing Zombie ...", green
- exec "npm install", (err, stdout, stderr)->
- process.stdout.write stderr
- onerror err
-
-
-clean = (callback)->
- exec "rm -rf build html man7", callback
-task "clean", "Remove temporary files and such", -> clean onerror
-
-
-## Testing ##
-
-runTests = (callback)->
- log "Running test suite ...", green
- exec "vows --spec spec/*_spec.coffee", (err, stdout, stderr)->
- process.stdout.write stdout
- process.stderr.write stderr
- callback err if callback
-task "test", "Run all tests", ->
- runTests (err)->
- process.stdout.on "drain", -> process.exit -1 if err
-
-
-## Documentation ##
-
-# HLJS can't guess the language (JavaScript) consistently, so we're going to help by limiting its choice of languages to
-# JavaScript and XML (good pick for one of the dumps).
-require("highlight/lib/vendor/highlight.js/languages/xml")(HLJS)
-require("highlight/lib/vendor/highlight.js/languages/javascript")(HLJS)
-
-# Syntax highlighting
-highlight = (html)->
- unescape = (html)->
- return html.replace(/&quot;/g, "\"").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")
- return html.replace(/<code>([\s\S]*?)<\/code>/gm, (_, source)-> "<code>#{HLJS.highlightText(unescape(source).replace(/\uffff/g,"\n"))}</code>")
-
-# Markdown to HTML.
-toHTML = (source, callback)->
- target = "html/#{Path.basename(source, ".md").toLowerCase()}.html"
- File.readFile "doc/layout/main.html", "utf8", (err, layout)->
- onerror err
- File.readFile source, "utf8", (err, text)->
- onerror err
- log "Creating #{target}", green
- exec "ronn --html #{source}", (err, stdout, stderr)->
- onerror err
- [name, title] = stdout.match(/<h1>(.*)<\/h1>/)[1].split(" -- ")
- name = name.replace(/\(\d\)/, "")
- body = stdout.replace(/<h1>.*<\/h1>/, "")
- html = layout.replace("{{body}}", body).replace(/{{title}}/g, title)
- html = highlight(html)
- File.writeFile target, html, "utf8", (err)->
- callback err, target
-
-documentPages = (callback)->
- files = File.readdirSync(".").filter((file)-> Path.extname(file) == ".md").
- concat(File.readdirSync("doc").filter((file)-> Path.extname(file) == ".md").map((file)-> "doc/#{file}"))
- File.mkdir "html", 0777, ->
- convert = ->
- if file = files.pop()
- toHTML file, (err)->
- onerror err
- convert()
- else
- process.stdout.write "\n"
- File.readFile "html/readme.html", "utf8", (err, html)->
- html = html.replace(/<h1>(.*)<\/h1>/, "<h1>Zombie.js</h1><b>$1</b>")
- File.writeFile "html/index.html", html, "utf8", onerror
- File.unlink "html/readme.html", onerror
- exec "cp -fr doc/css doc/images html/", callback
- convert()
-
-documentSource = (callback)->
- log "Documenting source files ...", green
- exec "docco lib/**/*.coffee", (err, stdout, stderr)->
- log stdout, green
- onerror err
- log "Copying to html/source", green
- exec "mkdir -p html && cp -rf docs/ html/source && rm -rf docs", callback
-
-generateMan = (callback)->
- files = File.readdirSync(".").filter((file)-> Path.extname(file) == ".md").
- concat(File.readdirSync("doc").filter((file)-> Path.extname(file) == ".md").map((file)-> "doc/#{file}"))
- File.mkdir "man7", 0777, (err)->
- log "Generating man file ...", green
- convert = ->
- if file = files.pop()
- target = "man7/#{Path.basename(file, ".md").toLowerCase()}.7"
- exec "ronn --roff #{file}", (err, stdout, stderr)->
- onerror err
- log "Creating #{target}", green
- File.writeFile target, stdout, "utf8", onerror
- convert()
- else
- exec "mv man7/readme.7 man7/zombie.7", onerror
- process.stdout.write "\n"
- callback()
- convert()
-
-generatePDF = (callback)->
- log "Generating PDF documentation ...", green
- files = "index api selectors troubleshoot".split(" ").map((f)-> "html/#{f}.html")
- options = "--disable-javascript --outline --print-media-type --title Zombie.js --header-html doc/layout/header.html --allow doc/images"
- margins = "--margin-left 30 --margin-right 30 --margin-top 30 --margin-bottom 30 --header-spacing 5"
- outline = " --outline --outline-depth 2"
- toc = "toc --disable-dotted-lines"
- cover = "cover doc/layout/cover.html"
- exec "wkhtmltopdf #{options} #{margins} #{cover} #{toc} #{files.join(" ")} html/zombie.pdf", callback
-
-generateDocs = (callback)->
- log "Generating documentation ...", green
- documentPages (err)->
- onerror err
- documentSource (err)->
- onerror err
- generatePDF (err)->
- onerror err
- generateMan callback
-
-task "doc:pages", "Generate documentation for main pages", -> documentPages onerror
-task "doc:source", "Generate documentation from source files", -> documentSource onerror
-task "doc:man", "Generate man pages", -> generateMan onerror
-task "doc:pdf", "Generate PDF documentation", ->
- documentPages (err)->
- onerror err
- generatePDF onerror
-task "doc", "Generate all documentation", -> generateDocs onerror
-
-
-## Publishing ##
-
-publishDocs = (callback)->
- log "Uploading documentation ...", green
- exec "rsync -chr --del --stats html/ labnotes.org:/var/www/zombie/", (err, stdout, stderr)->
- log stdout, green
- callback err
-task "doc:publish", "Publish documentation to site", ->
- documentPages (err)->
- onerror err
- documentSource (err)->
- onerror err
- generatePDF (err)->
- onerror err
- publishDocs onerror
-
-task "publish", "Publish new version (Git, NPM, site)", ->
- # Run tests, don't publish unless tests pass.
- runTests (err)->
- onerror err
- # Clean up temporary files and such, want to create everything from
- # scratch, don't want generated files we no longer use, etc.
- clean (err)->
- onerror err
- exec "git push", (err)->
- onerror err
- File.readFile "package.json", "utf8", (err, package)->
- package = JSON.parse(package)
-
- # Publish documentation, need these first to generate man pages,
- # inclusion on NPM package.
- generateDocs (err)->
- onerror err
-
- log "Publishing to NPM ...", green
- exec "npm publish", (err, stdout, stderr)->
- log stdout, green
- onerror err
-
- # Create a tag for this version and push changes to Github.
- log "Tagging v#{package.version} ...", green
- exec "git tag v#{package.version}", (err, stdout, stderr)->
- log stdout, green
- exec "git push --tags origin master", (err, stdout, stderr)->
- log stdout, green
-
- # We can do this in parallel.
- publishDocs onerror
View
76 Makefile
@@ -0,0 +1,76 @@
+test :
+ vows --spec spec/*_spec.coffee
+
+
+# Documentation consists of Markdown files converted to HTML, CSS/images copied over, annotated source code and PDF.
+doc : html html/source html/zombie.pdf
+
+html/index.html : README.md doc/layout/main.html
+ mkdir -p html
+ coffee doc/render.coffee $< $@
+
+html/changelog.html : CHANGELOG.md doc/layout/main.html
+ mkdir -p html
+ coffee doc/render.coffee $< $@
+
+html/%.html : doc/%.md doc/layout/main.html
+ mkdir -p html
+ coffee doc/render.coffee $< $@
+
+html : $(foreach file,$(wildcard doc/*.md),html/$(notdir $(basename $(file))).html) html/index.html html/changelog.html
+ mkdir -p html
+ cp -fr doc/css doc/images html/
+
+html/source : lib/**/*.coffee
+ @echo "Documenting source files ..."
+ docco lib/**/*.coffee
+ mkdir -p html
+ mv docs html/source
+
+html/zombie.pdf : html/*.html
+ @echo "Generating PDF documentation ..."
+ wkhtmltopdf \
+ --disable-javascript --outline --print-media-type --title Zombie.js --header-html doc/layout/header.html --allow doc/images \
+ --margin-left 30 --margin-right 30 --margin-top 30 --margin-bottom 30 --header-spacing 5 \
+ cover doc/layout/cover.html toc --disable-dotted-lines \
+ html/index.html html/api.html html/selectors.html html/troubleshoot.html \
+ html/zombie.pdf
+
+
+# Man pages.
+man7 : $(foreach file,$(wildcard doc/*.md),man7/zombie-$(notdir $(basename $(file))).7) man7/zombie.7 man7/zombie-changelog.7
+ mkdir -p man7
+
+man7/zombie.7 : README.md
+ mkdir -p man7
+ ronn --roff $< > $@
+
+man7/zombie-changelog.7 : README.md
+ mkdir -p man7
+ ronn --roff $< > $@
+
+man7/zombie-%.7 : doc/%.md
+ mkdir -p man7
+ ronn --roff $< > $@
+
+
+# Clean up temporary directories
+clean :
+ rm -rf html man7
+
+
+# Get version number from package.json, need this for tagging.
+version = $(shell node -e "console.log(JSON.parse(require('fs').readFileSync('package.json')).version)")
+
+# Publish site only.
+publish-docs : html html/source html/zombie.pdf
+ @echo "Uploading documentation ..."
+ rsync -chr --del --stats html/ labnotes.org:/var/www/zombie/
+
+# npm publish, public-docs and tag
+publish : test man7 publish-docs
+ git push
+ npm publish
+ git tag v$(version)
+ git push --tags origin master
+
View
2  doc/guts.md
@@ -22,7 +22,7 @@ can "install" your working directory using `npm link`.
To generate the documentation:
- $ cake doc:pages
+ $ make doc
$ open html/index.html
View
2  doc/layout/main.html
@@ -13,7 +13,7 @@
<div id="sidebar">
<ul class="navigation">
<li><a href="/">Getting Started</a></li>
- <li><a href="api.html">The API</a></li>
+ <li><a href="API.html">The API</a></li>
<li><a href="selectors.html">CSS Selectors</a></li>
<li><a href="troubleshoot.html">Troubleshooting</a></li>
<li><a href="guts.html">The Guts</a></li>
View
30 doc/render.coffee
@@ -0,0 +1,30 @@
+File = require("fs")
+{ exec} = require("child_process")
+HLJS = require("highlight/lib/vendor/highlight.js/highlight").hljs
+
+
+# HLJS can't guess the language (JavaScript) consistently, so we're going to help by limiting its choice of languages to
+# JavaScript and XML (good pick for one of the dumps).
+require("highlight/lib/vendor/highlight.js/languages/xml")(HLJS)
+require("highlight/lib/vendor/highlight.js/languages/javascript")(HLJS)
+
+# Syntax highlighting
+highlight = (html)->
+ unescape = (html)->
+ return html.replace(/&quot;/g, "\"").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")
+ return html.replace(/<code>([\s\S]*?)<\/code>/gm, (_, source)-> "<code>#{HLJS.highlightText(unescape(source).replace(/\uffff/g,"\n"))}</code>")
+
+# Markdown to HTML.
+exec "ronn --html #{process.argv[2]}", (error, stdout, stderr)->
+ throw error if error
+ File.readFile "doc/layout/main.html", "utf8", (error, layout)->
+ throw error if error
+
+ [name, title] = stdout.match(/<h1>(.*)<\/h1>/)[1].split(" -- ")
+ name = name.replace(/\(\d\)/, "")
+ body = stdout.replace(/<h1>.*<\/h1>/, "")
+ html = layout.replace("{{body}}", body).replace(/{{title}}/g, title)
+ html = highlight(html)
+ File.writeFile process.argv[3], html, "utf8", (error)->
+ throw error if error
+ process.exit(0)
Please sign in to comment.
Something went wrong with that request. Please try again.