I'm developing a custom grunt extension that reloads a chrome tab. It works fine when I use it within the plugin's own folder, but then when I try to download it from NPM and use it in another project, it goes bonkers.
I included it as such:
grunt.loadNpmTasks('grunt-chrome-extension-reload');
My custom task code, located in the tasks
folder of the plugin, is as such:
/*
* grunt-chrome-extension-reload
* https://github.com/freedomflyer/grunt-chrome-extension-reload
*
* Copyright (c) 2014 Spencer Gardner
* Licensed under the MIT license.
*/
'use strict';
module.exports = function(grunt) {
var chromeExtensionTabId = 0;
grunt.initConfig({
/**
Reloads tab in chrome with id of chromeExtensionTabId
Called after correct tab number is found from chrome-cli binary.
*/
exec: {
reloadChromeTab: {
cmd: function() {
return chromeExtensionTabId ? "chrome-cli reload -t " + chromeExtensionTabId : "chrome-cli open chrome://extensions && chrome-cli reload";
}
}
},
/**
Executes "chrome-cli list tabs", grabs stdout, and finds open extension tabs ID's.
Sets variable chromeExtensionTabId to the first extension tab ID
*/
external_daemon: {
getExtensionTabId: {
options: {
verbose: true,
startCheck: function(stdout, stderr) {
// Find any open tab in Chrome that has the extensions page loaded, grab ID of tab
var extensionTabMatches = stdout.match(/\[\d{1,5}\] Extensions/);
if(extensionTabMatches){
var chromeExtensionTabIdContainer = extensionTabMatches[0].match(/\[\d{1,5}\]/)[0];
chromeExtensionTabId = chromeExtensionTabIdContainer.substr(1, chromeExtensionTabIdContainer.length - 2);
console.log("Chrome Extension Tab #: " + chromeExtensionTabId);
}
return true;
}
},
cmd: "chrome-cli",
args: ["list", "tabs"]
}
}
});
grunt.registerTask('chrome_extension_reload', function() {
grunt.task.run(['external_daemon:getExtensionTabId', 'exec:reloadChromeTab']);
});
};
So, when I run it in an external project with grunt watch
, grunt spits out this error a few hundred times before quitting (endless loop?)
Running "watch" task
Waiting...Verifying property watch exists in config...ERROR
>> Unable to process task.
Warning: Required config property "watch" missing.
Fatal error: Maximum call stack size exceeded
Interestingly, can not even call my plugin within the watch
task, and the problem persists. Only by removing grunt.loadNpmTasks('grunt-chrome-extension-reload');
can I get rid of the issue, which basically means that the code inside my task is wrong. Any ideas?