Permalink
Browse files

Autorun mode

  • Loading branch information...
1 parent 1514773 commit 064a4c887de7ee2d49632c624b4024c8cd5e0b6d @G3z G3z committed Dec 29, 2012
Showing with 34 additions and 2 deletions.
  1. +16 −0 README.md
  2. +1 −1 src/toaster.coffee
  3. +3 −0 src/toaster/cli.coffee
  4. +14 −1 src/toaster/core/builder.coffee
View
@@ -56,6 +56,7 @@ CoffeeToaster was created initially as a base for creating the
- [Compile](#compile) `-c`
- [Watch](#watch) `-w`
- [Debug](#debug) `-cd`, `-wd`
+ - [Autorun](#autorun) `-a`, `-ad`
- [Representative structure](#representative-structure)
- [HTML inclusion](#html-inclusion)
- [Advanced options](#advanced-options)
@@ -179,6 +180,7 @@ Options:
-w, --watch Start watching/compiling your project
-c, --compile Compile the entire project, without watching it.
-d, --debug Debug mode (compile js files individually)
+ -a, --autorun Execute the script in node.js after compilation
-j, --config Config file formatted as a json-string. [string]
-f, --config-file Path to a different config file. [string]
-v, --version
@@ -303,6 +305,20 @@ directory, so you can debug it sanely.
The debug file `www/js/app-debug.js` is the boot-loader responsible for loading
all these individual compiled JS files into the right order.
+<a name="autorun"/>
+## Autorun
+
+In autorun mode option `-a` the script is recompiled after each file change and
+it is executed in a node.js child process. It is possible to use autorun in
+combination with debug option `-d` to set the script breakpoint on the first line
+
+````bash
+toaster -a
+toaster -ad
+````
+to better debug your application via node.js you can use some tools like
+[node-inspector](https://github.com/dannycoates/node-inspector)
+
<a name="html-inclusion"/>
## HTML inclusion
View
@@ -55,7 +55,7 @@ exports.Toaster = class Toaster
new toaster.misc.InjectNS @toast.builders
# starting watching'n'compiling process
- else if (base = @cli.argv.w || @cli.argv.c)
+ else if (base = @cli.argv.w || @cli.argv.c || @cli.argv.a)
config = if options and options.config then options.config else null
@toast = new toaster.Toast @
@build() unless skip_initial_build
@@ -32,6 +32,9 @@ class Cli
.alias('d', 'debug')
.describe('d', 'Debug mode (compile js files individually)')
+ .alias('a', 'autorun')
+ .describe('a', 'Execute the script in node.js after compilation')
+
.alias('j', 'config')
.string( 'j' )
.describe('j', "Config file formatted as a json-string.")
@@ -8,6 +8,7 @@ class Builder
fsu = require 'fs-util'
path = require 'path'
cs = require "coffee-script"
+ cp = require "child_process"
uglify = require("uglify-js").uglify
uglify_parser = require("uglify-js").parser
@@ -92,7 +93,7 @@ class Builder
log "[#{now}] #{'Compiled'.bold} #{@release}".green
# compiling for debug
- if @cli.argv.d && @debug?
+ if @cli.argv.d && @debug? and not @cli.argv.a
files = @compile_for_debug()
# saving boot loader
@@ -117,6 +118,18 @@ class Builder
# notify user through cli
log "[#{now}] #{'Compiled'.bold} #{@debug}".green
+ # autorun mode
+ if @cli.argv.a
+ if @child?
+ log "Application restarted:".blue
+ @child.kill('SIGHUP')
+ else
+ log "Application started:".blue
+ if @cli.argv.d
+ @child = cp.fork @release, { execArgv: ['--debug-brk'] }
+ else
+ @child = cp.fork @release
+
# Creates a NS holder for all folders
build_namespaces:()->
tree = {}

0 comments on commit 064a4c8

Please sign in to comment.