From 36d9dd8ef368818afb7a1ba738348a78dcb91d31 Mon Sep 17 00:00:00 2001 From: Ben Nolan Date: Thu, 21 Apr 2011 15:08:26 +1000 Subject: [PATCH] Fixed up capt server to use project#watch. --- src/main.coffee | 37 ++---------------------- src/project.coffee | 9 ++++++ templates/controllers/application.coffee | 5 ++++ templates/controllers/test.coffee | 0 templates/html/index.jst | 8 ++++- 5 files changed, 24 insertions(+), 35 deletions(-) create mode 100644 templates/controllers/application.coffee delete mode 100644 templates/controllers/test.coffee diff --git a/src/main.coffee b/src/main.coffee index 046f9a4..992afa5 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -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") + "" @@ -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) -> @@ -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.") @@ -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" diff --git a/src/project.coffee b/src/project.coffee index 3be7efb..46eb430 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -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 diff --git a/templates/controllers/application.coffee b/templates/controllers/application.coffee new file mode 100644 index 0000000..8ded7e5 --- /dev/null +++ b/templates/controllers/application.coffee @@ -0,0 +1,5 @@ +class Application + constructor: -> + console.log 'App started' + +@Application = Application diff --git a/templates/controllers/test.coffee b/templates/controllers/test.coffee deleted file mode 100644 index e69de29..0000000 diff --git a/templates/html/index.jst b/templates/html/index.jst index a328c57..ea43513 100644 --- a/templates/html/index.jst +++ b/templates/html/index.jst @@ -7,6 +7,12 @@ - Hello! + Hello world. + + \ No newline at end of file