Is there a way to automatically run a script (such as copy files from a to b) when the truffle migrate command finishes?

I want to copy the json files from the build/contracts folder into the a folder where my webapp code is.

Currently I use the "truffle develop" command console, soit would be cool, if I could just type "migrate" to for a deployment script to kick in and copy the files.

  • Why don't you write a script which calls truffle migrate and then copies those json files? Commented May 8, 2018 at 11:35
  • i don't think that is possible via truffle means of course, but you can write a JS script and run it with node or just in any kind of language you want. Commented May 8, 2018 at 13:34
  • I can't run truffle migrate because it won't work on my office workstation. I can run the migrate command from inside the Truffle development console.
    – simbro
    Commented May 8, 2018 at 14:23

1 Answer 1


Truffle scripts are executed in stages. So you can create an additional state that is executed last (migrations/9_copy_artifacts.js). That will run after all previous stages have completed, so you will be sure the contract's artifacts will be in the build directory.

  • Thanks Ismael, actually that did the trick - worked perfectly - thank you!
    – simbro
    Commented May 14, 2018 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.