IdeHelper plugin on steroids

Pretty much 5 years ago I blogged about leveraging your IDE.

In this small update here I want to showcase a very handy new feature:
Live annotation updates in your code base while you bake, develop and customize.

Note: The following requires IdeHelper 2.10+ plugin version.

(File) Watchers

Currently, once you baked code, or you modified a PHP class or view template, you need to manually run the annotator.
I often use -f SomeFilter to quickly run it over relevant files.

Sometimes I forget and get reminded from PHPStan then, that there are some unknown relations or class usage.

You can set up a file watcher to run the annotation tool on every file change.
This way you can have a live annotation update while coding.

Using Node + Chokidar

Install using

npm init -y
npm install chokidar --save

in your project root.

Run for example:

node vendor/dereuromark/cakephp-ide-helper/annotate-watcher.cjs

If necessary, you can also customize the paths using --path=src/,templates/, for example.

You can also copy the annotate-watcher.cjs to your app and customize it.

Since this is a cross-platform tool, this is currently the recommended approach, as it is also
the most performant (only touches the files directly modified).
It might miss a few related templates that are not modified but would get updates.
This is the tradeoff.

Using watchexec

See github.com/watchexec/watchexec.

watchexec -e php 'bin/cake annotate all'

With this, you would usually run it over all files. Still usually quite performant.

Customization

You can pull down the cjs file to your application and modify it. Then just execute that one instead.

Shortcuts

If you dont want to type the whole command every time, or if you further customized the paths, it can be useful to make this a composer script:

    // your composer.json scripts section
    'watcher' => 'node vendor/dereuromark/cakephp-ide-helper/annotate-watcher.cjs ...'

and then only have to run

composer watcher

If you want to run it in the background, you can further enhance it with a 2nd stop command when needed.
Then it could be as simple as

composer watcher-start
composer watcher-end

Hope this gave you some useful ideas for an even more productive CakePHP coding experience.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.