bdkjones / CodeKit2

CodeKit 2 Beta
98 stars 4 forks source link

Hook keeps looping #596

Closed kosmiq closed 8 years ago

kosmiq commented 8 years ago

So I just started out using a Hook for a current project. The hook is supersimple, it just runs "grunt grunticon" (https://github.com/filamentgroup/grunticon)

ck_hooks

I have tried other settings to trigger the hook than those above, like the default, looking for minified files and so (but all JS-files).

What happens is that when I save "scripts.js" it gets processed as it should by CodeKit, minified and saved just fine. The hook will launch "grunt grunticon" (it does what it should) and generate all its stuff, including the file "grunticon.loader.js" which I also prepend to scripts.js.

I guess this is where things gets... Weird.

So in short:

I guess it is because I save the script file, it runs the hook, a prepended file is changed, so CodeKit does it thing with uglify, concatetate and minify, and runs the hook again and it all starts over.

Is there a simple fix for this or should I simply stick to having it run on whenever style.css changes or whatever? I am aware that I might be seriously stupid here prepending a file that's created by a hook...

bdkjones commented 8 years ago

Ha, yea, you've set up an infinite loop. script.js is saved and CodeKit responds to that event by processing the file. At the end of processing, you have a Hook that modifies a file you prepend into script.js. CodeKit sees that file change, walks the dependency graph and says, "Script.js needs to be compiled because something it imports changed."

You'll need to restructure this so that the loop isn't created; there's really no way for CodeKit to know that the change to the dependent file happened as a result of a Hook running on the first iteration of processing.

kosmiq commented 8 years ago

So I changed the hook to run when saving style.scss instead. Problem solved of course.