Skip to content

Instantly share code, notes, and snippets.

@edom18
Last active December 14, 2015 13:58
Show Gist options
  • Save edom18/5097021 to your computer and use it in GitHub Desktop.
Save edom18/5097021 to your computer and use it in GitHub Desktop.
普段使ってるCakefile ref: http://qiita.com/items/57ccb570f02799efd9d3
fs = require 'fs'
util = require 'util'
{spawn, exec} = require 'child_process'
option '-o', '--output [DIR]', 'Output directory.'
option '-t', '--target [DIR]', 'Watch target directory.'
stdout_handler = (data) ->
console.log data.toString().trim()
fileCopy = ->
dirname = '_src/coffee'
fs.readdir dirname, (err, filelist) ->
for filename in filelist
if /.*\.coffee$/.test filename
rio = fs.createReadStream "#{dirname}/#{filename}"
wio = fs.createWriteStream "js/#{filename}"
util.pump rio, wio
return
build = (watch, output = 'js', target = '_src/coffee') ->
console.log 'Watching coffee scripts'
console.log "Watch to #{target}"
options = ['-cb', '-o', output, target]
if watch is true
options[0] = '-cbw'
coffee = spawn 'coffee', options
coffee.stdout.on 'data', (data) ->
fileCopy()
stdout_handler data
style = (watch) ->
console.log 'Watching compass files.'
options = ['compile']
if watch is true
options = ['watch']
compass = spawn 'compass', options
compass.stdout.on 'data', (data) -> stdout_handler
compass.stderr.on 'data', (data) -> stdout_handler
task 'build', 'build the project', (watch) ->
build watch
task 'watch', 'watch for changes and rebuild', (options) ->
build true, options.output, options.target
style true
task 'copy', 'copy coffee file.', ->
fileCopy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment