14Nov

package.json script copy to smb mounted disc

Running a build then copy the “dist” folder into the server in order to share with the team can be time-consuming when you have to do it many times a day for your projects.
I was looking into doing one command line for multiples actions.

 

Run the build and then copy the dist folder created to an existing folder on the server. I work on a webpack build.

Here was the original script part

"scripts": {
  "start": "NODE_ENV=development webpack-dev-server --config webpack.development.config.js --inline --hot",
  "stage": "NODE_ENV=stage webpack -p --config webpack.development.config.js",
  "build": "webpack -p --config webpack.production.config.js",
  "fetch": "node ./tasks/fetch"
},

I wanted to copy what gets out of the run build to smb://xxxxx.zzzzz.com/organisation/people/denis/myproject

It looks like I can’t use “smb//…” as a destination. However, you can use the relative path. In your computer if you go to the “/Volumes” folder you will find your mounted disc path. (on mac: finder > go to folder > /Volumes > enter and go where needed)

Here are the two lines I added in order to get what I needed:

"scripts": {
  "start": "NODE_ENV=development webpack-dev-server --config webpack.development.config.js --inline --hot",
  "stage": "NODE_ENV=stage webpack -p --config webpack.development.config.js",
  "build": "webpack -p --config webpack.production.config.js",
  "fetch": "node ./tasks/fetch",
  "copy": "cp -R dist/ /Volumes/denis/myproject",
  "deploy": "npm run build && npm run copy"
},

  1. “cp” cp is for copy source destination. “cp -R” is to copy the directory.
  2. $ npm run deploy will do the build action and then do a copy of the folder in my volumes disc on the server. Obviously, if the disc is not mounted the second part of the script will fail.

This save me to go manually copy and paste the files after running the build. Precious seconds saved :)

Subscribe
Notify of

0 Comments
Inline Feedbacks
View all comments