Permalink
Browse files

Merge branch 'master' of http://github.com/andrzejsliwa/node-jake int…

…o andrzejsliwa-master
  • Loading branch information...
2 parents c6224c2 + ffd420e commit cab225e49a397a93ec23ee3405ca20e33f421723 @mde mde committed Sep 29, 2010
Showing with 77 additions and 13 deletions.
  1. +49 −1 README.markdown
  2. +28 −12 lib/jake.js
View
@@ -30,7 +30,7 @@ Or, get the code, and `npm link` in the code root.
* Jakefiles are in standard JavaScript syntax
* Tasks with prerequisites
* Namespaces for tasks
- * Async task execution
+ * Async task execution
### Options
@@ -113,6 +113,33 @@ Here's an example:
In this example, the foo:baz task depends on both the default and the foo:bar task.
+
+Use `invoke` to run any task in the middle of running another task. Call it with two arguments:
+
+ invoke(name, args);
+
+Where is `name` is the name of the task (with namespace ex. 'foo:baz'), and `args` is a array of arguments for task.
+
+Here's an example:
+
+ var sys = require('sys');
+
+ desc('This is the default task.');
+ task('default', [], function () {
+ sys.puts('This is the default task.');
+ sys.puts(sys.inspect(arguments));
+ invoke('foo:bar', ['param'])
+ });
+
+ namespace('foo', function () {
+ desc('This the foo:bar task');
+ task('bar', [], function (param) {
+ sys.puts('doing foo:bar task with param: ' + param);
+ sys.puts(sys.inspect(arguments));
+ });
+ });
+
+
### Passing parameters to jake
Two kinds of parameters can be passed to Jake: positional and named parameters.
@@ -150,6 +177,27 @@ And you'd get the following output:
Running `jake` with no arguments runs the default task.
+### Handling also CoffeeScript Jakefile
+
+Here's an example (Jakefile.coffee):
+
+ sys = require('sys')
+
+ desc 'This is the default task.'
+ task 'default', [], (params) ->
+ console.log 'Ths is the default task.'
+ console.log(sys.inspect(arguments))
+ invoke 'new', []
+
+ task 'new', [], ->
+ console.log 'ello from new'
+ invoke 'foo:next', ['param']
+
+ namespace 'foo', ->
+ task 'next', [], (param) ->
+ console.log 'ello from next with param: ' + param
+
+
### Related projects
James Coglan's "Jake": <http://github.com/jcoglan/jake>
View
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/*
- * Node-Jake JavaScript build tool
+ * Node-Jake JavaScript build tool
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,7 +37,7 @@ var usage = ''
+ ' -h, --help Outputs help information\n'
+ ' -V, --version Outputs Node-Jake version\n'
+ '';
-
+
var parseopts = {};
/**
@@ -48,11 +48,11 @@ var parseopts = {};
* [{full: 'foo', abbr: 'f'}, {full: 'bar', abbr: 'b'}]]
*/
parseopts.Parser = function (opts) {
- // Positional commands parse out of the args
+ // Positional commands parse out of the args
this.cmds = [];
// A key/value object of matching options parsed out of the args
this.opts = {};
-
+
// Data structures used for parsing
this.reg = [];
this.shortOpts = {};
@@ -137,7 +137,7 @@ var jake = new function () {
, _taskList = []
// The args passed to the 'jake' invocation, after the task name
, _args;
-
+
// Private functions
// =================
/**
@@ -183,7 +183,7 @@ var jake = new function () {
this.namespaceTasks = {
'default': {}
};
-
+
/**
* Initial function called to run the specified task. Parses all the
* dependencies and then kick off the queue-processing
@@ -209,7 +209,7 @@ var jake = new function () {
};
/**
- * Looks up a function object based on its name or namespace:name
+ * Looks up a function object based on its name or namespace:name
* @param {String} name The name of the task to look up
*/
this.getTask = function (name) {
@@ -223,7 +223,7 @@ var jake = new function () {
nsName = 'default';
taskName = name;
}
-
+
var task = jake.namespaceTasks[nsName][taskName];
if (!task) {
throw new Error('Task "' + name + '" is not defined in the Jakefile.');
@@ -257,7 +257,7 @@ var jake = new function () {
// Run this mofo
task.handler.apply(task, passArgs);
-
+
// Async tasks call this themselves
if (!task.async) {
complete();
@@ -288,7 +288,7 @@ var jake = new function () {
}
}
if (!hasOpts) { opts = null; }
- return {cmds: cmds, opts: opts};
+ return {cmds: cmds, opts: opts};
};
/**
@@ -371,6 +371,12 @@ global.complete = function () {
jake.runNextTask();
};
+global.invoke = function(name, args) {
+ if (!args) {
+ throw new Error('Missing args in invoke of task "' + name + '".');
+ }
+ jake.runTask(name, args);
+};
// ========================
// Run Jake
@@ -402,8 +408,9 @@ var jakefile;
var dirname = opts.directory || process.cwd();
taskName = taskName || 'default';
+
jakefile = opts.jakefile ?
- opts.jakefile.replace(/\.js$/, '') : dirname + '/Jakefile';
+ opts.jakefile.replace(/\.js$/, '').replace(/\.coffee$/, '') : dirname + '/Jakefile';
if (jakefile[0] != '/') {
jakefile = path.join(dirname, jakefile);
}
@@ -416,13 +423,22 @@ if (typeof opts.version != 'undefined') {
jake.die(JAKE_VERSION);
}
-var exists = path.existsSync(jakefile) || path.existsSync(jakefile + '.js');
+var isCoffee = path.existsSync(jakefile + '.coffee');
+var exists = path.existsSync(jakefile) || path.existsSync(jakefile + '.js') || isCoffee;
+
if(!exists) {
jake.die('Could not load Jakefile.\nIf no Jakefile specified with -f or --jakefile, ' +
'jake looks for Jakefile or Jakefile.js in the current directory.');
}
try {
+ if (isCoffee) {
+ try {
+ CoffeeScript = require('coffee-script');
+ } catch (e) {
+ jake.die('CoffeeScript is missing! Try `npm install coffee-script`');
+ }
+ }
var tasks = require(jakefile);
}
catch (e) {

0 comments on commit cab225e

Please sign in to comment.