| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- var exec = require('child_process').exec
- , fs = require('fs')
- , util = require('util')
- , utils = require('utilities');
- task('default', ['tmp']);
- directory('tmpsrc');
- directory('tmpbin');
- ////////////////////////////////////////////////////////////
- // Simple Suffix Rule
- file('tmp', ['tmp_init', 'tmp_dep1.o', 'tmp_dep2.o'], function (params) {
- console.log('tmp task');
- var data1 = fs.readFileSync('tmp_dep1.o');
- var data2 = fs.readFileSync('tmp_dep2.o');
- fs.writeFileSync('tmp', data1 + data2);
- });
- rule('.o', '.c', function() {
- var cmd = util.format('cp %s %s', this.source, this.name);
- console.log(cmd + ' task');
- jake.exec([cmd], function () {
- complete();
- });
- }, { async : true });
- file('tmp_dep1.c', function () {
- fs.writeFile('tmp_dep1.c', 'src_1', function (err) {
- if (err) {
- throw err;
- }
- console.log('tmp_dep1.c task');
- complete();
- });
- }, {async: true});
- // note that tmp_dep2.o depends on tmp_dep2.c, which is a
- // static file.
- task('tmp_init', function () {
- fs.writeFile('tmp_dep2.c', 'src_2', function (err) {
- if (err) {
- throw err;
- }
- console.log('tmp_dep2.c task');
- complete();
- });
- }, {async: true});
- ////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////
- // Pattern Rule
- file('tmp_p', ['tmp_init', 'tmp_dep1.oo', 'tmp_dep2.oo'], function (params) {
- console.log('tmp pattern task');
- var data1 = fs.readFileSync('tmp_dep1.oo');
- var data2 = fs.readFileSync('tmp_dep2.oo');
- fs.writeFileSync('tmp_p', data1 + data2 + ' pattern');
- });
- rule('%.oo', '%.c', function() {
- var cmd = util.format('cp %s %s', this.source, this.name);
- console.log(cmd + ' task');
- jake.exec([cmd], function () {
- complete();
- });
- }, { async : true });
- ////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////
- // Pattern Rule with Folder
- // i.e. rule('tmpbin/%.oo', 'tmpsrc/%.c', ...
- file('tmp_pf', [
- 'tmp_src_init'
- , 'tmpbin'
- , 'tmpbin/tmp_dep1.oo'
- , 'tmpbin/tmp_dep2.oo' ], function (params) {
- console.log('tmp pattern folder task');
- var data1 = fs.readFileSync('tmpbin/tmp_dep1.oo');
- var data2 = fs.readFileSync('tmpbin/tmp_dep2.oo');
- fs.writeFileSync('tmp_pf', data1 + data2 + ' pattern folder');
- });
- rule('tmpbin/%.oo', 'tmpsrc/%.c', function() {
- var cmd = util.format('cp %s %s', this.source, this.name);
- console.log(cmd + ' task');
- jake.exec([cmd], function () {
- complete();
- });
- }, { async : true });
- file('tmpsrc/tmp_dep2.c',['tmpsrc'], function () {
- fs.writeFile('tmpsrc/tmp_dep2.c', 'src/src_2', function (err) {
- if (err) {
- throw err;
- }
- console.log('tmpsrc/tmp_dep2.c task');
- complete();
- });
- }, {async: true});
- // Create static files in folder tmpsrc.
- task('tmp_src_init', ['tmpsrc'], function () {
- fs.writeFile('tmpsrc/tmp_dep1.c', 'src/src_1', function (err) {
- if (err) {
- throw err;
- }
- console.log('tmpsrc/tmp_dep1.c task');
- complete();
- });
- }, {async: true});
- ////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////
- // Namespace Test. This is a Mixed Test.
- // Test for
- // - rules belonging to different namespace.
- // - rules with folder and pattern
- task('tmp_ns', [
- 'tmpbin'
- , 'rule:init'
- , 'tmpbin/tmp_dep2.oo' // *** This relies on a rule defined before.
- , 'rule:tmpbin/dep1.oo'
- , 'rule:tmpbin/file2.oo' ], function () {
- console.log('tmp pattern folder namespace task');
- var data1 = fs.readFileSync('tmpbin/dep1.oo');
- var data2 = fs.readFileSync('tmpbin/tmp_dep2.oo');
- var data3 = fs.readFileSync('tmpbin/file2.oo');
- fs.writeFileSync('tmp_ns', data1 + data2 + data3 + ' pattern folder namespace');
- });
- namespace('rule', function() {
- task('init', ['tmpsrc'], function () {
- fs.writeFile('tmpsrc/file2.c', 'src/src_3', function (err) {
- if (err) {
- throw err;
- }
- console.log('tmpsrc/file2.c init task');
- complete();
- });
- }, {async: true});
- file('tmpsrc/dep1.c',['tmpsrc'], function () {
- fs.writeFile('tmpsrc/dep1.c', 'src/src_1', function (err) {
- if (err) {
- throw err;
- }
- console.log('tmpsrc/dep1.c task');
- complete();
- });
- }, {async: true});
- rule('tmpbin/%.oo', 'tmpsrc/%.c', function() {
- var cmd = util.format('cp %s %s', this.source, this.name);
- console.log(cmd + ' ns task');
- jake.exec([cmd], function () {
- complete();
- });
- }, { async : true });
- });
- ////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////
- // Chain rule
- // rule('tmpbin/%.pdf', 'tmpbin/%.dvi', function() { ...
- // rule('tmpbin/%.dvi', 'tmpsrc/%.tex', ['tmpbin'], function() { ...
- task('tmp_cr', [
- 'chainrule:init'
- , 'chainrule:tmpbin/file1.pdf'
- , 'chainrule:tmpbin/file2.pdf' ], function () {
- console.log('tmp chainrule namespace task');
- var data1 = fs.readFileSync('tmpbin/file1.pdf');
- var data2 = fs.readFileSync('tmpbin/file2.pdf');
- fs.writeFileSync('tmp_cr', data1 + data2 + ' chainrule namespace');
- });
- namespace('chainrule', function() {
- task('init', ['tmpsrc', 'tmpbin'], function () {
- fs.writeFileSync('tmpsrc/file1.tex', 'tex1 ');
- fs.writeFileSync('tmpsrc/file2.tex', 'tex2 ');
- console.log('chainrule init task');
- });
- rule('tmpbin/%.pdf', 'tmpbin/%.dvi', function() {
- var cmd = util.format('cp %s %s', this.source, this.name);
- console.log(cmd + ' dvi->pdf task');
- jake.exec([cmd], function () {
- complete();
- });
- }, { async : true });
- rule('tmpbin/%.dvi', 'tmpsrc/%.tex', ['tmpbin'], function() {
- var cmd = util.format('cp %s %s', this.source, this.name);
- console.log(cmd + ' tex->dvi task');
- jake.exec([cmd], function () {
- complete();
- });
- }, { async : true });
- });
- ////////////////////////////////////////////////////////////
- namespace('precedence', function () {
- task('test', ['foo.html'], function () {
- console.log('ran test');
- });
- rule('.html', '.txt', function () {
- console.log('created html');
- var data = fs.readFileSync(this.source);
- fs.writeFileSync(this.name, data.toString());
- });
- });
- namespace('regexPattern', function () {
- task('test', ['foo.html'], function () {
- console.log('ran test');
- });
- rule(/\.html$/, '.txt', function () {
- console.log('created html');
- var data = fs.readFileSync(this.source);
- fs.writeFileSync(this.name, data.toString());
- });
- });
- namespace('sourceFunction', function () {
- var srcFunc = function (taskName) {
- return taskName.replace(/\.[^.]+$/, '.txt');
- };
- task('test', ['foo.html'], function () {
- console.log('ran test');
- });
- rule('.html', srcFunc, function () {
- console.log('created html');
- var data = fs.readFileSync(this.source);
- fs.writeFileSync(this.name, data.toString());
- });
- });
- ////////////////////////////////////////////////////////////
- task('clean', function () {
- utils.file.rmRf('./foo');
- utils.file.rmRf('./tmp');
- });
|