Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created March 8, 2013 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/5118141 to your computer and use it in GitHub Desktop.
Save joyrexus/5118141 to your computer and use it in GitHub Desktop.
index2README task for simple litcoffee modules
{spawn} = require 'child_process'
fs = require 'fs'
task "build", "watch and build the source", ->
compiler = spawn 'coffee', ['-cw', '.']
compiler.stdout.on 'data', (data) -> console.log data.toString().trim()
compiler.stderr.on 'data', (data) -> console.error data.toString().trim()
# Render your literate source as a GH-highlight-able code-fenced README (a tweak of journo's Cakefile)
task "readme", "render index as README", ->
source = fs.readFileSync('index.coffee.md').toString()
indented = /\n\n ([\s\S]*?)\n\n(?! )/mg
asFenced = (match, code) ->
dedented = code.replace(/^ /mg, '')
"\n```coffeescript\n#{dedented}\n```\n"
fs.writeFileSync 'README.coffee.md', source.replace(indented, asFenced)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment