Skip to content

Instantly share code, notes, and snippets.

@mcfog
Created December 25, 2011 08:24
Show Gist options
  • Save mcfog/1518882 to your computer and use it in GitHub Desktop.
Save mcfog/1518882 to your computer and use it in GitHub Desktop.
coco cokefile(copy . to build and compiling all .co
{spawn} = require \child_process
SHELL = if(\win32 == process.platform) then "cmd /c " else "sh -c "
output = (error, stdout, stderr)->
if (error)
console.error stderr.trim!
else
console.log stdout.trim!
void
StreamReader = class
(stream, encoding = \ascii, cb)->
buffer = ''
consumeLine = ->
lines = buffer.split \\n
while lines.length>1
cb lines.shift!
stream.setEncoding encoding
(data) <- stream.on \data
buffer := buffer + data
consumeLine!
void
run = (cmd, con, ..., after)->
if(con === after)
con = console
con?.log? \> + cmd
[cmd,...args] = (SHELL+cmd).split(' ')
p = spawn cmd, args
#console.log p.pid,cmd,args
new StreamReader p.stdout, \ascii, (line)->
con?.log? line
new StreamReader p.stderr, \ascii, (line)->
con?.error? line
p.on 'exit', ->
after?!
p.stdin.end!
task \build, 'build' , (options)->
<- run "rm -r build"
#<- run "npm install"
<- run "cp -r . build"
fs = require \fs
path = require \path
walk = (d)->
for file of fs.readdirSync d
lpath = path.join d,file
stat = fs.statSync lpath
if stat.isDirectory! && file != 'build'
walk(d + \/ + file)
if stat.isFile! && /\.co$/.test file
try
fs.mkdirSync 'build/'+d
#<- run (["coco -c -o ", fs.realpathSync('build/'+d),' ', d, '/', file].join '')
<- run (["coco -c ", lpath, "&rm ", lpath].join '')
<- run 'rm -r ./build/Cokefile ./build/.gitignore ./build/.git'
walk './build'
console.log \done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment