Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add flag to watch for coffeescript changes

  • Loading branch information...
commit bfe254f79ef6fed5fd1d29f8e18b74ee516393fb 1 parent 82b6ac1
@ryanwilliams authored
Showing with 32 additions and 2 deletions.
  1. +22 −1 lib/cocos2d/commands/server.js
  2. +10 −1 skeletons/cocos2d-coffee/Cakefile
View
23 lib/cocos2d/commands/server.js
@@ -8,6 +8,7 @@ var sys = require('util')
, logger = jah.logger
, mimetypes = jah.mimetypes
, Template = jah.Template
+ , child_process = require('child_process')
var options = [
{ short: 'u',
@@ -28,7 +29,12 @@ var options = [
{ short: 'p',
long: 'port',
description: 'Port to listen on. Default is 4000',
- value: true }
+ value: true },
+
+ { short: 'w',
+ long: 'watch',
+ description: 'Watch src.coffee for changes',
+ value: false }
];
exports.description = 'Run the Cocos2D JavaScript development web server';
@@ -39,8 +45,23 @@ exports.run = function () {
config = opts.get('config') || 'jah.json',
server = new Server(config)
+ if (opts.get('watch')) {
+ exports.watchForCoffeeScript()
+ }
+
server.start(host, port)
};
+exports.watchForCoffeeScript = function (src, dest) {
+ src = src || 'src.coffee'
+ dest = dest || 'src'
+ var coffee = child_process.spawn('coffee', ['-w', '-c', '-o', dest, src])
+ coffee.stderr.on('data', function (data) {
+ process.stderr.write(data.toString())
+ })
+ coffee.stdout.on('data', function (data) {
+ sys.print(data.toString())
+ })
+}
function Server () {
jah.Server.apply(this, arguments)
View
11 skeletons/cocos2d-coffee/Cakefile
@@ -1,5 +1,14 @@
-{exec} = require 'child_process'
+{print} = require 'sys'
+{exec, spawn} = require 'child_process'
+
task 'build', 'Build project from src.coffee/*.coffee to src/*.js', ->
exec 'coffee --compile --output src/ src.coffee/', (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
+
+task 'watch', 'Watch src.coffee/ for changes', ->
+ coffee = spawn 'coffee', ['-w', '-c', '-o', 'src', 'src.coffee']
+ coffee.stderr.on 'data', (data) ->
+ process.stderr.write data.toString()
+ coffee.stdout.on 'data', (data) ->
+ print data.toString()
Please sign in to comment.
Something went wrong with that request. Please try again.