1

Is there a way to hook an extra script that will look into an specific JSON file and create an enum from it.

I need to recreate it after each change of the JSON. Usually I would use an npm watch for it but I want to hook it into the regular ionic/angular build, so if I run ionic serve or ionic build it should be called.

Is there a way to do this? I have found info about pre and post npm scripts but they just work for one call of scripts from the package.json

Writing an pre/post script after the angular build script "build": "ng build", does nothing while on serve mode.

distante
  • 6,438
  • 6
  • 48
  • 90
  • What have you tried so far and why didn't it work? – igg Jan 08 '20 at 09:41
  • @IraklisGkougkousis I have trying to put a `pre` or `post` script after the ` "build": "ng build"` script with an echo msg and it did not wrote anything in the console. – distante Jan 08 '20 at 09:42
  • Does chanining `npm` scripts not work for you? You can create 1 script that creates the enum and then call another one like `ionic serve`, using `&&`. Does this help you: https://stackoverflow.com/questions/39172536/running-npm-scripts-sequentially/39172660 – igg Jan 08 '20 at 09:46
  • @IraklisGkougkousis for that `ionic serve` should end. It (like `ng serve`) lives in watch mode until I manually kill it with`ctrl+c` – distante Jan 08 '20 at 09:48
  • You can create your own command inside `package.json` and `scripts` tag then use && to combine both – Nour Jan 08 '20 at 09:48
  • @distante You mean you want your enum creation script to run while `ionic serve` is active? Meaning make changes to the code -> save -> re-create enum -> reload browser? Something like that? – igg Jan 08 '20 at 09:50
  • @IraklisGkougkousis Yes exactly. Currently I have to (remember to) run the script manually when I change the JSON file. I want to be able to let it automatically if possible. – distante Jan 08 '20 at 09:51
  • @distante This works for `ng`, it might help you for ionic: https://stackoverflow.com/questions/42364234/hook-into-angular-cli-build-watch – igg Jan 08 '20 at 09:56
  • @IraklisGkougkousis I already saw that post I thought that maybe angular has now some kind of hook system but looks like don't. – distante Jan 08 '20 at 10:01

0 Answers0