1

I need to run in command line (cmd)

npm run build

and after that, I need to run

xcopy C:\fileOne C:\fileTwo

BUT, I would like to run only one command and to execute both of those above. So I thought maybe my package.json should look like this:

 "scripts": {
       "build": "react-scripts build",
       "copy": "xcopy C:\path\firstFile C:\path\secondFile",
       "zack": "npm run build && npm run copy",
 },

based on this idea:

"scripts": {
       "a1": "command1",
       "a2": "command2",
       "zack": "npm run a1 && npm run a2",
 },

and then I could run in command line:

npm run zack

but I'm not managing to make it happen

(the reason why I'm doing this, is: I want to change source code in SubliteText 3 (HTML JS CSS) and automatically to send (copy-paste) in Eclipse (in some other project) )

I want to do this:

enter image description here

My main problem is how to put local directory path inside the string in package.json file.

1
  • 1
    If the answer below helps you out please be sure to mark it as accepted. Commented Feb 22, 2018 at 14:14

2 Answers 2

1

Instead of writing commands directly inside the package.json you should write a script file that handles it for you.

Something like

var fs = require('fs');
fs.createReadStream('PATH_TO_FILE_ONE').pipe(fs.createWriteStream('PATH_TO_NEW_FILE'));

save the above script as something like afterBuild.js

and in your package.json just do zack as npm run build && node afterBuild.js

Sign up to request clarification or add additional context in comments.

2 Comments

ok looks interesting, I tried, and when I run: npm run build && node afterBuild.js I'm getting: Error: EISDIR: illegal operation on a directory, open 'C:\Users\Dev30\Desktop\demo2\src\main\webapp' npm ERR! code ELIFECYCLE
createReadStream is for files the EISDIR (Error, is directory) error means you're trying to read a directory with a command meant only to read a file. If you wish to copy an entire directory, use: ncp npmjs.com/package/ncp
0

I installed npc module:

npm install ncp -g

npm install ncp --save

then I created a file: afterBuild.js and I inserted this code inside:

var ncp = require("ncp");
ncp("C:/directory/file.txt", "C:/destination/directory/file.txt", callback);
function callback(){} //empty function, I don't need it for the start

and in package.json i wrote:

 "scripts": {
       "build": "react-scripts build",
       "zack": "npm run build && node afterBuild.js"
 },

and I run it form command line like:

npm run zack

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.