Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge commit '8ffa9f7348bd1d577922a4f9c464afd319b4925c' from remote-t…

…racking branch 'g3z/master' into dev.

It adds up the `autorun` mode to Toaster.
  • Loading branch information...
commit a63e57031c4631d9072b29c7725778de51b50a81 2 parents 6095e67 + 8ffa9f7
@arboleya authored
View
34 README.md
@@ -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,38 @@ 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 -da
+````
+of if you like the `watch` option
+
+````bash
+toaster -wa
+toaster -wda
+````
+
+to better debug your application via node.js you can use some tools like
+[node-inspector](https://github.com/dannycoates/node-inspector)
+
+It is also possible to pass arguments to the compiled script
+
+````bash
+toaster -wa argument argument2 argument3
+toaster -wda argument argument2 argument3
+````
+
+Please note that the `-a` arguments has to be the last of the group in order to
+make it work: `toaster -ad argument` will not behave as expected and
+`toaster -da argument` should be used instead
+
<a name="html-inclusion"/>
## HTML inclusion
View
35 lib/toaster.js
@@ -630,7 +630,7 @@ var toaster = exports.toaster = {};
usage += " toaster -i [myawsomeapp] (" + 'optional'.green + ")\n";
usage += " toaster -w [myawsomeapp] (" + 'optional'.green + ")\n";
usage += " toaster -wd [myawsomeapp] (" + 'optional'.green + ")";
- this.argv = (this.opts = optimist.usage(usage).alias('n', 'new').describe('n', "Scaffold a very basic new App").alias('i', 'init').describe('i', "Create a config (toaster.coffee) file").alias('w', 'watch').describe('w', "Start watching/compiling your project").alias('c', 'compile').describe('c', "Compile the entire project, without watching it.").alias('d', 'debug').describe('d', 'Debug mode (compile js files individually)').alias('j', 'config').string('j').describe('j', "Config file formatted as a json-string.").alias('f', 'config-file').string('f').describe('f', "Path to a different config file.").alias('v', 'version').describe('v', '').alias('h', 'help').describe('h', '')).argv;
+ this.argv = (this.opts = optimist.usage(usage).alias('n', 'new').describe('n', "Scaffold a very basic new App").alias('i', 'init').describe('i', "Create a config (toaster.coffee) file").alias('w', 'watch').describe('w', "Start watching/compiling your project").alias('c', 'compile').describe('c', "Compile the entire project, without watching it.").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.").alias('f', 'config-file').string('f').describe('f', "Path to a different config file.").alias('v', 'version').describe('v', '').alias('h', 'help').describe('h', '')).argv;
}
return Cli;
@@ -638,7 +638,7 @@ var toaster = exports.toaster = {};
})();
__t('toaster.core').Builder = (function() {
- var ArrayUtil, FnUtil, Script, StringUtil, cs, fs, fsu, missing, path, uglify, uglify_parser, _ref;
+ var ArrayUtil, FnUtil, Script, StringUtil, cp, cs, fs, fsu, missing, path, uglify, uglify_parser, _ref;
fs = require('fs');
@@ -648,6 +648,8 @@ var toaster = exports.toaster = {};
cs = require("coffee-script");
+ cp = require("child_process");
+
uglify = require("uglify-js").uglify;
uglify_parser = require("uglify-js").parser;
@@ -731,7 +733,7 @@ var toaster = exports.toaster = {};
};
Builder.prototype.build = function(header_code, footer_code) {
- var ast, contents, f, files, i, include, namespaces, now, tmpl, vendors, _i, _len;
+ var args, ast, contents, f, files, i, include, namespaces, now, tmpl, vendors, _i, _j, _len, _ref1;
if (header_code == null) {
header_code = "";
}
@@ -764,7 +766,7 @@ var toaster = exports.toaster = {};
fs.writeFileSync(this.release, contents);
now = (("" + (new Date)).match(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}/))[0];
log(("[" + now + "] " + 'Compiled'.bold + " " + this.release).green);
- if (this.cli.argv.d && (this.debug != null)) {
+ if (this.cli.argv.d && (this.debug != null) && !this.cli.argv.a) {
files = this.compile_for_debug();
for (i = _i = 0, _len = files.length; _i < _len; i = ++_i) {
f = files[i];
@@ -791,7 +793,28 @@ var toaster = exports.toaster = {};
}
contents = contents.join('\n');
fs.writeFileSync(this.debug, contents);
- return log(("[" + now + "] " + 'Compiled'.bold + " " + this.debug).green);
+ log(("[" + now + "] " + 'Compiled'.bold + " " + this.debug).green);
+ }
+ if (this.cli.argv.a) {
+ args = [];
+ if (process.argv.length > 3) {
+ for (i = _j = 3, _ref1 = process.argv.length; _j < _ref1; i = _j += 1) {
+ args.push(process.argv[i]);
+ }
+ }
+ if (this.child != null) {
+ log("Application restarted:".blue);
+ this.child.kill('SIGHUP');
+ } else {
+ log("Application started:".blue);
+ }
+ if (this.cli.argv.d) {
+ return this.child = cp.fork(this.release, args, {
+ execArgv: ['--debug-brk']
+ });
+ } else {
+ return this.child = cp.fork(this.release, args);
+ }
}
};
@@ -1326,7 +1349,7 @@ var toaster = exports.toaster = {};
} else if (this.cli.argv.ns) {
this.toast = new toaster.Toast(this);
new toaster.misc.InjectNS(this.toast.builders);
- } else if ((base = this.cli.argv.w || this.cli.argv.c)) {
+ } else if ((base = this.cli.argv.w || this.cli.argv.c || this.cli.argv.a)) {
config = options && options.config ? options.config : null;
this.toast = new toaster.Toast(this);
if (!skip_initial_build) {
View
2  src/toaster.coffee
@@ -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
View
3  src/toaster/cli.coffee
@@ -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.")
View
24 src/toaster/core/builder.coffee
@@ -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,27 @@ class Builder
# notify user through cli
log "[#{now}] #{'Compiled'.bold} #{@debug}".green
+ # autorun mode
+ if @cli.argv.a
+
+ # getting arguments after the third ( first three are ['node', 'path_to_toaster', '-a'] )
+ args = []
+ if process.argv.length > 3
+ for i in [3...process.argv.length] by 1
+ args.push process.argv[i]
+
+ if @child?
+ log "Application restarted:".blue
+ @child.kill('SIGHUP')
+ else
+ log "Application started:".blue
+
+ # adding debug arguments
+ if @cli.argv.d
+ @child = cp.fork @release, args, { execArgv: ['--debug-brk'] }
+ else
+ @child = cp.fork @release, args
+
# Creates a NS holder for all folders
build_namespaces:()->
tree = {}
Please sign in to comment.
Something went wrong with that request. Please try again.