Once upon a time, in the vast universe of programming, repetitive tasks were a common source of headaches. Then, along came the "File Watchers" tool, built into the PHPStorm IDE. It swept onto the scene, promising a solution for those tiresome tasks that seemed to eat up so much of a developer's day.
Have you also found yourself looking for a tool that could automate some tasks in your programming routine? Something that would take over mundane actions, freeing up your time for more complex coding tasks? If yes, then you're in good company!
You might be wondering, "But what about built-in observers in many modern frameworks and tools?" True, they're useful, but "File Watchers" has its own charm. While developing a module for PrestaShop, I found myself yearning for a solution that would allow me to automatically create a compressed module, ready for verification and installation. In particular, I wanted this process to be triggered each time I saved the file I was working on. This desire led me down the rabbit hole, and I discovered the "File Watchers" tool available by default in the PHPStorm IDE.
What sets "File Watchers" apart is its high degree of configurability. It offers the opportunity to connect various programs to be set in motion each time a file is saved. It's like having a digital genie, waiting to fulfil your command at the click of a save button.
To summon this genie, you only need to follow the magical pathway: “Preferences -> Tools -> File Watchers”.
When the window pops up, you have the power to add a new watcher, adjust existing ones, or banish those that no longer serve your needs. To initiate a new watcher, all you need to do is click on the little "+" icon. From there, you can select from a suite of pre-existing templates (like those tailored for the SASS preprocessor), or if you're feeling adventurous, you can craft a fresh setting. For the purposes of this post, and perhaps your own explorations, choosing "<custom>" could be just the right amount of spice you need to add to your coding recipe.
The "File Watchers" tool boasts a plethora of options. PHPStorm allows you to select the file type that triggers an action upon modification. The "scope" option provides a nifty advantage, as it can be restricted to only VCS-committed files, which I believe makes the workflow a lot smoother. Other key options include "Program" and "Arguments", where you can choose the appropriate executable file and its parameters, respectively.
Additional settings let you decide where the tool's output and logs should be written, set environment variables, and specify the folder where the watcher will operate. Advanced options, such as tracking files after automatic save or tracking external changes, are available at your disposal, along with the possibility to control what appears in the terminal and filter the output.
To meet my specific needs, I created a Bash file. Imagine the scenario in PrestaShop module development: a Bash file is created that, upon triggering the rsync and zip commands, copies all required module files into a separate folder, then creates a compressed file ready for deployment and verification. It's like having an automated assembly line, taking care of the monotonous production while the developer focuses on the design and quality control.
So, next time when the tedium of repetition starts to creep into your coding routine, let "File Watchers" be your escape hatch. Think of it as a magical tool within PHPStorm IDE, ready to take away the monotony of your programming journey, helping you reach new pinnacles of creativity and productivity. In its wide range of capabilities, "File Watchers" not only helps streamline complex projects but also guides you efficiently through the intricacies of the coding process, serving as a reliable guide.
Primotly is a trading name of bPolNet Sp. z o.o.,
ul. Człuchowska 9/6 01-360 Warszawa, Poland