[Cashtab] Improve extension build script error handling
Summary:
T2572
If npm run build fails during a build of the extension, Cashtab makes a big mess that is difficult to clean up. It will leave the extension files in place of the web files (App.js and others), and then delete the old files. So you need to manually unwind a lot of stuff to get back to normal.
This can happen easily as npm run build may fail even when npm start looks great, for example if there is an unused variable in a file.
This diff moves the logic for restoring the file structure into the cleanup function, so that the original file structure is preserved even if there is an error in npm run build
Test Plan:
npm run extension
extension builds and works
In cashMethods.js, add the line import BCH from 'bch-js'; at the end of the imports. This will cause npm run build to fail
Run npm run extension
Note that the build failed and the script exited
Note the console prints that files were moved back
git status shows no changes other than cashMethods.js
Reviewers: #bitcoin_abc, kieran709
Reviewed By: #bitcoin_abc, kieran709
Differential Revision: https://reviews.bitcoinabc.org/D12500