Search code examples
phpstorm

Pass file name to build script in PhpStorm


I have the next configuration for a build system in PhpStorm:

Build configuration

And it works ok, but I have a problem... my build script needs to receive the name of the file I'm running it on, so, if I build a PHP file, it will run phpcs on it, but if I'm building a CSS or JS file, it will run gulp... with Sublime Text that is possible, is it possible with PhpStorm?


Solution

  • There are no macros support for Run/Debug Configurations -- they are made so they do not depend on a context (currently opened file in editor). In other words -- they are pretty static and all file names/paths are basically hard coded.


    For what you are describing (build script).. you need to use External Tools functionality (which can have all of that and made specifically for such tasks). Once created, you can assign custom shortcut to any External Tools entry (check Settings/Preferences | Keymap for that) so it's more convenient to use it.

    If you want such script to be called on every file save automatically -- then use File Watchers -- pretty much external tools that will be called for you automatically (once per each file modified).


    Since you are doing this for a build script -- maybe you should try to use dedicated (and therefore more appropriate in general) tools? For example: Gulp / Grunt .. or even Phing.