Skip to content

Commit

Permalink
Fixed up capt server to use project#watch.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnolan committed Apr 21, 2011
1 parent f819f2a commit 36d9dd8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
37 changes: 3 additions & 34 deletions src/main.coffee
Expand Up @@ -57,7 +57,6 @@ task = (command, description, func) ->
#
task 'server', 'start a webserver', (arguments) ->
project = new Project(process.cwd())
project.targets = arguments

server.get "/", (req, res, match) ->
ejs = fs.readFileSync("#{project.root}/index.jst") + ""
Expand All @@ -69,6 +68,7 @@ task 'server', 'start a webserver', (arguments) ->

server.get /(.*)/, router.staticDirHandler(project.root, '/')

project.watchAndBuild()
server.listen(3000)

task 'build', 'concatenate and minify all javascript and stylesheets for production', (arguments) ->
Expand Down Expand Up @@ -118,39 +118,7 @@ task 'build', 'concatenate and minify all javascript and stylesheets for product

task 'watch', 'watch files and regenerate test.html and index.html as needed', (arguments) ->
project = new Project(process.cwd())
project.targets = arguments

# timer = null

watch = (source) ->
fs.watchFile Path.join(project.root, source), {persistent: true, interval: 500}, (curr, prev) ->
return if curr.size is prev.size and curr.mtime.getTime() is prev.mtime.getTime()
project.compileFile(source)

for source in project.getWatchables()
watch(source)
project.compileFile(source)

# doRebuild = ->
# sys.puts "Rebuilt project..."
#
# ejs = fs.readFileSync("#{project.root}/index.jst") + ""
# fs.writeFileSync("#{project.root}/index.html", _.template(ejs, { project : project }))
#
# ejs = fs.readFileSync("#{project.root}/spec/index.jst") + ""
# fs.writeFileSync("#{project.root}/spec/index.html", _.template(ejs, { project : project }))
#
# rebuild = ->
# if timer
# clearTimeout timer
#
# timer = setTimeout(doRebuild, 25)
#
# for script in project.getFilesToWatch()
# fs.watchFile Path.join(project.root, script), ->
# rebuild()
#
# rebuild()
project.watchAndBuild()

task 'new', 'create a new project', (arguments) ->
project = arguments[0] or raise("Must supply a name for new project.")
Expand All @@ -169,6 +137,7 @@ task 'new', 'create a new project', (arguments) ->
"lib/underscore.js" : "lib/underscore.js"
"lib/backbone.js" : "lib/backbone.js"
"lib/less.js" : "lib/less.js"
"app/controllers/application.coffee" : "controllers/application.coffee"
"spec/jasmine/jasmine-html.js" : "lib/jasmine-html.js"
"spec/jasmine/jasmine.css" : "lib/jasmine.css"
"spec/jasmine/jasmine.js" : "lib/jasmine.js"
Expand Down
9 changes: 9 additions & 0 deletions src/project.coffee
Expand Up @@ -216,5 +216,14 @@ class Project
sys.puts " * Compiled " + outpath
fs.writeFileSync Path.join(@root, outpath), output

watchAndBuild: ->
watch = (source) =>
fs.watchFile Path.join(@root, source), {persistent: true, interval: 500}, (curr, prev) =>
return if curr.size is prev.size and curr.mtime.getTime() is prev.mtime.getTime()
@compileFile(source)

for source in @getWatchables()
watch(source)
@compileFile(source)

exports.Project = Project
5 changes: 5 additions & 0 deletions templates/controllers/application.coffee
@@ -0,0 +1,5 @@
class Application
constructor: ->
console.log 'App started'

@Application = Application
Empty file removed templates/controllers/test.coffee
Empty file.
8 changes: 7 additions & 1 deletion templates/html/index.jst
Expand Up @@ -7,6 +7,12 @@
</head>

<body>
Hello!
Hello world.

<script>
$(document).ready(function(){
window.app = new Application;
});
</script>
</body>
</html>

0 comments on commit 36d9dd8

Please sign in to comment.