MDL-49817 grunt: make shifter work watch on right place
authorDan Poltawski <dan@moodle.com>
Thu, 14 Jan 2016 16:42:44 +0000 (16:42 +0000)
committerDan Poltawski <dan@moodle.com>
Thu, 28 Jan 2016 08:27:31 +0000 (08:27 +0000)
We mess around with the cwd to find a shifter path, not ideal but avoids
having to refactor the shifter task.

Also fix jshint errors..

1) The gruntfile runs in a nodejs environment and not a browser
environment.

2) There was an uninitialised variable

Gruntfile.js

index 600ec05..e901c07 100644 (file)
@@ -12,6 +12,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/* jshint node: true, browser: false */
 
 /**
  * @copyright  2014 Andrew Nicols
@@ -106,6 +107,7 @@ module.exports = function(grunt) {
             },
             shifter;
 
+            grunt.log.ok("Running shifter on " + cwd);
             args.push( path.normalize(__dirname + '/node_modules/shifter/bin/shifter'));
 
             // Determine the most appropriate options to run with based upon the current location.
@@ -199,7 +201,7 @@ module.exports = function(grunt) {
                         files.forEach(function (file) {
 
                             var p = path.join(directory, file);
-                            stat = fs.statSync(p);
+                            var stat = fs.statSync(p);
                             if (!stat.isDirectory()) {
                                 pending--;
                             } else {
@@ -266,6 +268,12 @@ module.exports = function(grunt) {
     grunt.event.on('watch', function(action, filepath) {
       grunt.config('jshint.amd.src', filepath);
       grunt.config('uglify.amd.files', [{ expand: true, src: filepath, rename: uglify_rename }]);
+      if (filepath.match('yui')) {
+          // Set the cwd to the base directory for yui modules which have changed.
+          cwd = filepath.split(path.sep + 'yui' + path.sep + 'src').shift();
+      } else {
+          cwd = process.env.PWD || process.cwd();
+      }
     });
 
     // Register NPM tasks.