7

cro run stops the server, recompiles, restarts the server when anything in the directory tree changes. That's great.

But when developing the client side UI, and using NPX/yarn/webpack, there is an additional step that is needed to produce the main.js file.

In the Cro tutorial this step seems to be done manually, viz., we have the line "And there we have it. npm run build, refresh, and give it a spin." Here npm run build is a command that has to be run 'manually'.

Is there a simple way, eg., using .cro.yml to force another command when changes in a sub-directory tree are detected? Eg, if the client side UI files are under path/to/cro-app/client-ui-directory and the command to be run if any files change is path/to/cro-app/client-ui/directory/yarn build

Richard Hainsworth
  • 1,585
  • 7
  • 9

1 Answers1

0

The cro-tools repo has all the file watching code associated with cro run.

So, one way would be to subclass the appropriate stuff in that repo and make a super-cro run command.

But I think the thing to do would be to set up a file watcher and trigger the rebuild in your server process. Cro files set environment variables, so you could use them to configure this behavior.

daotoad
  • 26,689
  • 7
  • 59
  • 100
  • I don't understand the code well enough to give write you a sample, and don't have time to figure it out right now. But the Cro::Tools repo on github has some examples you can use as a starting point. https://github.com/croservices/cro/blob/master/lib/Cro/Tools/Services.pm6#L121 – daotoad Dec 18 '19 at 20:07