-
Notifications
You must be signed in to change notification settings - Fork 0
/
Watchfile
80 lines (65 loc) · 2.28 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
require('design.io').extension('watchfile')
async = require('async')
File = require('pathfinder').File
mint = require('mint')
require("design.io-stylesheets") /(app\/client|lib\/stylesheets|vendor\/stylesheets)/
compress: false
debug: false
ignore: /(public|node_modules)/
paths: ["./app/client/stylesheets", "./vendor/stylesheets/bootstrap"]
outputPath: (path) ->
"public/stylesheets/#{path}".replace(/\.(sass|scss|stylus|styl|less|css)/, ".css")
require("design.io-javascripts")
compress: false
debug: false
ignore: /(public|node_modules|server|app\/views|config)/
outputPath: (path) ->
"public/javascripts/#{path}".replace(/\.(js|coffee)/, ".js")
# client config
require("design.io-javascripts") /(config\/locales\/.*|config\/routes|app\/client\/config\/.*)\.(js|coffee)$/
compress: false
debug: false
ignore: /(public|node_modules)/
outputPath: (path) ->
"public/javascripts/#{path}".replace(/\.(js|coffee)/, ".js")
watch /app\/views.*\.coffee$/
update: (path, callback) ->
try
nodes = path.replace("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("app/views")
result = []
for file in files
continue unless file.match(/\.coffee$/)
result.push [file.replace(/\.coffee$/, ""), File.read(file) + "\n\n"]
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()
async.forEachSeries result, iterator, (error) =>
mint.coffee template, bare: true, (error, string) =>
if error
console.log error
return callback(error)
else
File.write "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