WIP: Use rake to start compiling resources (like require.coffee)

This commit is contained in:
Nathan Sobo
2012-08-26 16:29:46 -05:00
parent 72468b7028
commit c3e748a17c
128 changed files with 35213 additions and 7 deletions

50
src/app/file.coffee Normal file
View File

@@ -0,0 +1,50 @@
EventEmitter = require 'event-emitter'
fs = require 'fs'
_ = require 'underscore'
module.exports =
class File
path: null
md5: null
constructor: (@path) ->
throw "Creating file with path that is not a file: #{@path}" unless fs.isFile(@path)
@updateMd5()
setPath: (@path) ->
getPath: ->
@path
getBaseName: ->
fs.base(@path)
updateMd5: ->
@md5 = fs.md5ForPath(@path)
afterSubscribe: ->
@subscribeToNativeChangeEvents() if @subscriptionCount() == 1
afterUnsubscribe: ->
@unsubscribeFromNativeChangeEvents() if @subscriptionCount() == 0
subscribeToNativeChangeEvents: ->
@watchId = $native.watchPath @path, (eventType, path) =>
if eventType is "remove"
@trigger "remove"
@off()
else if eventType is "move"
@setPath(path)
@trigger "move"
else if eventType is "contents-change"
newMd5 = fs.md5ForPath(@getPath())
return if newMd5 == @md5
@md5 = newMd5
@trigger 'contents-change'
unsubscribeFromNativeChangeEvents: ->
$native.unwatchPath(@path, @watchId)
_.extend File.prototype, EventEmitter