forked from tower-archive/tower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Watchfile
89 lines (73 loc) · 2.59 KB
/
Watchfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
File = require('pathfinder').File
require('design.io').extension('watchfile')
async = require('async')
File = require('pathfinder').File
mint = require('mint')
require("design.io-javascripts")
compress: false
debug: false
ignore: /(lib\/|public|node_modules|server\.js|spec|test|dist)/
#outputPath: (path) ->
# "spec/tmp/test.css"
write: (path, string) ->
path = path.replace(/^(src)/, "lib").replace(/\.(js|coffee)/, ".js")
#growl.notify("updated #{path}", { title: 'Stylesheets' })
try
File.write path, string, (error) ->
console.log(error.stack) if error
catch error
console.log error.stack
require("design.io-javascripts") /test\/example\/.*\.coffee$/
compress: false
debug: false
ignore: /(public|node_modules|view)/
outputPath: (path) ->
path = path.replace("test/example/", "")
"test/example/public/javascripts/#{path}".replace(/\.(js|coffee)/, ".js")
require("design.io-javascripts") /test\/cases\/.*\.coffee$/
ignore: /(public|node_modules|server)/
compress: false
debug: false
outputPath: (path) ->
"test/example/public/javascripts/#{path}".replace(/\.(js|coffee)/, ".js")
watch /test\/example\/app\/views.*\.coffee$/
update: (path, callback) ->
try
nodes = path.replace("test/example/app/views/", "").split("/")
name = {}
data = File.read(path)
id = nodes.join("/")
selector = id
name = ""
@broadcast body: data, id: id, selector: selector, path: "/#{name}"
files = File.files("test/example/app/views")
result = []
for file in files
continue unless file.match(/\.coffee$/)
result.push [file.replace("test/example/", ""), File.read(file)]
template = "Tower.View.cache =\n"
iterator = (item, next) =>
template += " '#{item[0]}': ->\n"
lines = item[1].split(/\n/)
for line, i in lines
lines[i] = " #{line}"
template += lines.join("\n")
template += "\n"
next()
require('async').forEachSeries result, iterator, (error) =>
mint.coffee template, bare: true, (error, string) =>
if error
console.log error
return callback(error)
else
File.write "test/example/public/javascripts/app/views/templates.js", string
callback()
catch error
callback(error)
client:
update: (data) ->
Tower.View.cache[data.id] = data
if data.reload
window.location = data.path
else
Tower.get data.path