mde/jake — pull request #181 by xiejw (2013-04-02 15:17:15+00:00)
Title: New Feature of Suffix/Pattern Rules

Hi, I have finished the code for Suffix Pattern Rules. The test cases can be found at `test/rule.js`.

As a brief summary, the code supports the following scenarios:

desc('This is a rule, which does not support namespace or pattern.');
rule('.o', '.c', function (obj, src) {
var cmd = util.format('gcc -o %s %s', obj, src);
jake.exec([cmd], function () {
complete();
}, {printStdout: true});
}, { async : true });

desc('This rule has prerequisites.');
rule('.o', '.c', ['util.h'], function (obj, src) {
var cmd = util.format('gcc -o %s %s', obj, src);
jake.exec([cmd], function () {
complete();
}, {printStdout: true});
}, { async : true });

desc('This is a rule with patterns.');
rule('%.o', '%.c', function (obj, src) {
var cmd = util.format('gcc -o %s %s', obj, src);
jake.exec([cmd], function () {
complete();
}, {printStdout: true});
}, { async : true });

desc('This is another rule with patterns.');
rule('obj/%.o', 'src/%.c', function (obj, src) {
var cmd = util.format('gcc -o %s %s', obj, src);
jake.exec([cmd], function () {
complete();
}, {printStdout: true});
}, { async : true });

desc('This is an example with chain rules.');

rule('%.pdf', '%.dvi', function (obj, src) {
var cmd = util.format('dvipdfm %s',src);
jake.exec([cmd], function () {
complete();
}, {printStdout: true});
}, { async : true });

rule('%.dvi', '%.tex', function (obj, src) {
var cmd = util.format('latex %s',src);
jake.exec([cmd], function () {
complete();
}, {printStdout: true});
}, { async : true });

desc('This rule has a namespace.');
task('default', ['debug:obj/main.o]);

namespace('debug', function() {
rule('obj/%.o', 'src/%.c', function (obj, src) {
// This will create a file task depending on 'debug:src/main.c' task.
// ...
}, { async : true });