Skip to content

Commit

Permalink
WIP. Non-functional.
Browse files Browse the repository at this point in the history
So the basic idea here is that instead of binding a hidden `grunt.even.on('watch)` event, we could register a multiTask directly, and loop over the supplied filenames.

The problem seems to be that grunt-contrib-watch doesn't expect to hand off to a multiTask, so things don't work correctly. There seems to be an approach for handling this kind of case laid out here though: https://www.npmjs.com/package/grunt-contrib-watch#compiling-files-as-needed

Needs more experimentation.
  • Loading branch information
beporter committed Jan 21, 2015
1 parent c197030 commit 992ee74
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
30 changes: 15 additions & 15 deletions Console/node/tasks/php_tests.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var fs = require('fs');

module.exports = function(grunt) {
grunt.event.on('watch', function(action, filepath) {
var CakeTestRunner, regex = /\.php$/;
if (regex.test(filepath)) {
CakeTestRunner = require('../cake_test_runner'),
file = new CakeTestRunner(filepath);

if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too.
file.vagrantHost = true;
}

file.exists(function() { file.run(); });
}
});
};
// module.exports = function(grunt) {
// grunt.event.on('watch', function(action, filepath) {
// var CakeTestRunner, regex = /\.php$/;
// if (regex.test(filepath)) {
// CakeTestRunner = require('../cake_test_runner'),
// file = new CakeTestRunner(filepath);
//
// if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too.
// file.vagrantHost = true;
// }
//
// file.exists(function() { file.run(); });
// }
// });
// };
45 changes: 20 additions & 25 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function(grunt) {
grunt.loadTasks('Console/node/tasks');
require('load-grunt-tasks')(grunt);
var changedFiles = {};
var fs = require('fs');

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Expand All @@ -17,6 +17,9 @@ module.exports = function(grunt) {
}
}
},
phptestfile: {
target: {},
},

watch: {
php: {
Expand All @@ -27,8 +30,8 @@ module.exports = function(grunt) {
'!tmp/**',
'!.git/**/*.php'
],
tasks: 'null' // See Console/node/tasks/php_tests.js
// tasks: 'phptestfile',
// tasks: 'null', // See Console/node/tasks/php_tests.js
tasks: ['phptestfile'],
options: {
spawn: false
}
Expand All @@ -43,27 +46,19 @@ module.exports = function(grunt) {
grunt.registerTask('default', ['less', 'watch']);
grunt.registerTask('test', ['jstest']); // See Console/node/tasks/js_tests.js

grunt.registerMultiTask('phptestfile', function() {
var files = this.filesSrc;
var CakeTestRunner = require('./Console/node/cake_test_runner');
var phpfile;
var vagrantHost = fs.existsSync('.vagrant');

files.forEach(function(filepath) {
phpfile = new CakeTestRunner(filepath);
phpfile.vagrantHost = vagrantHost;
phpfile.exists(function() { phpfile.run(); });
});

// grunt.event.on('watch', function(action, filepath) {
// if (this.name === 'watch:php') {
// changedFiles[filepath] = action;
// }
// });
//
// grunt.registerMultiTask('phptestfile', function() {
// console.log(changedFiles);
// return true;
//
// var filepath = '?';
// var CakeTestRunner = require('./Console/node/cake_test_runner');
// var file = new CakeTestRunner(filepath);
//
// if (fs.existsSync('.vagrant')) { //@TODO: This doesn't work because the folder shows up inside the VM too.
// file.vagrantHost = true;
// }
//
// file.exists(function() { file.run(); });
// });

};
// Otherwise, print a success message.
grunt.log.ok('Files tested: ' + files.length);
});
}

0 comments on commit 992ee74

Please sign in to comment.